ukko: further fixes; should now provide a smooth overboard experience

This commit is contained in:
czaks 2013-08-04 01:36:56 -04:00
parent 7ed01737c7
commit e2b5ec9354

View File

@ -2,8 +2,8 @@
var cache = new Array(), var cache = new Array(),
thread = false, thread = false,
loading = false; loading = false,
ukkotimer = false;
if (localStorage.hiddenboards !== null) { if (localStorage.hiddenboards !== null) {
localStorage.hiddenboards = "{}"; localStorage.hiddenboards = "{}";
} }
@ -52,11 +52,11 @@ $(document).ready(function() {
$("h2").each(addukkohide); $("h2").each(addukkohide);
$('.pages').hide(); $('.pages').hide();
$(window).on('scroll', function() { var loadnext = function() {
if (overflow.length == 0) { if (overflow.length == 0) {
$('.pages').show().html(_("No more threads to display")); $('.pages').show().html(_("No more threads to display"));
} }
while($(window).scrollTop() + $(window).height() + 500 > $(document).height() && !loading && overflow.length > 0) { while($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading && overflow.length > 0) {
var page = '../' + overflow[0].board + '/' + overflow[0].page; var page = '../' + overflow[0].board + '/' + overflow[0].page;
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]'); thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present
@ -66,11 +66,13 @@ $(document).ready(function() {
var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>'); var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>');
if($.inArray(page, cache) != -1 && thread.length > 0) { if($.inArray(page, cache) != -1) {
$('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block')); if (thread.length > 0) {
boardheader.insertBefore(thread); $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
addukkohide.call(boardheader); boardheader.insertBefore(thread);
$(document).trigger('new_post', thread); addukkohide.call(boardheader);
$(document).trigger('new_post', thread);
}
overflow.shift(); overflow.shift();
} else { } else {
loading = true; loading = true;
@ -92,11 +94,8 @@ $(document).ready(function() {
boardheader.insertBefore(thread); boardheader.insertBefore(thread);
addukkohide.call(boardheader); addukkohide.call(boardheader);
$(document).trigger('new_post', thread); $(document).trigger('new_post', thread);
overflow.shift();
}
else {
overflow.shift(); // We missed it? Or already present...
} }
overflow.shift();
loading = false; loading = false;
$('.pages').hide().html(""); $('.pages').hide().html("");
@ -104,7 +103,13 @@ $(document).ready(function() {
break; break;
} }
} }
}); clearTimeout(ukkotimer);
ukkotimer = setTimeout(loadnext, 1000);
};
$(window).on('scroll', loadnext);
ukkotimer = setTimeout(loadnext, 1000);
}); });
})(); })();