summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-03-15 20:40:52 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-03-15 20:40:52 +1100
commitaf7b5b5d78b5981a2b47cea0afa614bc70a6c7f5 (patch)
treea34d6b6d2ef0b12132ec057ef5a42a5b7100e552 /js
parentae848ef6663ec90c1e83f3729558c59547b2e0e7 (diff)
better scroll events
Diffstat (limited to 'js')
-rw-r--r--js/auto-reload.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/js/auto-reload.js b/js/auto-reload.js
index 83e9751e..5070c9ca 100644
--- a/js/auto-reload.js
+++ b/js/auto-reload.js
@@ -17,10 +17,9 @@ $(document).ready(function(){
if($('div.banner').length == 0)
return; // not index
- setInterval(function() {
- if($(window).scrollTop() + $(window).height() < $('div.post.reply:last').position().top + $('div.post.reply:last').height())
- return; // not scrolled past last reply
-
+ var poll_interval;
+
+ var poll = function() {
$.ajax({
url: document.location,
success: function(data) {
@@ -32,6 +31,20 @@ $(document).ready(function(){
});
}
});
- }, 5000);
+
+ poll_interval = setTimeout(poll, 5000);
+ };
+
+ $(window).scroll(function() {
+ if($(this).scrollTop() + $(this).height() < $('div.post.reply:last').position().top + $('div.post.reply:last').height()) {
+ clearTimeout(poll_interval);
+ poll_interval = false;
+ return;
+ }
+
+ if(poll_interval === false) {
+ poll_interval = setTimeout(poll, 1500);
+ }
+ }).trigger('scroll');
});