X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=js%2Ffunctions.js;h=25aa26d39201a576df175a472709ba5b1774f66b;hb=bfdbc454678bca4cb1e178aa52ed764c9713a180;hp=2e9e544a9372fcba1fb58b0cfc1100e5639e9127;hpb=3857536f70057370810c70145cf8e54af5fdcd78;p=tt-rss.git diff --git a/js/functions.js b/js/functions.js old mode 100755 new mode 100644 index 2e9e544a..25aa26d3 --- a/js/functions.js +++ b/js/functions.js @@ -1,8 +1,12 @@ -var loading_progress = 0; -var sanity_check_done = false; -var init_params = {}; -var _label_base_index = -1024; -var notify_hide_timerid = false; +/* global dijit, __ */ + +let init_params = {}; +let _label_base_index = -1024; +let loading_progress = 0; +let notify_hide_timerid = false; + +let hotkey_prefix = 0; +let hotkey_prefix_pressed = false; Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( function (callOriginal, options) { @@ -22,72 +26,75 @@ Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( } ); +/* xhr shorthand helpers */ + +function xhrPost(url, params, complete) { + console.log("xhrPost:", params); + return new Ajax.Request(url, { + parameters: params, + onComplete: complete + }); +} + +function xhrJson(url, params, complete) { + return 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) { - for (var i=0; i < this.length; i++) { + for (let i=0; i < this.length; i++) { if (s == this[i]) this.splice(i, 1); } }; -/* create console.log if it doesn't exist */ - -if (!window.console) console = {}; -console.log = console.log || function(msg) { }; -console.warn = console.warn || function(msg) { }; -console.error = console.error || function(msg) { }; +function report_error(message, filename, lineno, colno, error) { + exception_error(error, null, filename, lineno); +} -function exception_error(location, e, ext_info) { - var msg = format_exception_error(location, e); +function exception_error(e, e_compat, filename, lineno, colno) { + if (typeof e == "string") e = e_compat; - if (!ext_info) ext_info = false; + if (!e) return; // no exception object, nothing to report. try { - - if (ext_info) - ext_info = JSON.stringify(ext_info); + console.error(e); + const msg = e.toString(); try { - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "log", logmsg: msg}, - onComplete: function (transport) { - console.log(transport.responseText); - } }); - - } catch (eii) { - console.log("Exception while trying to log the error."); - console.log(eii); - } - - msg += "
"+ __("The error will be reported to the configured log destination.") + - "
"; - - var content = "" + msg + ""; - - content += "