gitlabhq/app/assets/javascripts/note.js

96 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-11-15 09:34:30 +01:00
var NoteList = {
2011-11-04 14:37:38 +01:00
first_id: 0,
last_id: 0,
resource_name: null,
2012-02-12 22:52:27 +01:00
disable:false,
2011-11-04 14:37:38 +01:00
2011-11-15 09:34:30 +01:00
init:
function(resource_name, first_id, last_id) {
this.resource_name = resource_name;
this.first_id = first_id;
this.last_id = last_id;
2011-11-04 14:37:38 +01:00
this.initRefresh();
this.initLoadMore();
},
getOld:
2011-11-15 09:34:30 +01:00
function() {
2011-11-04 14:37:38 +01:00
$('.loading').show();
$.ajax({
type: "GET",
url: location.href,
data: "first_id=" + this.first_id,
complete: function(){ $('.loading').hide()},
dataType: "script"});
},
append:
function(id, html) {
2012-02-12 22:52:27 +01:00
if(this.first_id == id) {
this.disable = true;
} else {
this.first_id = id;
$("#notes-list").append(html);
}
2011-11-04 14:37:38 +01:00
},
2011-11-15 09:34:30 +01:00
replace:
2011-11-05 12:59:43 +01:00
function(fid, lid, html) {
this.first_id = fid;
this.last_id = lid;
$("#notes-list").html(html);
this.initLoadMore();
},
2011-11-04 14:37:38 +01:00
prepend:
function(id, html) {
2011-11-15 09:34:30 +01:00
if(id != this.last_id) {
2011-11-06 22:32:37 +01:00
this.last_id = id;
$("#notes-list").prepend(html);
}
2011-11-04 14:37:38 +01:00
},
getNew:
2011-11-15 09:34:30 +01:00
function() {
2011-11-04 14:37:38 +01:00
// refersh notes list
$.ajax({
type: "GET",
url: location.href,
data: "last_id=" + this.last_id,
dataType: "script"});
},
2011-11-05 12:59:43 +01:00
refresh:
2011-11-15 09:34:30 +01:00
function() {
2011-11-05 12:59:43 +01:00
// refersh notes list
$.ajax({
type: "GET",
url: location.href,
data: "first_id=" + this.first_id + "&last_id=" + this.last_id,
dataType: "script"});
},
2011-11-04 14:37:38 +01:00
initRefresh:
function() {
// init timer
2011-11-05 12:59:43 +01:00
var intNew = setInterval("NoteList.getNew()", 15000);
var intRefresh = setInterval("NoteList.refresh()", 90000);
2011-11-04 14:37:38 +01:00
},
initLoadMore:
2011-11-15 09:34:30 +01:00
function() {
2012-02-12 22:52:27 +01:00
$(document).endlessScroll({
bottomPixels: 400,
fireDelay: 1000,
fireOnce:true,
ceaseFire: function() {
return NoteList.disable;
},
callback: function(i) {
2011-11-04 14:37:38 +01:00
NoteList.getOld();
}
2012-02-12 22:52:27 +01:00
});
2011-11-04 14:37:38 +01:00
}
}