From 0d27227359df5597d4dc3b646eaa63082f42e4f0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 29 Nov 2018 22:21:09 +0300 Subject: use xhrPost in more places; various minor cleanup --- js/functions.js | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index 25dc587dc..7fbb4e75d 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1,10 +1,9 @@ /* global dijit, __ */ -var loading_progress = 0; -var sanity_check_done = false; -var init_params = {}; -var _label_base_index = -1024; -var notify_hide_timerid = false; +let init_params = {}; +let _label_base_index = -1024; +let loading_progress = 0; +let notify_hide_timerid = false; Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( function (callOriginal, options) { @@ -24,6 +23,29 @@ Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( } ); +/* xhr shorthand helpers */ + +function xhrPost(url, params, complete) { + console.log("xhrPost:", params); + new Ajax.Request(url, { + parameters: params, + onComplete: complete + }); +} + +function xhrJson(url, params, complete) { + xhrPost(url, params, (reply) => { + try { + const obj = JSON.parse(reply.responseText); + complete(obj); + } catch (e) { + console.error("xhrJson", e, reply); + complete(null); + } + + }) +} + /* add method to remove element from array */ Array.prototype.remove = function(s) { @@ -46,14 +68,14 @@ function exception_error(e, e_compat, filename, lineno, colno) { const msg = e.toString(); try { - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "log", + xhrPost("backend.php", + {op: "rpc", method: "log", file: e.fileName ? e.fileName : filename, line: e.lineNumber ? e.lineNumber : lineno, msg: msg, context: e.stack}, - onComplete: function (transport) { + (transport) => { console.warn(transport.responseText); - } }); + }); } catch (e) { console.error("Exception while trying to log the error.", e); @@ -1082,13 +1104,6 @@ function unsubscribeFeed(feed_id, title) { function backend_sanity_check_callback(transport) { - if (sanity_check_done) { - fatalError(11, "Sanity check request received twice. This can indicate "+ - "presence of Firebug or some other disrupting extension. "+ - "Please disable it and try again."); - return; - } - const reply = JSON.parse(transport.responseText); if (!reply) { @@ -1120,10 +1135,7 @@ function backend_sanity_check_callback(transport) { window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); } - sanity_check_done = true; - init_second_stage(); - } function genUrlChangeKey(feed, is_cat) { -- cgit v1.2.3