forked from leftypol/leftypol
Improve broken auto-reload
This commit is contained in:
parent
0806e39c03
commit
fa4f543a2d
2 changed files with 16 additions and 20 deletions
|
@ -80,7 +80,6 @@ $(window).ready(function() {
|
||||||
|| (!settings.get('always_noko_replies', true) && !post_response.noko)) {
|
|| (!settings.get('always_noko_replies', true) && !post_response.noko)) {
|
||||||
document.location = post_response.redirect;
|
document.location = post_response.redirect;
|
||||||
} else {
|
} else {
|
||||||
/*
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: document.location,
|
url: document.location,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
|
@ -89,6 +88,8 @@ $(window).ready(function() {
|
||||||
if($('#' + id).length == 0) {
|
if($('#' + id).length == 0) {
|
||||||
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
|
$(this).insertAfter($('div.post:last').next()).after('<br class="clear">');
|
||||||
$(document).trigger('new_post', this);
|
$(document).trigger('new_post', this);
|
||||||
|
// auto-reload.js immediate update on own post
|
||||||
|
$(document).trigger('own_new_post', this);
|
||||||
// watch.js & auto-reload.js retrigger
|
// watch.js & auto-reload.js retrigger
|
||||||
setTimeout(function() { $(window).trigger("scroll"); }, 100);
|
setTimeout(function() { $(window).trigger("scroll"); }, 100);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +108,6 @@ $(window).ready(function() {
|
||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false
|
processData: false
|
||||||
}, 'html');
|
}, 'html');
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
$(form).find('input[type="submit"]').val(_('Posted...'));
|
$(form).find('input[type="submit"]').val(_('Posted...'));
|
||||||
$(document).trigger("ajax_after_post", post_response);
|
$(document).trigger("ajax_after_post", post_response);
|
||||||
|
|
|
@ -46,7 +46,7 @@ $(document).ready(function(){
|
||||||
if($('div.banner').length == 0)
|
if($('div.banner').length == 0)
|
||||||
{
|
{
|
||||||
return; // not index
|
return; // not index
|
||||||
}
|
}
|
||||||
if($(".post.op").length != 1)
|
if($(".post.op").length != 1)
|
||||||
{
|
{
|
||||||
return; //not thread page
|
return; //not thread page
|
||||||
|
@ -75,7 +75,6 @@ $(document).ready(function(){
|
||||||
if (!("Notification" in window)) return;
|
if (!("Notification" in window)) return;
|
||||||
|
|
||||||
var setting = $(this).parent().attr('id');
|
var setting = $(this).parent().attr('id');
|
||||||
|
|
||||||
if ($(this).is(':checked')) {
|
if ($(this).is(':checked')) {
|
||||||
Notification.requestPermission(function(permission){
|
Notification.requestPermission(function(permission){
|
||||||
if (permission === "granted") {
|
if (permission === "granted") {
|
||||||
|
@ -137,7 +136,7 @@ $(document).ready(function(){
|
||||||
var title = document.title;
|
var title = document.title;
|
||||||
|
|
||||||
if (typeof update_title == "undefined") {
|
if (typeof update_title == "undefined") {
|
||||||
var update_title = function() {
|
var update_title = function() {
|
||||||
if (new_posts) {
|
if (new_posts) {
|
||||||
document.title = "("+new_posts+") "+title;
|
document.title = "("+new_posts+") "+title;
|
||||||
} else {
|
} else {
|
||||||
|
@ -165,7 +164,6 @@ $(document).ready(function(){
|
||||||
$(window).blur(function() {
|
$(window).blur(function() {
|
||||||
window_active = false;
|
window_active = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#auto_update_status').click(function() {
|
$('#auto_update_status').click(function() {
|
||||||
if($("#auto_update_status").is(':checked')) {
|
if($("#auto_update_status").is(':checked')) {
|
||||||
|
@ -176,7 +174,6 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var decrement_timer = function() {
|
var decrement_timer = function() {
|
||||||
poll_current_time = poll_current_time - 1000;
|
poll_current_time = poll_current_time - 1000;
|
||||||
|
@ -203,18 +200,18 @@ $(document).ready(function(){
|
||||||
var auto_update = function(delay) {
|
var auto_update = function(delay) {
|
||||||
clearInterval(countdown_interval);
|
clearInterval(countdown_interval);
|
||||||
|
|
||||||
poll_current_time = delay;
|
poll_current_time = delay;
|
||||||
countdown_interval = setInterval(decrement_timer, 1000);
|
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() {
|
var stop_auto_update = function() {
|
||||||
clearInterval(countdown_interval);
|
clearInterval(countdown_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
var epoch = (new Date).getTime();
|
var epoch = (new Date).getTime();
|
||||||
var epochold = epoch;
|
var epochold = epoch;
|
||||||
|
|
||||||
var timeDiff = function (delay) {
|
var timeDiff = function (delay) {
|
||||||
if((epoch-epochold) > delay) {
|
if((epoch-epochold) > delay) {
|
||||||
epochold = epoch = (new Date).getTime();
|
epochold = epoch = (new Date).getTime();
|
||||||
|
@ -228,8 +225,9 @@ $(document).ready(function(){
|
||||||
var poll = function(manualUpdate) {
|
var poll = function(manualUpdate) {
|
||||||
stop_auto_update();
|
stop_auto_update();
|
||||||
$('#update_secs').text(_("Updating..."));
|
$('#update_secs').text(_("Updating..."));
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
cache: !manualUpdate,
|
||||||
url: document.location,
|
url: document.location,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
var loaded_posts = 0; // the number of new posts loaded in this update
|
var loaded_posts = 0; // the number of new posts loaded in this update
|
||||||
|
@ -262,7 +260,6 @@ $(document).ready(function(){
|
||||||
|
|
||||||
time_loaded = Date.now(); // interop with watch.js
|
time_loaded = Date.now(); // interop with watch.js
|
||||||
|
|
||||||
|
|
||||||
if ($('#auto_update_status').is(':checked')) {
|
if ($('#auto_update_status').is(':checked')) {
|
||||||
// If there are no new posts, double the delay. Otherwise set it to the min.
|
// If there are no new posts, double the delay. Otherwise set it to the min.
|
||||||
if(loaded_posts == 0) {
|
if(loaded_posts == 0) {
|
||||||
|
@ -315,13 +312,11 @@ $(document).ready(function(){
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
$(post).on('submit', function(e){
|
$(document).on('own_new_post', function(e){
|
||||||
setTimeout(
|
//prevent automatic window scroll from double updating
|
||||||
function() {
|
epochold = epoch = (new Date).getTime();
|
||||||
poll(manualUpdate = true)
|
|
||||||
},
|
poll(manualUpdate = true);
|
||||||
500
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(window).scrollStopped(function() {
|
$(window).scrollStopped(function() {
|
||||||
|
@ -338,6 +333,7 @@ $(document).ready(function(){
|
||||||
recheck_activated(end_of_page);
|
recheck_activated(end_of_page);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$('#update_thread').on('click', function() { poll(manualUpdate = true); return false; });
|
$('#update_thread').on('click', function() { poll(manualUpdate = true); return false; });
|
||||||
|
|
||||||
if($("#auto_update_status").is(':checked')) {
|
if($("#auto_update_status").is(':checked')) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue