From 5817194be4e2124d47846c5ab7bfc238a395f586 Mon Sep 17 00:00:00 2001 From: czaks Date: Mon, 23 Dec 2013 16:34:44 +0100 Subject: [PATCH] auto-reload.js: tweak timeouts, so now it gets new posts even if not at bottom --- js/auto-reload.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/auto-reload.js b/js/auto-reload.js index 5d96146a..f3f04639 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -21,6 +21,8 @@ $(document).ready(function(){ return; //not thread page var poll_interval; + + var end_of_page = false; var poll = function() { $.ajax({ @@ -36,19 +38,21 @@ $(document).ready(function(){ } }); - poll_interval = setTimeout(poll, 5000); + clearTimeout(poll_interval); + poll_interval = setTimeout(poll, end_of_page ? 3000 : 10000); }; $(window).scroll(function() { if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) { - clearTimeout(poll_interval); - poll_interval = false; + end_of_page = false; return; } - if(poll_interval === false) { - poll_interval = setTimeout(poll, 1500); - } + clearTimeout(poll_interval); + poll_interval = setTimeout(poll, 100); + end_of_page = true; }).trigger('scroll'); + + poll_interval = setTimeout(poll, 3000); });