gitlabhq/app/assets/javascripts/note.js

87 lines
1.7 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,
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) {
this.first_id = id;
$("#notes-list").append(html);
this.initLoadMore();
},
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() {
2011-11-04 14:37:38 +01:00
$(window).bind('scroll', function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
$(window).unbind('scroll');
NoteList.getOld();
}
});
}
}