diff --git a/js/auto-reload.js b/js/auto-reload.js index be381059..db7aac2a 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -17,62 +17,65 @@ * * You must have boardlinks or else this script will not load. * Search for "$config['boards'] = array(" within your inc/config.php and add something similar to your instance-config.php. - * */ - -auto_reload_enabled = true; // for watch.js to interop +auto_reload_enabled = true; // For watch.js to interop. $(document).ready(function(){ - if($('div.banner').length == 0) - return; // not index - - if($(".post.op").size() != 1) - return; //not thread page - + if($('div.banner').length == 0) { + // Not index. + return; + } + + if($(".post.op").size() != 1) { + // Not thread page. + return; + } + var countdown_interval; - // Add an update link + // Add an update link. $('.boardlist.bottom').prev().after("["+_("Update")+"] ( "+_("Auto")+") "); - // Grab the settings + // Grab the settings. var settings = new script_settings('auto-reload'); var poll_interval_mindelay = settings.get('min_delay_bottom', 5000); var poll_interval_maxdelay = settings.get('max_delay', 600000); var poll_interval_errordelay = settings.get('error_delay', 30000); - // number of ms to wait before reloading + // number of ms to wait before reloading. var poll_interval_delay = poll_interval_mindelay; var poll_current_time = poll_interval_delay; var end_of_page = false; - var new_posts = 0; + var new_posts = 0; var first_new_post = null; - + var title = document.title; if (typeof update_title == "undefined") { - var update_title = function() { - if (new_posts) { - document.title = "("+new_posts+") "+title; - } else { - document.title = title; - } - }; + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + } + }; } - if (typeof add_title_collector != "undefined") - add_title_collector(function(){ - return new_posts; - }); + if (typeof add_title_collector != "undefined") { + add_title_collector(function() { + return new_posts; + }); + } var window_active = true; $(window).focus(function() { window_active = true; recheck_activated(); - // Reset the delay if needed + // Reset the delay if needed. if(settings.get('reset_focus', true)) { poll_interval_delay = poll_interval_mindelay; } @@ -80,7 +83,7 @@ $(document).ready(function(){ $(window).blur(function() { window_active = false; }); - + $('#auto_update_status').click(function() { if($("#auto_update_status").is(':checked')) { @@ -89,14 +92,13 @@ $(document).ready(function(){ stop_auto_update(); $('#update_secs').text(""); } - }); - + var decrement_timer = function() { poll_current_time = poll_current_time - 1000; $('#update_secs').text(poll_current_time/1000); - + if (poll_current_time <= 0) { poll(manualUpdate = false); } @@ -112,37 +114,37 @@ $(document).ready(function(){ update_title(); first_new_post = null; }; - + // automatically updates the thread after a specified delay var auto_update = function(delay) { clearInterval(countdown_interval); - poll_current_time = delay; + poll_current_time = delay; countdown_interval = setInterval(decrement_timer, 1000); - $('#update_secs').text(poll_current_time/1000); + $('#update_secs').text(poll_current_time/1000); } - + var stop_auto_update = function() { clearInterval(countdown_interval); } - - var epoch = (new Date).getTime(); - var epochold = epoch; - + + var epoch = (new Date).getTime(); + var epochold = epoch; + var timeDiff = function (delay) { - if((epoch-epochold) > delay) { + if ((epoch-epochold) > delay) { epochold = epoch = (new Date).getTime(); return true; - }else{ + } else { epoch = (new Date).getTime(); return; } } - + var poll = function(manualUpdate) { stop_auto_update(); $('#update_secs').text(_("Updating...")); - + $.ajax({ url: document.location, success: function(data) { @@ -168,15 +170,15 @@ $(document).ready(function(){ $(document).trigger('new_post', ele); }); time_loaded = Date.now(); // interop with watch.js - - + + if ($('#auto_update_status').is(':checked')) { // If there are no new posts, double the delay. Otherwise set it to the min. if(loaded_posts == 0) { // if the update was manual, don't increase the delay if (manualUpdate == false) { poll_interval_delay *= 2; - + // Don't increase the delay beyond the maximum if(poll_interval_delay > poll_interval_maxdelay) { poll_interval_delay = poll_interval_maxdelay; @@ -185,7 +187,7 @@ $(document).ready(function(){ } else { poll_interval_delay = poll_interval_mindelay; } - + auto_update(poll_interval_delay); } else { // Decide the message to show if auto update is disabled @@ -210,7 +212,7 @@ $(document).ready(function(){ } else { $('#update_secs').text(_("Unknown error")); } - + // Keep trying to update if ($('#auto_update_status').is(':checked')) { poll_interval_delay = poll_interval_errordelay; @@ -218,14 +220,14 @@ $(document).ready(function(){ } } }); - + return false; }; - + $(window).scroll(function() { recheck_activated(); - - // if the newest post is not visible + + // If the newest post is not visible. if($(this).scrollTop() + $(this).height() < $('div.post:last').position().top + $('div.post:last').height()) { end_of_page = false;