From da1e060c54902fef1239bec1b23c0b53cedf0010 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Mon, 4 Jan 2021 00:34:55 -0500 Subject: [PATCH 1/4] Retab auto-reload.js --- js/auto-reload.js | 554 +++++++++++++++++++++++----------------------- 1 file changed, 277 insertions(+), 277 deletions(-) diff --git a/js/auto-reload.js b/js/auto-reload.js index 44ec58da..544f5df9 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -18,24 +18,24 @@ */ // From http://stackoverflow.com/a/14035162 -$.fn.scrollStopped = function(callback) { - $(this).scroll(function(){ - var self = this, $this = $(self); - if ($this.data('scrollTimeout')) { - clearTimeout($this.data('scrollTimeout')); - } - $this.data('scrollTimeout', setTimeout(callback,250,self)); - }); +$.fn.scrollStopped = function(callback) { + $(this).scroll(function(){ + var self = this, $this = $(self); + if ($this.data('scrollTimeout')) { + clearTimeout($this.data('scrollTimeout')); + } + $this.data('scrollTimeout', setTimeout(callback,250,self)); + }); }; function makeIcon(mode){ - var favicon = $("link[rel='shortcut icon']"); + var favicon = $("link[rel='shortcut icon']"); - if (!favicon.length) { - var favicon = $('').appendTo('head'); - } + if (!favicon.length) { + var favicon = $('').appendTo('head'); + } - $("link[rel='shortcut icon']").attr("href", configRoot+"static/favicon"+(mode?"-"+mode:"")+".ico"); + $("link[rel='shortcut icon']").attr("href", configRoot+"static/favicon"+(mode?"-"+mode:"")+".ico"); } +function(){ @@ -43,297 +43,297 @@ var notify = false; auto_reload_enabled = true; // for watch.js to interop $(document).ready(function(){ - if($('div.banner').length == 0) - { - return; // not index - } - if($(".post.op").length != 1) - { - return; //not thread page - } + if($('div.banner').length == 0) + { + return; // not index + } + if($(".post.op").length != 1) + { + return; //not thread page + } - // Adds Options panel item - if (typeof localStorage.auto_thread_update === 'undefined') { - localStorage.auto_thread_update = 'true'; //default value - } - if (window.Options && Options.get_tab('general')) { - Options.extend_tab("general", "
"+_("Auto update")+"" - + ('') - + ('') - + ('') - + '
'); + // Adds Options panel item + if (typeof localStorage.auto_thread_update === 'undefined') { + localStorage.auto_thread_update = 'true'; //default value + } + if (window.Options && Options.get_tab('general')) { + Options.extend_tab("general", "
"+_("Auto update")+"" + + ('') + + ('') + + ('') + + '
'); - $('#auto-thread-update>input').on('click', function() { - if ($('#auto-thread-update>input').is(':checked')) { - localStorage.auto_thread_update = 'true'; - } else { - localStorage.auto_thread_update = 'false'; - } - }); + $('#auto-thread-update>input').on('click', function() { + if ($('#auto-thread-update>input').is(':checked')) { + localStorage.auto_thread_update = 'true'; + } else { + localStorage.auto_thread_update = 'false'; + } + }); - $('#auto_thread_desktop_notifications>input,#auto_thread_desktop_notifications_all>input').on('click', function() { - if (!("Notification" in window)) return; - - var setting = $(this).parent().attr('id'); + $('#auto_thread_desktop_notifications>input,#auto_thread_desktop_notifications_all>input').on('click', function() { + if (!("Notification" in window)) return; + + var setting = $(this).parent().attr('id'); - if ($(this).is(':checked')) { - Notification.requestPermission(function(permission){ - if (permission === "granted") { - localStorage[setting] = 'true'; - } - }); - if (Notification.permission === "granted") { - localStorage[setting] = 'true'; - } - } else { - localStorage[setting] = 'false'; - } - }); + if ($(this).is(':checked')) { + Notification.requestPermission(function(permission){ + if (permission === "granted") { + localStorage[setting] = 'true'; + } + }); + if (Notification.permission === "granted") { + localStorage[setting] = 'true'; + } + } else { + localStorage[setting] = 'false'; + } + }); - if (localStorage.auto_thread_update === 'true') { - $('#auto-thread-update>input').prop('checked', true); - } + if (localStorage.auto_thread_update === 'true') { + $('#auto-thread-update>input').prop('checked', true); + } - if (localStorage.auto_thread_desktop_notifications === 'true') { - $('#auto_thread_desktop_notifications>input').prop('checked', true); - notify = "mention"; - } + if (localStorage.auto_thread_desktop_notifications === 'true') { + $('#auto_thread_desktop_notifications>input').prop('checked', true); + notify = "mention"; + } - if (localStorage.auto_thread_desktop_notifications_all === 'true') { - $('#auto_thread_desktop_notifications_all>input').prop('checked', true); - notify = "all"; - } - } + if (localStorage.auto_thread_desktop_notifications_all === 'true') { + $('#auto_thread_desktop_notifications_all>input').prop('checked', true); + notify = "all"; + } + } - // not thread - if (active_page != 'thread') - return; + // not thread + if (active_page != 'thread') + return; - var countdown_interval; + var countdown_interval; - // Add an update link - $(".threadlinks span:last-child").append("["+_("Update")+"] ( "+_("Auto")+") "); + // Add an update link + $(".threadlinks span:last-child").append("["+_("Update")+"] ( "+_("Auto")+") "); - // Set the updater checkbox according to user setting - if (localStorage.auto_thread_update === 'true') { - $('#auto_update_status').prop('checked', true); - } + // Set the updater checkbox according to user setting + if (localStorage.auto_thread_update === 'true') { + $('#auto_update_status').prop('checked', true); + } - // 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); + // 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 - var poll_interval_delay = poll_interval_mindelay; - var poll_current_time = poll_interval_delay; + // 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 end_of_page = false; - var new_posts = 0; - var first_new_post = null; - - var title = document.title; + 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; - makeIcon(false); - } - }; - } + if (typeof update_title == "undefined") { + var update_title = function() { + if (new_posts) { + document.title = "("+new_posts+") "+title; + } else { + document.title = title; + makeIcon(false); + } + }; + } - 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(); + var window_active = true; + $(window).focus(function() { + window_active = true; + recheck_activated(); - // Reset the delay if needed - if(settings.get('reset_focus', true)) { - poll_interval_delay = poll_interval_mindelay; - } - }); - $(window).blur(function() { - window_active = false; - }); - + // Reset the delay if needed + if(settings.get('reset_focus', true)) { + poll_interval_delay = poll_interval_mindelay; + } + }); + $(window).blur(function() { + window_active = false; + }); + - $('#auto_update_status').click(function() { - if($("#auto_update_status").is(':checked')) { - auto_update(poll_interval_mindelay); - } else { - stop_auto_update(); - $('#update_secs').text(""); - } + $('#auto_update_status').click(function() { + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_mindelay); + } else { + 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); - } - } + 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); + } + } - var recheck_activated = function(end_of_page) { - if (typeof end_of_page == "undefined") var end_of_page = false; - if (end_of_page || (new_posts && window_active && - $(window).scrollTop() + $(window).height() >= - $('div.boardlist.bottom').position().top)) { + var recheck_activated = function(end_of_page) { + if (typeof end_of_page == "undefined") var end_of_page = false; + if (end_of_page || (new_posts && window_active && + $(window).scrollTop() + $(window).height() >= + $('div.boardlist.bottom').position().top)) { - new_posts = 0; - } - update_title(); - first_new_post = null; - }; - - // automatically updates the thread after a specified delay - var auto_update = function(delay) { - clearInterval(countdown_interval); + new_posts = 0; + } + 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; - countdown_interval = setInterval(decrement_timer, 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 timeDiff = function (delay) { - if((epoch-epochold) > delay) { - epochold = epoch = (new Date).getTime(); - return true; - }else{ - epoch = (new Date).getTime(); - return; - } - } - - var poll = function(manualUpdate) { - stop_auto_update(); - $('#update_secs').text(_("Updating...")); - - $.ajax({ - url: document.location, - success: function(data) { - var loaded_posts = 0; // the number of new posts loaded in this update - $(data).find('div.post.reply').each(function() { - var id = $(this).attr('id'); - if($('#' + id).length == 0) { - if (!new_posts) { - first_new_post = this; - makeIcon('reply'); - if (notify === "all" || (notify === "mention" && $(this).find('.own_post').length)) { - var body = $(this).children('.body').html().replace(//gi, "\n"); - var n = new Notification("New reply to "+$('title').text(), {body: $('
').html(body).text()}); - } - } - if ($("div.post").length > 1){ - $(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('
'); - } - else { - $(this).insertAfter($('div.post:not(.post-hover):last')).after('
'); - } - new_posts++; - loaded_posts++; - $(document).trigger('new_post', this); - recheck_activated(); - } - }); - 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; - } - } - } else { - poll_interval_delay = poll_interval_mindelay; - } - - auto_update(poll_interval_delay); - } else { - // Decide the message to show if auto update is disabled - if (loaded_posts > 0) - $('#update_secs').text(fmt(_("Thread updated with {0} new post(s)"), [loaded_posts])); - else - $('#update_secs').text(_("No new posts found")); - } - }, - error: function(xhr, status_text, error_text) { - if (status_text == "error") { - if (error_text == "Not Found") { - $('#update_secs').text(_("Thread deleted or pruned")); - $('#auto_update_status').prop('checked', false); - $('#auto_update_status').prop('disabled', true); // disable updates if thread is deleted - return; - } else { - $('#update_secs').text("Error: "+error_text); - } - } else if (status_text) { - $('#update_secs').text(_("Error: ")+status_text); - } else { - $('#update_secs').text(_("Unknown error")); - } - - // Keep trying to update - if ($('#auto_update_status').is(':checked')) { - poll_interval_delay = poll_interval_errordelay; - auto_update(poll_interval_delay); - } - } - }); - - return false; - }; + poll_current_time = delay; + countdown_interval = setInterval(decrement_timer, 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 timeDiff = function (delay) { + if((epoch-epochold) > delay) { + epochold = epoch = (new Date).getTime(); + return true; + }else{ + epoch = (new Date).getTime(); + return; + } + } + + var poll = function(manualUpdate) { + stop_auto_update(); + $('#update_secs').text(_("Updating...")); + + $.ajax({ + url: document.location, + success: function(data) { + var loaded_posts = 0; // the number of new posts loaded in this update + $(data).find('div.post.reply').each(function() { + var id = $(this).attr('id'); + if($('#' + id).length == 0) { + if (!new_posts) { + first_new_post = this; + makeIcon('reply'); + if (notify === "all" || (notify === "mention" && $(this).find('.own_post').length)) { + var body = $(this).children('.body').html().replace(//gi, "\n"); + var n = new Notification("New reply to "+$('title').text(), {body: $('
').html(body).text()}); + } + } + if ($("div.post").length > 1){ + $(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('
'); + } + else { + $(this).insertAfter($('div.post:not(.post-hover):last')).after('
'); + } + new_posts++; + loaded_posts++; + $(document).trigger('new_post', this); + recheck_activated(); + } + }); + 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; + } + } + } else { + poll_interval_delay = poll_interval_mindelay; + } + + auto_update(poll_interval_delay); + } else { + // Decide the message to show if auto update is disabled + if (loaded_posts > 0) + $('#update_secs').text(fmt(_("Thread updated with {0} new post(s)"), [loaded_posts])); + else + $('#update_secs').text(_("No new posts found")); + } + }, + error: function(xhr, status_text, error_text) { + if (status_text == "error") { + if (error_text == "Not Found") { + $('#update_secs').text(_("Thread deleted or pruned")); + $('#auto_update_status').prop('checked', false); + $('#auto_update_status').prop('disabled', true); // disable updates if thread is deleted + return; + } else { + $('#update_secs').text("Error: "+error_text); + } + } else if (status_text) { + $('#update_secs').text(_("Error: ")+status_text); + } else { + $('#update_secs').text(_("Unknown error")); + } + + // Keep trying to update + if ($('#auto_update_status').is(':checked')) { + poll_interval_delay = poll_interval_errordelay; + auto_update(poll_interval_delay); + } + } + }); + + return false; + }; - $(post).on('submit', function(e){ - poll(manualUpdate = true); - dothis(this); - }); - - $(window).scrollStopped(function() { - // 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; - } else { - if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { - poll(manualUpdate = true); - } - end_of_page = true; - } - recheck_activated(end_of_page); - }); + $(post).on('submit', function(e){ + poll(manualUpdate = true); + dothis(this); + }); + + $(window).scrollStopped(function() { + // 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; + } else { + if($("#auto_update_status").is(':checked') && timeDiff(poll_interval_mindelay)) { + poll(manualUpdate = true); + } + end_of_page = true; + } + 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')) { - auto_update(poll_interval_delay); - } + if($("#auto_update_status").is(':checked')) { + auto_update(poll_interval_delay); + } }); }(); From 11ee04f9730635c9fe4baebdc447342780cfe296 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Mon, 4 Jan 2021 02:32:45 -0500 Subject: [PATCH 2/4] retab ajax.js --- js/ajax.js | 240 ++++++++++++++++++++++++++--------------------------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 1072031d..a85840d9 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -13,128 +13,128 @@ */ $(window).ready(function() { - var settings = new script_settings('ajax'); - var do_not_ajax = false; + var settings = new script_settings('ajax'); + var do_not_ajax = false; - // Enable submit button if disabled (cache problem) - $('input[type="submit"]').removeAttr('disabled'); - - var setup_form = function($form) { - $form.submit(function() { - if (do_not_ajax) - return true; - var form = this; - var submit_txt = $(this).find('input[type="submit"]').val(); - if (window.FormData === undefined) - return true; - - var formData = new FormData(this); - formData.append('json_response', '1'); - formData.append('post', submit_txt); + // Enable submit button if disabled (cache problem) + $('input[type="submit"]').removeAttr('disabled'); + + var setup_form = function($form) { + $form.submit(function() { + if (do_not_ajax) + return true; + var form = this; + var submit_txt = $(this).find('input[type="submit"]').val(); + if (window.FormData === undefined) + return true; + + var formData = new FormData(this); + formData.append('json_response', '1'); + formData.append('post', submit_txt); - $(document).trigger("ajax_before_post", formData); + $(document).trigger("ajax_before_post", formData); - var updateProgress = function(e) { - var percentage; - if (e.position === undefined) { // Firefox - percentage = Math.round(e.loaded * 100 / e.total); - } - else { // Chrome? - percentage = Math.round(e.position * 100 / e.total); - } - $(form).find('input[type="submit"]').val(_('Posting... (#%)').replace('#', percentage)); - }; + var updateProgress = function(e) { + var percentage; + if (e.position === undefined) { // Firefox + percentage = Math.round(e.loaded * 100 / e.total); + } + else { // Chrome? + percentage = Math.round(e.position * 100 / e.total); + } + $(form).find('input[type="submit"]').val(_('Posting... (#%)').replace('#', percentage)); + }; - $.ajax({ - url: this.action, - type: 'POST', - xhr: function() { - var xhr = $.ajaxSettings.xhr(); - if(xhr.upload) { - xhr.upload.addEventListener('progress', updateProgress, false); - } - return xhr; - }, - success: function(post_response) { - if (post_response.error) { - if (post_response.banned) { - // You are banned. Must post the form normally so the user can see the ban message. - do_not_ajax = true; - $(form).find('input[type="submit"]').each(function() { - var $replacement = $(''); - $replacement.attr('name', $(this).attr('name')); - $replacement.val(submit_txt); - $(this) - .after($replacement) - .replaceWith($('').val(submit_txt)); - }); - $(form).submit(); - } else { - alert(post_response.error); - $(form).find('input[type="submit"]').val(submit_txt); - $(form).find('input[type="submit"]').removeAttr('disabled'); - } - } else if (post_response.redirect && post_response.id) { - if (!$(form).find('input[name="thread"]').length - || (!settings.get('always_noko_replies', true) && !post_response.noko)) { - document.location = post_response.redirect; - } else { - $.ajax({ - url: document.location, - success: function(data) { - $(data).find('div.post.reply').each(function() { - var id = $(this).attr('id'); - if($('#' + id).length == 0) { - $(this).insertAfter($('div.post:last').next()).after('
'); - $(document).trigger('new_post', this); - // watch.js & auto-reload.js retrigger - setTimeout(function() { $(window).trigger("scroll"); }, 100); - } - }); - - highlightReply(post_response.id); - window.location.hash = post_response.id; - $(window).scrollTop($(document).height()); - - $(form).find('input[type="submit"]').val(submit_txt); - $(form).find('input[type="submit"]').removeAttr('disabled'); - $(form).find('input[name="subject"],input[name="file_url"],\ - textarea[name="body"],input[type="file"]').val('').change(); - }, - cache: false, - contentType: false, - processData: false - }, 'html'); - } - $(form).find('input[type="submit"]').val(_('Posted...')); - $(document).trigger("ajax_after_post", post_response); - } else { - alert(_('An unknown error occured when posting!')); - $(form).find('input[type="submit"]').val(submit_txt); - $(form).find('input[type="submit"]').removeAttr('disabled'); - } - }, - error: function(xhr, status, er) { - console.log(xhr); - alert(_('The server took too long to submit your post. Your post was probably still submitted. If it wasn\'t, we might be experiencing issues right now -- please try your post again later. Error information: ') + "
"); - $(form).find('input[type="submit"]').val(submit_txt); - $(form).find('input[type="submit"]').removeAttr('disabled'); - }, - data: formData, - cache: false, - contentType: false, - processData: false - }, 'json'); - - $(form).find('input[type="submit"]').val(_('Posting...')); - $(form).find('input[type="submit"]').attr('disabled', true); - - return false; - }); - }; - setup_form($('form[name="post"]')); - $(window).on('quick-reply', function() { - $('form#quick-reply').off('submit'); - setup_form($('form#quick-reply')); - }); + $.ajax({ + url: this.action, + type: 'POST', + xhr: function() { + var xhr = $.ajaxSettings.xhr(); + if(xhr.upload) { + xhr.upload.addEventListener('progress', updateProgress, false); + } + return xhr; + }, + success: function(post_response) { + if (post_response.error) { + if (post_response.banned) { + // You are banned. Must post the form normally so the user can see the ban message. + do_not_ajax = true; + $(form).find('input[type="submit"]').each(function() { + var $replacement = $(''); + $replacement.attr('name', $(this).attr('name')); + $replacement.val(submit_txt); + $(this) + .after($replacement) + .replaceWith($('').val(submit_txt)); + }); + $(form).submit(); + } else { + alert(post_response.error); + $(form).find('input[type="submit"]').val(submit_txt); + $(form).find('input[type="submit"]').removeAttr('disabled'); + } + } else if (post_response.redirect && post_response.id) { + if (!$(form).find('input[name="thread"]').length + || (!settings.get('always_noko_replies', true) && !post_response.noko)) { + document.location = post_response.redirect; + } else { + $.ajax({ + url: document.location, + success: function(data) { + $(data).find('div.post.reply').each(function() { + var id = $(this).attr('id'); + if($('#' + id).length == 0) { + $(this).insertAfter($('div.post:last').next()).after('
'); + $(document).trigger('new_post', this); + // watch.js & auto-reload.js retrigger + setTimeout(function() { $(window).trigger("scroll"); }, 100); + } + }); + + highlightReply(post_response.id); + window.location.hash = post_response.id; + $(window).scrollTop($(document).height()); + + $(form).find('input[type="submit"]').val(submit_txt); + $(form).find('input[type="submit"]').removeAttr('disabled'); + $(form).find('input[name="subject"],input[name="file_url"],\ + textarea[name="body"],input[type="file"]').val('').change(); + }, + cache: false, + contentType: false, + processData: false + }, 'html'); + } + $(form).find('input[type="submit"]').val(_('Posted...')); + $(document).trigger("ajax_after_post", post_response); + } else { + alert(_('An unknown error occured when posting!')); + $(form).find('input[type="submit"]').val(submit_txt); + $(form).find('input[type="submit"]').removeAttr('disabled'); + } + }, + error: function(xhr, status, er) { + console.log(xhr); + alert(_('The server took too long to submit your post. Your post was probably still submitted. If it wasn\'t, we might be experiencing issues right now -- please try your post again later. Error information: ') + "
"); + $(form).find('input[type="submit"]').val(submit_txt); + $(form).find('input[type="submit"]').removeAttr('disabled'); + }, + data: formData, + cache: false, + contentType: false, + processData: false + }, 'json'); + + $(form).find('input[type="submit"]').val(_('Posting...')); + $(form).find('input[type="submit"]').attr('disabled', true); + + return false; + }); + }; + setup_form($('form[name="post"]')); + $(window).on('quick-reply', function() { + $('form#quick-reply').off('submit'); + setup_form($('form#quick-reply')); + }); }); From efb74f0eb6b667eea5368a0b4832638cadf755bb Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Mon, 4 Jan 2021 03:00:16 -0500 Subject: [PATCH 3/4] Fix for ajax posting not showing you your new post - TODO: there are console.logs that still need to be removed - Posting was loading the new page twice - once in ajax.js and once in auto-reload.js. auto-reload will handle this behaviour, the other is commented out - The new post does not immediately show up when immediately ajax requesting the page after posting completes. Adding an epoch query parameter did not change this. Instead of figuring out why it was easier to add a 500ms delay before requesting the page, now it seems to work well. --- js/ajax.js | 7 +++++++ js/auto-reload.js | 22 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index a85840d9..31634e9e 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -79,6 +79,8 @@ $(window).ready(function() { || (!settings.get('always_noko_replies', true) && !post_response.noko)) { document.location = post_response.redirect; } else { + console.log("do nothing for now, this behaviour will be handled by auto-reload.js"); + /* $.ajax({ url: document.location, success: function(data) { @@ -105,9 +107,14 @@ $(window).ready(function() { contentType: false, processData: false }, 'html'); + */ } $(form).find('input[type="submit"]').val(_('Posted...')); $(document).trigger("ajax_after_post", post_response); + $(form).find('input[type="submit"]').val(submit_txt); + $(form).find('input[type="submit"]').removeAttr('disabled'); + $(form).find('input[name="subject"],input[name="file_url"],\ + textarea[name="body"],input[type="file"]').val('').change(); } else { alert(_('An unknown error occured when posting!')); $(form).find('input[type="submit"]').val(submit_txt); diff --git a/js/auto-reload.js b/js/auto-reload.js index 544f5df9..5c2b7064 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -232,10 +232,18 @@ $(document).ready(function(){ $.ajax({ url: document.location, success: function(data) { + console.log("poll ajax succes"); + console.log(data); var loaded_posts = 0; // the number of new posts loaded in this update + $(data).find('div.post.reply').each(function() { + console.log("new data post reply:", this); var id = $(this).attr('id'); + console.log("new data post reply id:", id); + + // check that this post doesn't already exist if($('#' + id).length == 0) { + console.log("post with id ", id, "does not already exist on the page"); if (!new_posts) { first_new_post = this; makeIcon('reply'); @@ -245,17 +253,22 @@ $(document).ready(function(){ } } if ($("div.post").length > 1){ + console.log("adding post A"); $(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('
'); } else { + console.log("adding post B"); $(this).insertAfter($('div.post:not(.post-hover):last')).after('
'); } new_posts++; loaded_posts++; $(document).trigger('new_post', this); recheck_activated(); + } else { + console.log("post with id ", id, "already exists on the page, not adding"); } }); + time_loaded = Date.now(); // interop with watch.js @@ -312,8 +325,13 @@ $(document).ready(function(){ }; $(post).on('submit', function(e){ - poll(manualUpdate = true); - dothis(this); + console.log("post on submit"); + setTimeout( + function() { + poll(manualUpdate = true) + }, + 500 + ); }); $(window).scrollStopped(function() { From 86d847118c30cdef128fcbc1712422c1a4135571 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Mon, 4 Jan 2021 20:41:19 -0500 Subject: [PATCH 4/4] Remove console logs --- js/ajax.js | 1 - js/auto-reload.js | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index 31634e9e..c312c130 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -79,7 +79,6 @@ $(window).ready(function() { || (!settings.get('always_noko_replies', true) && !post_response.noko)) { document.location = post_response.redirect; } else { - console.log("do nothing for now, this behaviour will be handled by auto-reload.js"); /* $.ajax({ url: document.location, diff --git a/js/auto-reload.js b/js/auto-reload.js index 5c2b7064..623027d4 100644 --- a/js/auto-reload.js +++ b/js/auto-reload.js @@ -232,18 +232,13 @@ $(document).ready(function(){ $.ajax({ url: document.location, success: function(data) { - console.log("poll ajax succes"); - console.log(data); var loaded_posts = 0; // the number of new posts loaded in this update $(data).find('div.post.reply').each(function() { - console.log("new data post reply:", this); var id = $(this).attr('id'); - console.log("new data post reply id:", id); // check that this post doesn't already exist if($('#' + id).length == 0) { - console.log("post with id ", id, "does not already exist on the page"); if (!new_posts) { first_new_post = this; makeIcon('reply'); @@ -253,19 +248,15 @@ $(document).ready(function(){ } } if ($("div.post").length > 1){ - console.log("adding post A"); $(this).parent().insertAfter($('div.post:not(.post-hover):last').parent().next()).after('
'); } else { - console.log("adding post B"); $(this).insertAfter($('div.post:not(.post-hover):last')).after('
'); } new_posts++; loaded_posts++; $(document).trigger('new_post', this); recheck_activated(); - } else { - console.log("post with id ", id, "already exists on the page, not adding"); } }); @@ -325,7 +316,6 @@ $(document).ready(function(){ }; $(post).on('submit', function(e){ - console.log("post on submit"); setTimeout( function() { poll(manualUpdate = true)