From e2b5ec93547bde60244190aa7dd00b4f3523e1e0 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 4 Aug 2013 01:36:56 -0400 Subject: [PATCH] ukko: further fixes; should now provide a smooth overboard experience --- templates/themes/ukko/ukko.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/templates/themes/ukko/ukko.js b/templates/themes/ukko/ukko.js index d8693db3..4a36b394 100644 --- a/templates/themes/ukko/ukko.js +++ b/templates/themes/ukko/ukko.js @@ -2,8 +2,8 @@ var cache = new Array(), thread = false, - loading = false; - + loading = false, + ukkotimer = false; if (localStorage.hiddenboards !== null) { localStorage.hiddenboards = "{}"; } @@ -52,11 +52,11 @@ $(document).ready(function() { $("h2").each(addukkohide); $('.pages').hide(); - $(window).on('scroll', function() { + var loadnext = function() { if (overflow.length == 0) { $('.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; thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]'); if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present @@ -66,11 +66,13 @@ $(document).ready(function() { var boardheader = $('

/' + overflow[0].board + '/

'); - if($.inArray(page, cache) != -1 && thread.length > 0) { - $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block')); - boardheader.insertBefore(thread); - addukkohide.call(boardheader); - $(document).trigger('new_post', thread); + if($.inArray(page, cache) != -1) { + if (thread.length > 0) { + $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block')); + boardheader.insertBefore(thread); + addukkohide.call(boardheader); + $(document).trigger('new_post', thread); + } overflow.shift(); } else { loading = true; @@ -92,11 +94,8 @@ $(document).ready(function() { boardheader.insertBefore(thread); addukkohide.call(boardheader); $(document).trigger('new_post', thread); - overflow.shift(); - } - else { - overflow.shift(); // We missed it? Or already present... } + overflow.shift(); loading = false; $('.pages').hide().html(""); @@ -104,7 +103,13 @@ $(document).ready(function() { break; } } - }); + clearTimeout(ukkotimer); + ukkotimer = setTimeout(loadnext, 1000); + }; + + $(window).on('scroll', loadnext); + + ukkotimer = setTimeout(loadnext, 1000); }); })();