While we're here, restore infinite scrolling functionality.

This commit is contained in:
Zixaphir 2014-01-10 21:39:36 -07:00
parent 1555eb8166
commit f0a90a12c5
3 changed files with 89 additions and 0 deletions

View File

@ -2281,6 +2281,7 @@
});
this.searchInput = $('#index-search', this.navLinks);
this.currentPage = this.getCurrentPage();
$.on(d, 'scroll', Index.scroll);
$.on(this.pagelist, 'click', this.cb.pageNav);
$.on(this.searchInput, 'input', this.onSearchInput);
$.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch);
@ -2315,6 +2316,39 @@
}
});
},
scroll: $.debounce(100, function() {
var nodes, nodesPerPage, pageNum;
if (Conf['Index Mode'] !== 'paged' || ((d.body.scrollTop || doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight))) {
return;
}
pageNum = Index.getCurrentPage() + 1;
if (pageNum >= Index.pagesNum) {
return Index.endNotice();
}
nodesPerPage = Index.threadsNumPerPage * 2;
history.pushState(null, '', "/" + g.BOARD + "/" + pageNum);
nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1));
if (Conf['Show Replies']) {
Index.buildReplies(nodes);
}
$.add(Index.root, nodes);
return Index.setPage();
}),
endNotice: (function() {
var notify, reset;
notify = false;
reset = function() {
return notify = false;
};
return function() {
if (notify) {
return;
}
notify = true;
new Notice('info', "Last page reached.", 2);
return setTimeout(reset, 3 * $.SECOND);
};
})(),
cb: {
mode: function() {
Index.togglePagelist();

View File

@ -2291,6 +2291,7 @@
});
this.searchInput = $('#index-search', this.navLinks);
this.currentPage = this.getCurrentPage();
$.on(d, 'scroll', Index.scroll);
$.on(this.pagelist, 'click', this.cb.pageNav);
$.on(this.searchInput, 'input', this.onSearchInput);
$.on($('#index-search-clear', this.navLinks), 'click', this.clearSearch);
@ -2325,6 +2326,39 @@
}
});
},
scroll: $.debounce(100, function() {
var nodes, nodesPerPage, pageNum;
if (Conf['Index Mode'] !== 'paged' || ((d.body.scrollTop || doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight))) {
return;
}
pageNum = Index.getCurrentPage() + 1;
if (pageNum >= Index.pagesNum) {
return Index.endNotice();
}
nodesPerPage = Index.threadsNumPerPage * 2;
history.pushState(null, '', "/" + g.BOARD + "/" + pageNum);
nodes = Index.sortedNodes.slice(nodesPerPage * pageNum, nodesPerPage * (pageNum + 1));
if (Conf['Show Replies']) {
Index.buildReplies(nodes);
}
$.add(Index.root, nodes);
return Index.setPage();
}),
endNotice: (function() {
var notify, reset;
notify = false;
reset = function() {
return notify = false;
};
return function() {
if (notify) {
return;
}
notify = true;
new Notice('info', "Last page reached.", 2);
return setTimeout(reset, 3 * $.SECOND);
};
})(),
cb: {
mode: function() {
Index.togglePagelist();

View File

@ -78,6 +78,7 @@ Index =
@searchInput = $ '#index-search', @navLinks
@currentPage = @getCurrentPage()
$.on d, 'scroll', Index.scroll
$.on @pagelist, 'click', @cb.pageNav
$.on @searchInput, 'input', @onSearchInput
$.on $('#index-search-clear', @navLinks), 'click', @clearSearch
@ -106,6 +107,26 @@ Index =
else
$.after $.id('delform'), Index.pagelist
scroll: $.debounce 100, ->
return if Conf['Index Mode'] isnt 'paged' or ((d.body.scrollTop or doc.scrollTop) <= doc.scrollHeight - (300 + window.innerHeight))
pageNum = Index.getCurrentPage() + 1
return Index.endNotice() if pageNum >= Index.pagesNum
nodesPerPage = Index.threadsNumPerPage * 2
history.pushState null, '', "/#{g.BOARD}/#{pageNum}"
nodes = Index.sortedNodes[nodesPerPage * pageNum ... nodesPerPage * (pageNum + 1)]
Index.buildReplies nodes if Conf['Show Replies']
$.add Index.root, nodes
Index.setPage()
endNotice: do ->
notify = false
reset = -> notify = false
return ->
return if notify
notify = true
new Notice 'info', "Last page reached.", 2
setTimeout reset, 3 * $.SECOND
cb:
mode: ->
Index.togglePagelist()