summaryrefslogtreecommitdiff
path: root/js/auto-reload.js
diff options
context:
space:
mode:
authorMichael Walker <mike@barrucadu.co.uk>2014-05-05 19:28:07 +0100
committerMichael Walker <mike@barrucadu.co.uk>2014-05-05 19:33:57 +0100
commit0e18636fe6302f134312c4dcc82d6768626d4d32 (patch)
tree674c786465514512a2549cce20c1bfe544e3da2b /js/auto-reload.js
parent72c7e28a0e6d55b6ca8be70aab53352c3cb4ce38 (diff)
Move the magic numbers out to variables
Diffstat (limited to 'js/auto-reload.js')
-rw-r--r--js/auto-reload.js22
1 files changed, 19 insertions, 3 deletions
diff --git a/js/auto-reload.js b/js/auto-reload.js
index 34acca90..40fa58a6 100644
--- a/js/auto-reload.js
+++ b/js/auto-reload.js
@@ -27,6 +27,18 @@ $(document).ready(function(){
var poll_interval;
+ // number of ms to wait before reloading
+ var poll_interval_delay;
+
+ // If at the bottom of the page, reload more quickly.
+ var poll_interval_mindelay_bottom = 3000;
+ var poll_interval_mindelay_top = 10000;
+
+ poll_interval_delay = poll_interval_mindelay_bottom;
+
+ // Upon scrolling to the bottom, reload very quickly.
+ var poll_interval_shortdelay = 100;
+
var end_of_page = false;
var new_posts = 0;
@@ -81,7 +93,11 @@ $(document).ready(function(){
});
clearTimeout(poll_interval);
- poll_interval = setTimeout(poll, end_of_page ? 3000 : 10000);
+
+ poll_interval_delay = end_of_page
+ ? poll_interval_mindelay_bottom
+ : poll_interval_mindelay_top;
+ poll_interval = setTimeout(poll, poll_interval_delay);
};
$(window).scroll(function() {
@@ -94,10 +110,10 @@ $(document).ready(function(){
}
clearTimeout(poll_interval);
- poll_interval = setTimeout(poll, 100);
+ poll_interval = setTimeout(poll, poll_interval_shortdelay);
end_of_page = true;
}).trigger('scroll');
- poll_interval = setTimeout(poll, 3000);
+ poll_interval = setTimeout(poll, poll_interval_delay);
});