diff --git a/index.php b/index.php index 6035ac186..f574eb4d6 100644 --- a/index.php +++ b/index.php @@ -135,12 +135,6 @@ - - diff --git a/js/AppBase.js b/js/AppBase.js new file mode 100644 index 000000000..8987d115e --- /dev/null +++ b/js/AppBase.js @@ -0,0 +1,35 @@ +'use strict' +/* global __, ngettext */ +define(["dojo/_base/declare"], function (declare) { + return declare("fox.AppBase", null, { + _initParams: [], + getInitParam: function(k) { + return this._initParams[k]; + }, + setInitParam: function(k, v) { + this._initParams[k] = v; + }, + constructor: function(args) { + // + }, + enableCsrfSupport: function() { + Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( + function (callOriginal, options) { + + if (App.getInitParam("csrf_token") != undefined) { + Object.extend(options, options || { }); + + if (Object.isString(options.parameters)) + options.parameters = options.parameters.toQueryParams(); + else if (Object.isHash(options.parameters)) + options.parameters = options.parameters.toObject(); + + options.parameters["csrf_token"] = App.getInitParam("csrf_token"); + } + + return callOriginal(options); + } + ); + } + }); +}); diff --git a/js/FeedTree.js b/js/FeedTree.js index 4a28bd2b0..37e3de2d1 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -123,7 +123,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], postCreate: function() { this.connect(this.model, "onChange", "updateCounter"); this.connect(this, "_expandNode", function() { - this.hideRead(getInitParam("hide_read_feeds"), getInitParam("hide_read_shows_special")); + this.hideRead(App.getInitParam("hide_read_feeds"), App.getInitParam("hide_read_shows_special")); }); this.inherited(arguments); diff --git a/js/Feeds.js b/js/Feeds.js index 8b6f6a707..d5371779f 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -83,7 +83,7 @@ define(["dojo/_base/declare"], function (declare) { if (id > 0) { if (has_img) { this.setIcon(id, false, - getInitParam("icons_url") + "/" + id + ".ico?" + has_img); + App.getInitParam("icons_url") + "/" + id + ".ico?" + has_img); } else { this.setIcon(id, false, 'images/blank_icon.gif'); } @@ -91,7 +91,7 @@ define(["dojo/_base/declare"], function (declare) { } } - this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); + this.hideOrShowFeeds(App.getInitParam("hide_read_feeds") == 1); this._counters_prev = elems; }, reloadCurrent: function(method) { @@ -132,7 +132,7 @@ define(["dojo/_base/declare"], function (declare) { let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; if (!force) - query.last_article_id = getInitParam("last_article_id"); + query.last_article_id = App.getInitParam("last_article_id"); xhrPost("backend.php", query, (transport) => { Utils.handleRpcJson(transport); @@ -160,7 +160,7 @@ define(["dojo/_base/declare"], function (declare) { const treeModel = new fox.FeedStoreModel({ store: store, query: { - "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed" + "type": App.getInitParam('enable_feed_cats') == 1 ? "category" : "feed" }, rootId: "root", rootLabel: "Feeds", @@ -221,9 +221,9 @@ define(["dojo/_base/declare"], function (declare) { this.open({feed: this.getActive(), is_cat: this.activeIsCat()}); } - this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); + this.hideOrShowFeeds(App.getInitParam("hide_read_feeds") == 1); - if (getInitParam("is_default_pw")) { + if (App.getInitParam("is_default_pw")) { console.warn("user password is at default value"); const dialog = new dijit.Dialog({ @@ -246,7 +246,7 @@ define(["dojo/_base/declare"], function (declare) { } // bw_limit disables timeout() so we request initial counters separately - if (getInitParam("bw_limit") == "1") { + if (App.getInitParam("bw_limit") == "1") { this.requestCounters(true); } else { setTimeout(() => { @@ -281,18 +281,18 @@ define(["dojo/_base/declare"], function (declare) { if (tree) return tree.selectFeed(feed, is_cat); }, toggleUnread: function() { - const hide = !(getInitParam("hide_read_feeds") == "1"); + const hide = !(App.getInitParam("hide_read_feeds") == "1"); xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { this.hideOrShowFeeds(hide); - setInitParam("hide_read_feeds", hide); + App.setInitParam("hide_read_feeds", hide); }); }, hideOrShowFeeds: function(hide) { const tree = dijit.byId("feedTree"); if (tree) - return tree.hideRead(hide, getInitParam("hide_read_shows_special")); + return tree.hideRead(hide, App.getInitParam("hide_read_shows_special")); }, open: function(params) { const feed = params.feed; @@ -366,7 +366,7 @@ define(["dojo/_base/declare"], function (declare) { if (viewfeed_debug) { window.open("backend.php?" + dojo.objectToQuery( - Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query) + Object.assign({debug: 1, csrf_token: App.getInitParam("csrf_token")}, query) )); } @@ -389,7 +389,7 @@ define(["dojo/_base/declare"], function (declare) { catchupAll: function() { const str = __("Mark all articles as read?"); - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { Notify.progress("Marking all feeds as read..."); @@ -448,7 +448,7 @@ define(["dojo/_base/declare"], function (declare) { str = str.replace("%s", fn) .replace("%w", mark_what); - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { return; } @@ -463,7 +463,7 @@ define(["dojo/_base/declare"], function (declare) { xhrPost("backend.php", catchup_query, (transport) => { Utils.handleRpcJson(transport); - const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; + const show_next_feed = App.getInitParam("on_catchup_show_next_feed") == "1"; if (show_next_feed) { const nuf = this.getNextUnread(feed, is_cat); @@ -486,7 +486,7 @@ define(["dojo/_base/declare"], function (declare) { const str = __("Mark all articles in %s as read?").replace("%s", title); - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']"); diff --git a/js/Headlines.js b/js/Headlines.js index 68dda8d3e..1bcd35896 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -12,13 +12,13 @@ define(["dojo/_base/declare"], function (declare) { if (App.isCombinedMode()) { - if (!in_body && (event.ctrlKey || id == Article.getActive() || getInitParam("cdm_expanded"))) { + if (!in_body && (event.ctrlKey || id == Article.getActive() || App.getInitParam("cdm_expanded"))) { Article.openInNewWindow(id); } Article.setActive(id); - if (!getInitParam("cdm_expanded")) + if (!App.getInitParam("cdm_expanded")) Article.cdmScrollToId(id); return in_body; @@ -81,7 +81,7 @@ define(["dojo/_base/declare"], function (declare) { // set topmost child in the buffer as active, but not if we're at the beginning (to prevent auto marking // first article as read all the time) if ($("headlines-frame").scrollTop != 0 && - getInitParam("cdm_expanded") && getInitParam("cdm_auto_catchup") == 1) { + App.getInitParam("cdm_expanded") && App.getInitParam("cdm_auto_catchup") == 1) { const rows = $$("#headlines-frame > div[id*=RROW]"); @@ -113,7 +113,7 @@ define(["dojo/_base/declare"], function (declare) { } } - if (getInitParam("cdm_auto_catchup") == 1) { + if (App.getInitParam("cdm_auto_catchup") == 1) { let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]"); @@ -139,7 +139,7 @@ define(["dojo/_base/declare"], function (declare) { console.log("we seem to be at an end"); - if (getInitParam("on_catchup_show_next_feed") == "1") { + if (App.getInitParam("on_catchup_show_next_feed") == "1") { Feeds.openNextUnread(); } } @@ -150,7 +150,7 @@ define(["dojo/_base/declare"], function (declare) { } }, updateFloatingTitle: function(unread_only) { - if (!App.isCombinedMode()/* || !getInitParam("cdm_expanded")*/) return; + if (!App.isCombinedMode()/* || !App.getInitParam("cdm_expanded")*/) return; const hf = $("headlines-frame"); const elems = $$("#headlines-frame > div[id*=RROW]"); @@ -201,7 +201,7 @@ define(["dojo/_base/declare"], function (declare) { } }, unpackVisible: function() { - if (!App.isCombinedMode() || !getInitParam("cdm_expanded")) return; + if (!App.isCombinedMode() || !App.getInitParam("cdm_expanded")) return; const rows = $$("#headlines-frame div[id*=RROW][data-content]"); const threshold = $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight + 600; @@ -714,7 +714,7 @@ define(["dojo/_base/declare"], function (declare) { str = str.replace("%d", rows.length); str = str.replace("%s", fn); - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { return; } @@ -839,7 +839,7 @@ define(["dojo/_base/declare"], function (declare) { str = str.replace("%d", rows.length); str = str.replace("%s", fn); - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { return; } @@ -869,7 +869,7 @@ define(["dojo/_base/declare"], function (declare) { str = str.replace("%d", rows.length); str = str.replace("%s", fn); - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { return; } @@ -952,7 +952,7 @@ define(["dojo/_base/declare"], function (declare) { } else { const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length); - if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { + if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { for (var i = 0; i < ids_to_mark.length; i++) { var e = $("RROW-" + ids_to_mark[i]); @@ -1090,7 +1090,7 @@ define(["dojo/_base/declare"], function (declare) { })); - const labels = getInitParam("labels"); + const labels = App.getInitParam("labels"); if (labels && labels.length) { diff --git a/js/Utils.js b/js/Utils.js index 1050cf018..d1de08b2c 100644 --- a/js/Utils.js +++ b/js/Utils.js @@ -28,7 +28,7 @@ define(["dojo/_base/declare"], function (declare) { }, keyeventToAction: function(event) { - const hotkeys_map = getInitParam("hotkeys"); + const hotkeys_map = App.getInitParam("hotkeys"); const keycode = event.which; const keychar = String.fromCharCode(keycode).toLowerCase(); @@ -191,7 +191,7 @@ define(["dojo/_base/declare"], function (declare) { if (message == "UPDATE_COUNTERS") { console.log("need to refresh counters..."); - setInitParam("last_article_id", -1); + App.setInitParam("last_article_id", -1); Feeds.requestCounters(true); } @@ -228,9 +228,6 @@ define(["dojo/_base/declare"], function (declare) { return false; }, parseRuntimeInfo: function(data) { - - //console.log("parsing runtime info..."); - for (const k in data) { if (data.hasOwnProperty(k)) { const v = data[k]; @@ -258,13 +255,13 @@ define(["dojo/_base/declare"], function (declare) { } if (k == "max_feed_id" || k == "num_feeds") { - if (init_params[k] != v) { + if (App.getInitParam(k) != v) { console.log("feed count changed, need to reload feedlist."); Feeds.reload(); } } - init_params[k] = v; + App.setInitParam(k, v); } } @@ -315,13 +312,12 @@ define(["dojo/_base/declare"], function (declare) { } console.log("IP:", k, "=>", params[k]); + App.setInitParam(k, params[k]); } } - init_params = params; - // PluginHost might not be available on non-index pages - window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); + window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, App._initParams); } App.initSecondStage(); diff --git a/js/common.js b/js/common.js index 1da3e6d1b..de6d13a78 100755 --- a/js/common.js +++ b/js/common.js @@ -1,28 +1,8 @@ 'use strict' /* global dijit, __ */ -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) { - - if (getInitParam("csrf_token") != undefined) { - Object.extend(options, options || { }); - - if (Object.isString(options.parameters)) - options.parameters = options.parameters.toQueryParams(); - else if (Object.isHash(options.parameters)) - options.parameters = options.parameters.toObject(); - - options.parameters["csrf_token"] = getInitParam("csrf_token"); - } - - return callOriginal(options); - } -); /* xhr shorthand helpers */ @@ -239,15 +219,15 @@ const Notify = { switch (kind) { case this.KIND_INFO: notify.addClassName("notify_info") - icon = getInitParam("icon_information"); + icon = App.getInitParam("icon_information"); break; case this.KIND_ERROR: notify.addClassName("notify_error"); - icon = getInitParam("icon_alert"); + icon = App.getInitParam("icon_alert"); break; case this.KIND_PROGRESS: notify.addClassName("notify_progress"); - icon = getInitParam("icon_indicator_white") + icon = App.getInitParam("icon_indicator_white") break; } @@ -255,7 +235,7 @@ const Notify = { msgfmt += (" ") - .replace("%s", getInitParam("icon_cross")); + .replace("%s", App.getInitParam("icon_cross")); notify.innerHTML = msgfmt; notify.addClassName("visible"); @@ -289,14 +269,6 @@ function displayIfChecked(checkbox, elemId) { } } -function getInitParam(key) { - return init_params[key]; -} - -function setInitParam(key, value) { - init_params[key] = value; -} - function fatalError(code, msg, ext_info) { if (code == 6) { window.location.href = "index.php"; @@ -390,5 +362,5 @@ function popupOpenArticle(id) { "height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no"); w.opener = null; - w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token"); + w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + App.getInitParam("csrf_token"); } diff --git a/js/prefs.js b/js/prefs.js index a1866f478..75f285b38 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,64 +1,67 @@ 'use strict' /* global dijit, __ */ +let App; let Utils; let CommonDialogs; let Filters; let Users; let Prefs; -const App = { - init: function() { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; +require(["dojo/_base/kernel", + "dojo/_base/declare", + "dojo/ready", + "dojo/parser", + "fox/AppBase", + "dojo/_base/loader", + "dojo/_base/html", + "dijit/ColorPalette", + "dijit/Dialog", + "dijit/form/Button", + "dijit/form/CheckBox", + "dijit/form/DropDownButton", + "dijit/form/FilteringSelect", + "dijit/form/MultiSelect", + "dijit/form/Form", + "dijit/form/RadioButton", + "dijit/form/ComboButton", + "dijit/form/Select", + "dijit/form/SimpleTextarea", + "dijit/form/TextBox", + "dijit/form/ValidationTextBox", + "dijit/InlineEditBox", + "dijit/layout/AccordionContainer", + "dijit/layout/AccordionPane", + "dijit/layout/BorderContainer", + "dijit/layout/ContentPane", + "dijit/layout/TabContainer", + "dijit/Menu", + "dijit/ProgressBar", + "dijit/Toolbar", + "dijit/Tree", + "dijit/tree/dndSource", + "dojo/data/ItemFileWriteStore", + "lib/CheckBoxStoreModel", + "lib/CheckBoxTree", + "fox/Utils", + "fox/CommonDialogs", + "fox/CommonFilters", + "fox/PrefUsers", + "fox/PrefHelpers", + "fox/PrefFeedStore", + "fox/PrefFilterStore", + "fox/PrefFeedTree", + "fox/PrefFilterTree", + "fox/PrefLabelTree"], function (dojo, declare, ready, parser, AppBase) { - require(["dojo/_base/kernel", - "dojo/ready", - "dojo/parser", - "dojo/_base/loader", - "dojo/_base/html", - "dijit/ColorPalette", - "dijit/Dialog", - "dijit/form/Button", - "dijit/form/CheckBox", - "dijit/form/DropDownButton", - "dijit/form/FilteringSelect", - "dijit/form/MultiSelect", - "dijit/form/Form", - "dijit/form/RadioButton", - "dijit/form/ComboButton", - "dijit/form/Select", - "dijit/form/SimpleTextarea", - "dijit/form/TextBox", - "dijit/form/ValidationTextBox", - "dijit/InlineEditBox", - "dijit/layout/AccordionContainer", - "dijit/layout/AccordionPane", - "dijit/layout/BorderContainer", - "dijit/layout/ContentPane", - "dijit/layout/TabContainer", - "dijit/Menu", - "dijit/ProgressBar", - "dijit/Toolbar", - "dijit/Tree", - "dijit/tree/dndSource", - "dojo/data/ItemFileWriteStore", - "lib/CheckBoxStoreModel", - "lib/CheckBoxTree", - "fox/Utils", - "fox/CommonDialogs", - "fox/CommonFilters", - "fox/PrefUsers", - "fox/PrefHelpers", - "fox/PrefFeedStore", - "fox/PrefFilterStore", - "fox/PrefFeedTree", - "fox/PrefFilterTree", - "fox/PrefLabelTree"], function (dojo, ready, parser) { + ready(function () { + try { + const _App = declare("fox.App", AppBase, { + constructor: function() { + window.onerror = function (message, filename, lineno, colno, error) { + report_error(message, filename, lineno, colno, error); + }; - ready(function () { - try { Utils = fox.Utils(); CommonDialogs = fox.CommonDialogs(); Filters = fox.CommonFilters(); @@ -73,81 +76,87 @@ const App = { const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset}; xhrPost("backend.php", params, (transport) => { - Utils.backendSanityCallback(transport); + try { + Utils.backendSanityCallback(transport); + } catch (e) { + exception_error(e); + } + }); + }, + initSecondStage: function() { + document.onkeydown = () => { App.hotkeyHandler(event) }; + Utils.setLoadingProgress(50); + Notify.close(); + + let tab = Utils.urlParam('tab'); + + if (tab) { + tab = dijit.byId(tab + "Tab"); + if (tab) { + dijit.byId("pref-tabs").selectChild(tab); + + switch (Utils.urlParam('method')) { + case "editfeed": + window.setTimeout(function () { + CommonDialogs.editFeed(Utils.urlParam('methodparam')) + }, 100); + break; + default: + console.warn("initSecondStage, unknown method:", Utils.urlParam("method")); + } + } + } else { + let tab = localStorage.getItem("ttrss:prefs-tab"); + + if (tab) { + tab = dijit.byId(tab); + if (tab) { + dijit.byId("pref-tabs").selectChild(tab); + } + } + } + + dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { + localStorage.setItem("ttrss:prefs-tab", elem.id); }); - } catch (e) { - exception_error(e); + }, + hotkeyHandler: function (event) { + if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; + + const action_name = Utils.keyeventToAction(event); + + if (action_name) { + switch (action_name) { + case "feed_subscribe": + CommonDialogs.quickAddFeed(); + return false; + case "create_label": + CommonDialogs.addLabel(); + return false; + case "create_filter": + Filters.quickAddFilter(); + return false; + case "help_dialog": + Utils.helpDialog("main"); + return false; + default: + console.log("unhandled action: " + action_name + "; keycode: " + event.which); + } + } + }, + isPrefs: function() { + return true; } }); - }); - }, - initSecondStage: function() { - document.onkeydown = () => { App.hotkeyHandler(event) }; - Utils.setLoadingProgress(50); - Notify.close(); - let tab = Utils.urlParam('tab'); + App = new _App(); - if (tab) { - tab = dijit.byId(tab + "Tab"); - if (tab) { - dijit.byId("pref-tabs").selectChild(tab); - - switch (Utils.urlParam('method')) { - case "editfeed": - window.setTimeout(function () { - CommonDialogs.editFeed(Utils.urlParam('methodparam')) - }, 100); - break; - default: - console.warn("initSecondStage, unknown method:", Utils.urlParam("method")); - } - } - } else { - let tab = localStorage.getItem("ttrss:prefs-tab"); - - if (tab) { - tab = dijit.byId(tab); - if (tab) { - dijit.byId("pref-tabs").selectChild(tab); - } - } + } catch (e) { + exception_error(e); } - - dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { - localStorage.setItem("ttrss:prefs-tab", elem.id); - }); - - }, - hotkeyHandler: function (event) { - if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; - - const action_name = Utils.keyeventToAction(event); - - if (action_name) { - switch (action_name) { - case "feed_subscribe": - CommonDialogs.quickAddFeed(); - return false; - case "create_label": - CommonDialogs.addLabel(); - return false; - case "create_filter": - Filters.quickAddFilter(); - return false; - case "help_dialog": - Utils.helpDialog("main"); - return false; - default: - console.log("unhandled action: " + action_name + "; keycode: " + event.which); - } - } - }, - isPrefs: function() { - return true; - } -}; + }); +}); function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; diff --git a/js/tt-rss.js b/js/tt-rss.js index 481386114..ec52755a1 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -1,6 +1,7 @@ 'use strict' /* global dijit,__ */ +let App; let Utils; let CommonDialogs; let Filters; @@ -9,63 +10,63 @@ let Headlines; let Article; let ArticleCache; -const App = { - global_unread: -1, - _widescreen_mode: false, - hotkey_actions: {}, - init: function() { +require(["dojo/_base/kernel", + "dojo/_base/declare", + "dojo/ready", + "dojo/parser", + "fox/AppBase", + "dojo/_base/loader", + "dojo/_base/html", + "dojo/query", + "dijit/ProgressBar", + "dijit/ColorPalette", + "dijit/Dialog", + "dijit/form/Button", + "dijit/form/ComboButton", + "dijit/form/CheckBox", + "dijit/form/DropDownButton", + "dijit/form/FilteringSelect", + "dijit/form/Form", + "dijit/form/RadioButton", + "dijit/form/Select", + "dijit/form/MultiSelect", + "dijit/form/SimpleTextarea", + "dijit/form/TextBox", + "dijit/form/ComboBox", + "dijit/form/ValidationTextBox", + "dijit/InlineEditBox", + "dijit/layout/AccordionContainer", + "dijit/layout/BorderContainer", + "dijit/layout/ContentPane", + "dijit/layout/TabContainer", + "dijit/PopupMenuItem", + "dijit/Menu", + "dijit/Toolbar", + "dijit/Tree", + "dijit/tree/dndSource", + "dijit/tree/ForestStoreModel", + "dojo/data/ItemFileWriteStore", + "fox/Utils", + "fox/CommonDialogs", + "fox/CommonFilters", + "fox/Feeds", + "fox/Headlines", + "fox/Article", + "fox/ArticleCache", + "fox/FeedStoreModel", + "fox/FeedTree"], function (dojo, declare, ready, parser, AppBase) { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; + ready(function () { + try { + const _App = declare("fox.App", AppBase, { + global_unread: -1, + _widescreen_mode: false, + hotkey_actions: {}, + constructor: function () { + window.onerror = function (message, filename, lineno, colno, error) { + report_error(message, filename, lineno, colno, error); + }; - require(["dojo/_base/kernel", - "dojo/ready", - "dojo/parser", - "dojo/_base/loader", - "dojo/_base/html", - "dojo/query", - "dijit/ProgressBar", - "dijit/ColorPalette", - "dijit/Dialog", - "dijit/form/Button", - "dijit/form/ComboButton", - "dijit/form/CheckBox", - "dijit/form/DropDownButton", - "dijit/form/FilteringSelect", - "dijit/form/Form", - "dijit/form/RadioButton", - "dijit/form/Select", - "dijit/form/MultiSelect", - "dijit/form/SimpleTextarea", - "dijit/form/TextBox", - "dijit/form/ComboBox", - "dijit/form/ValidationTextBox", - "dijit/InlineEditBox", - "dijit/layout/AccordionContainer", - "dijit/layout/BorderContainer", - "dijit/layout/ContentPane", - "dijit/layout/TabContainer", - "dijit/PopupMenuItem", - "dijit/Menu", - "dijit/Toolbar", - "dijit/Tree", - "dijit/tree/dndSource", - "dijit/tree/ForestStoreModel", - "dojo/data/ItemFileWriteStore", - "fox/Utils", - "fox/CommonDialogs", - "fox/CommonFilters", - "fox/Feeds", - "fox/Headlines", - "fox/Article", - "fox/ArticleCache", - "fox/FeedStoreModel", - "fox/FeedTree"], function (dojo, ready, parser) { - - ready(function () { - - try { Utils = fox.Utils(); CommonDialogs = fox.CommonDialogs(); Filters = fox.CommonFilters(); @@ -76,11 +77,11 @@ const App = { parser.parse(); - if (!App.genericSanityCheck()) - return false; + if (!this.genericSanityCheck()) + return; Utils.setLoadingProgress(30); - App.initHotkeyActions(); + this.initHotkeyActions(); const a = document.createElement('audio'); const hasAudio = !!a.canPlayType; @@ -99,483 +100,483 @@ const App = { try { Utils.backendSanityCallback(transport); } catch (e) { - console.error(e); + exception_error(e); } }); + }, + initSecondStage: function () { + this.enableCsrfSupport(); - } catch (e) { - exception_error(e); - } + Feeds.reload(); + Article.close(); - }); - - - }); - }, - initSecondStage: function () { - Feeds.reload(); - Article.close(); - - if (parseInt(Cookie.get("ttrss_fh_width")) > 0) { - dijit.byId("feeds-holder").domNode.setStyle( - {width: Cookie.get("ttrss_fh_width") + "px"}); - } - - dijit.byId("main").resize(); - - dojo.connect(dijit.byId('feeds-holder'), 'resize', - function (args) { - if (args && args.w >= 0) { - Cookie.set("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); - } - }); - - dojo.connect(dijit.byId('content-insert'), 'resize', - function (args) { - if (args && args.w >= 0 && args.h >= 0) { - Cookie.set("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); - Cookie.set("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); - } - }); - - Cookie.delete("ttrss_test"); - - const toolbar = document.forms["main_toolbar_form"]; - - dijit.getEnclosingWidget(toolbar.view_mode).attr('value', - getInitParam("default_view_mode")); - - dijit.getEnclosingWidget(toolbar.order_by).attr('value', - getInitParam("default_view_order_by")); - - const hash_feed_id = hash_get('f'); - const hash_feed_is_cat = hash_get('c') == "1"; - - if (hash_feed_id != undefined) { - Feeds.setActive(hash_feed_id, hash_feed_is_cat); - } - - Utils.setLoadingProgress(50); - - ArticleCache.clear(); - - this._widescreen_mode = getInitParam("widescreen"); - this.switchPanelMode(this._widescreen_mode); - - Headlines.initScrollHandler(); - - if (getInitParam("simple_update")) { - console.log("scheduling simple feed updater..."); - window.setInterval(() => { Feeds.updateRandom() }, 30 * 1000); - } - - console.log("second stage ok"); - }, - genericSanityCheck: function() { - Cookie.set("ttrss_test", "TEST"); - - if (Cookie.get("ttrss_test") != "TEST") { - return fatalError(2); - } - - return true; - }, - updateTitle: function() { - let tmp = "Tiny Tiny RSS"; - - if (this.global_unread > 0) { - tmp = "(" + this.global_unread + ") " + tmp; - } - - document.title = tmp; - }, - onViewModeChanged: function() { - ArticleCache.clear(); - return Feeds.reloadCurrent(''); - }, - isCombinedMode: function() { - return getInitParam("combined_display_mode"); - }, - hotkeyHandler(event) { - if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; - - const action_name = Utils.keyeventToAction(event); - - if (action_name) { - const action_func = this.hotkey_actions[action_name]; - - if (action_func != null) { - action_func(); - event.stopPropagation(); - return false; - } - } - }, - switchPanelMode: function(wide) { - if (App.isCombinedMode()) return; - - const article_id = Article.getActive(); - - if (wide) { - dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); - dijit.byId("content-insert").attr("region", "trailing"); - - dijit.byId("content-insert").domNode.setStyle({width: '50%', - height: 'auto', - borderTopWidth: '0px' }); - - if (parseInt(Cookie.get("ttrss_ci_width")) > 0) { - dijit.byId("content-insert").domNode.setStyle( - {width: Cookie.get("ttrss_ci_width") + "px" }); - } - - $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); - $("headlines-frame").addClassName("wide"); - - } else { - - dijit.byId("content-insert").attr("region", "bottom"); - - dijit.byId("content-insert").domNode.setStyle({width: 'auto', - height: '50%', - borderTopWidth: '0px'}); - - if (parseInt(Cookie.get("ttrss_ci_height")) > 0) { - dijit.byId("content-insert").domNode.setStyle( - {height: Cookie.get("ttrss_ci_height") + "px" }); - } - - $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); - $("headlines-frame").removeClassName("wide"); - - } - - Article.close(); - - if (article_id) Article.view(article_id); - - xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); - }, - initHotkeyActions: function() { - this.hotkey_actions["next_feed"] = function () { - const rv = dijit.byId("feedTree").getNextFeed( - Feeds.getActive(), Feeds.activeIsCat()); - - if (rv) Feeds.open({feed: rv[0], is_cat: rv[1], delayed: true}) - }; - this.hotkey_actions["prev_feed"] = function () { - const rv = dijit.byId("feedTree").getPreviousFeed( - Feeds.getActive(), Feeds.activeIsCat()); - - if (rv) Feeds.open({feed: rv[0], is_cat: rv[1], delayed: true}) - }; - this.hotkey_actions["next_article"] = function () { - Headlines.move('next'); - }; - this.hotkey_actions["prev_article"] = function () { - Headlines.move('prev'); - }; - this.hotkey_actions["next_article_noscroll"] = function () { - Headlines.move('next', true); - }; - this.hotkey_actions["prev_article_noscroll"] = function () { - Headlines.move('prev', true); - }; - this.hotkey_actions["next_article_noexpand"] = function () { - Headlines.move('next', true, true); - }; - this.hotkey_actions["prev_article_noexpand"] = function () { - Headlines.move('prev', true, true); - }; - this.hotkey_actions["search_dialog"] = function () { - Feeds.search(); - }; - this.hotkey_actions["toggle_mark"] = function () { - Headlines.selectionToggleMarked(); - }; - this.hotkey_actions["toggle_publ"] = function () { - Headlines.selectionTogglePublished(); - }; - this.hotkey_actions["toggle_unread"] = function () { - Headlines.selectionToggleUnread({no_error: 1}); - }; - this.hotkey_actions["edit_tags"] = function () { - const id = Article.getActive(); - if (id) { - Article.editTags(id); - } - }; - this.hotkey_actions["open_in_new_window"] = function () { - if (Article.getActive()) { - Article.openInNewWindow(Article.getActive()); - } - }; - this.hotkey_actions["catchup_below"] = function () { - Headlines.catchupRelativeTo(1); - }; - this.hotkey_actions["catchup_above"] = function () { - Headlines.catchupRelativeTo(0); - }; - this.hotkey_actions["article_scroll_down"] = function () { - Article.scroll(40); - }; - this.hotkey_actions["article_scroll_up"] = function () { - Article.scroll(-40); - }; - this.hotkey_actions["close_article"] = function () { - if (App.isCombinedMode()) { - Article.cdmUnsetActive(); - } else { - Article.close(); - } - }; - this.hotkey_actions["email_article"] = function () { - if (typeof emailArticle != "undefined") { - emailArticle(); - } else if (typeof mailtoArticle != "undefined") { - mailtoArticle(); - } else { - alert(__("Please enable mail plugin first.")); - } - }; - this.hotkey_actions["select_all"] = function () { - Headlines.select('all'); - }; - this.hotkey_actions["select_unread"] = function () { - Headlines.select('unread'); - }; - this.hotkey_actions["select_marked"] = function () { - Headlines.select('marked'); - }; - this.hotkey_actions["select_published"] = function () { - Headlines.select('published'); - }; - this.hotkey_actions["select_invert"] = function () { - Headlines.select('invert'); - }; - this.hotkey_actions["select_none"] = function () { - Headlines.select('none'); - }; - this.hotkey_actions["feed_refresh"] = function () { - if (Feeds.getActive() != undefined) { - Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()}); - } - }; - this.hotkey_actions["feed_unhide_read"] = function () { - Feeds.toggleUnread(); - }; - this.hotkey_actions["feed_subscribe"] = function () { - CommonDialogs.quickAddFeed(); - }; - this.hotkey_actions["feed_debug_update"] = function () { - if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) { - window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActive() + - "&csrf_token=" + getInitParam("csrf_token")); - } else { - alert("You can't debug this kind of feed."); - } - }; - - this.hotkey_actions["feed_debug_viewfeed"] = function () { - Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), viewfeed_debug: true}); - }; - - this.hotkey_actions["feed_edit"] = function () { - if (Feeds.activeIsCat()) - alert(__("You can't edit this kind of feed.")); - else - CommonDialogs.editFeed(Feeds.getActive()); - }; - this.hotkey_actions["feed_catchup"] = function () { - if (Feeds.getActive() != undefined) { - Feeds.catchupCurrent(); - } - }; - this.hotkey_actions["feed_reverse"] = function () { - Headlines.reverse(); - }; - this.hotkey_actions["feed_toggle_vgroup"] = function () { - xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { - Feeds.reloadCurrent(); - }) - }; - this.hotkey_actions["catchup_all"] = function () { - Feeds.catchupAll(); - }; - this.hotkey_actions["cat_toggle_collapse"] = function () { - if (Feeds.activeIsCat()) { - dijit.byId("feedTree").collapseCat(Feeds.getActive()); - } - }; - this.hotkey_actions["goto_all"] = function () { - Feeds.open({feed: -4}); - }; - this.hotkey_actions["goto_fresh"] = function () { - Feeds.open({feed: -3}); - }; - this.hotkey_actions["goto_marked"] = function () { - Feeds.open({feed: -1}); - }; - this.hotkey_actions["goto_published"] = function () { - Feeds.open({feed: -2}); - }; - this.hotkey_actions["goto_tagcloud"] = function () { - Utils.displayDlg(__("Tag cloud"), "printTagCloud"); - }; - this.hotkey_actions["goto_prefs"] = function () { - document.location.href = "prefs.php"; - }; - this.hotkey_actions["select_article_cursor"] = function () { - const id = Article.getUnderPointer(); - if (id) { - const row = $("RROW-" + id); - - if (row) { - const cb = dijit.getEnclosingWidget( - row.select(".rchk")[0]); - - if (cb) { - if (!row.hasClassName("active")) - cb.attr("checked", !cb.attr("checked")); - - Headlines.onRowChecked(cb); - return false; + if (parseInt(Cookie.get("ttrss_fh_width")) > 0) { + dijit.byId("feeds-holder").domNode.setStyle( + {width: Cookie.get("ttrss_fh_width") + "px"}); } + + dijit.byId("main").resize(); + + dojo.connect(dijit.byId('feeds-holder'), 'resize', + function (args) { + if (args && args.w >= 0) { + Cookie.set("ttrss_fh_width", args.w, App.getInitParam("cookie_lifetime")); + } + }); + + dojo.connect(dijit.byId('content-insert'), 'resize', + function (args) { + if (args && args.w >= 0 && args.h >= 0) { + Cookie.set("ttrss_ci_width", args.w, App.getInitParam("cookie_lifetime")); + Cookie.set("ttrss_ci_height", args.h, App.getInitParam("cookie_lifetime")); + } + }); + + Cookie.delete("ttrss_test"); + + const toolbar = document.forms["main_toolbar_form"]; + + dijit.getEnclosingWidget(toolbar.view_mode).attr('value', + App.getInitParam("default_view_mode")); + + dijit.getEnclosingWidget(toolbar.order_by).attr('value', + App.getInitParam("default_view_order_by")); + + const hash_feed_id = hash_get('f'); + const hash_feed_is_cat = hash_get('c') == "1"; + + if (hash_feed_id != undefined) { + Feeds.setActive(hash_feed_id, hash_feed_is_cat); + } + + Utils.setLoadingProgress(50); + + ArticleCache.clear(); + + this._widescreen_mode = App.getInitParam("widescreen"); + this.switchPanelMode(this._widescreen_mode); + + Headlines.initScrollHandler(); + + if (App.getInitParam("simple_update")) { + console.log("scheduling simple feed updater..."); + window.setInterval(() => { Feeds.updateRandom() }, 30 * 1000); + } + + console.log("second stage ok"); + }, + genericSanityCheck: function() { + Cookie.set("ttrss_test", "TEST"); + + if (Cookie.get("ttrss_test") != "TEST") { + return fatalError(2); + } + + return true; + }, + updateTitle: function() { + let tmp = "Tiny Tiny RSS"; + + if (this.global_unread > 0) { + tmp = "(" + this.global_unread + ") " + tmp; + } + + document.title = tmp; + }, + onViewModeChanged: function() { + ArticleCache.clear(); + return Feeds.reloadCurrent(''); + }, + isCombinedMode: function() { + return App.getInitParam("combined_display_mode"); + }, + hotkeyHandler(event) { + if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; + + const action_name = Utils.keyeventToAction(event); + + if (action_name) { + const action_func = this.hotkey_actions[action_name]; + + if (action_func != null) { + action_func(); + event.stopPropagation(); + return false; + } + } + }, + switchPanelMode: function(wide) { + if (App.isCombinedMode()) return; + + const article_id = Article.getActive(); + + if (wide) { + dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); + dijit.byId("content-insert").attr("region", "trailing"); + + dijit.byId("content-insert").domNode.setStyle({width: '50%', + height: 'auto', + borderTopWidth: '0px' }); + + if (parseInt(Cookie.get("ttrss_ci_width")) > 0) { + dijit.byId("content-insert").domNode.setStyle( + {width: Cookie.get("ttrss_ci_width") + "px" }); + } + + $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); + $("headlines-frame").addClassName("wide"); + + } else { + + dijit.byId("content-insert").attr("region", "bottom"); + + dijit.byId("content-insert").domNode.setStyle({width: 'auto', + height: '50%', + borderTopWidth: '0px'}); + + if (parseInt(Cookie.get("ttrss_ci_height")) > 0) { + dijit.byId("content-insert").domNode.setStyle( + {height: Cookie.get("ttrss_ci_height") + "px" }); + } + + $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); + $("headlines-frame").removeClassName("wide"); + + } + + Article.close(); + + if (article_id) Article.view(article_id); + + xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); + }, + initHotkeyActions: function() { + this.hotkey_actions["next_feed"] = function () { + const rv = dijit.byId("feedTree").getNextFeed( + Feeds.getActive(), Feeds.activeIsCat()); + + if (rv) Feeds.open({feed: rv[0], is_cat: rv[1], delayed: true}) + }; + this.hotkey_actions["prev_feed"] = function () { + const rv = dijit.byId("feedTree").getPreviousFeed( + Feeds.getActive(), Feeds.activeIsCat()); + + if (rv) Feeds.open({feed: rv[0], is_cat: rv[1], delayed: true}) + }; + this.hotkey_actions["next_article"] = function () { + Headlines.move('next'); + }; + this.hotkey_actions["prev_article"] = function () { + Headlines.move('prev'); + }; + this.hotkey_actions["next_article_noscroll"] = function () { + Headlines.move('next', true); + }; + this.hotkey_actions["prev_article_noscroll"] = function () { + Headlines.move('prev', true); + }; + this.hotkey_actions["next_article_noexpand"] = function () { + Headlines.move('next', true, true); + }; + this.hotkey_actions["prev_article_noexpand"] = function () { + Headlines.move('prev', true, true); + }; + this.hotkey_actions["search_dialog"] = function () { + Feeds.search(); + }; + this.hotkey_actions["toggle_mark"] = function () { + Headlines.selectionToggleMarked(); + }; + this.hotkey_actions["toggle_publ"] = function () { + Headlines.selectionTogglePublished(); + }; + this.hotkey_actions["toggle_unread"] = function () { + Headlines.selectionToggleUnread({no_error: 1}); + }; + this.hotkey_actions["edit_tags"] = function () { + const id = Article.getActive(); + if (id) { + Article.editTags(id); + } + }; + this.hotkey_actions["open_in_new_window"] = function () { + if (Article.getActive()) { + Article.openInNewWindow(Article.getActive()); + } + }; + this.hotkey_actions["catchup_below"] = function () { + Headlines.catchupRelativeTo(1); + }; + this.hotkey_actions["catchup_above"] = function () { + Headlines.catchupRelativeTo(0); + }; + this.hotkey_actions["article_scroll_down"] = function () { + Article.scroll(40); + }; + this.hotkey_actions["article_scroll_up"] = function () { + Article.scroll(-40); + }; + this.hotkey_actions["close_article"] = function () { + if (App.isCombinedMode()) { + Article.cdmUnsetActive(); + } else { + Article.close(); + } + }; + this.hotkey_actions["email_article"] = function () { + if (typeof emailArticle != "undefined") { + emailArticle(); + } else if (typeof mailtoArticle != "undefined") { + mailtoArticle(); + } else { + alert(__("Please enable mail plugin first.")); + } + }; + this.hotkey_actions["select_all"] = function () { + Headlines.select('all'); + }; + this.hotkey_actions["select_unread"] = function () { + Headlines.select('unread'); + }; + this.hotkey_actions["select_marked"] = function () { + Headlines.select('marked'); + }; + this.hotkey_actions["select_published"] = function () { + Headlines.select('published'); + }; + this.hotkey_actions["select_invert"] = function () { + Headlines.select('invert'); + }; + this.hotkey_actions["select_none"] = function () { + Headlines.select('none'); + }; + this.hotkey_actions["feed_refresh"] = function () { + if (Feeds.getActive() != undefined) { + Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()}); + } + }; + this.hotkey_actions["feed_unhide_read"] = function () { + Feeds.toggleUnread(); + }; + this.hotkey_actions["feed_subscribe"] = function () { + CommonDialogs.quickAddFeed(); + }; + this.hotkey_actions["feed_debug_update"] = function () { + if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) { + window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActive() + + "&csrf_token=" + App.getInitParam("csrf_token")); + } else { + alert("You can't debug this kind of feed."); + } + }; + + this.hotkey_actions["feed_debug_viewfeed"] = function () { + Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), viewfeed_debug: true}); + }; + + this.hotkey_actions["feed_edit"] = function () { + if (Feeds.activeIsCat()) + alert(__("You can't edit this kind of feed.")); + else + CommonDialogs.editFeed(Feeds.getActive()); + }; + this.hotkey_actions["feed_catchup"] = function () { + if (Feeds.getActive() != undefined) { + Feeds.catchupCurrent(); + } + }; + this.hotkey_actions["feed_reverse"] = function () { + Headlines.reverse(); + }; + this.hotkey_actions["feed_toggle_vgroup"] = function () { + xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { + Feeds.reloadCurrent(); + }) + }; + this.hotkey_actions["catchup_all"] = function () { + Feeds.catchupAll(); + }; + this.hotkey_actions["cat_toggle_collapse"] = function () { + if (Feeds.activeIsCat()) { + dijit.byId("feedTree").collapseCat(Feeds.getActive()); + } + }; + this.hotkey_actions["goto_all"] = function () { + Feeds.open({feed: -4}); + }; + this.hotkey_actions["goto_fresh"] = function () { + Feeds.open({feed: -3}); + }; + this.hotkey_actions["goto_marked"] = function () { + Feeds.open({feed: -1}); + }; + this.hotkey_actions["goto_published"] = function () { + Feeds.open({feed: -2}); + }; + this.hotkey_actions["goto_tagcloud"] = function () { + Utils.displayDlg(__("Tag cloud"), "printTagCloud"); + }; + this.hotkey_actions["goto_prefs"] = function () { + document.location.href = "prefs.php"; + }; + this.hotkey_actions["select_article_cursor"] = function () { + const id = Article.getUnderPointer(); + if (id) { + const row = $("RROW-" + id); + + if (row) { + const cb = dijit.getEnclosingWidget( + row.select(".rchk")[0]); + + if (cb) { + if (!row.hasClassName("active")) + cb.attr("checked", !cb.attr("checked")); + + Headlines.onRowChecked(cb); + return false; + } + } + } + }; + this.hotkey_actions["create_label"] = function () { + CommonDialogs.addLabel(); + }; + this.hotkey_actions["create_filter"] = function () { + Filters.quickAddFilter(); + }; + this.hotkey_actions["collapse_sidebar"] = function () { + Feeds.reloadCurrent(); + }; + this.hotkey_actions["toggle_embed_original"] = function () { + if (typeof embedOriginalArticle != "undefined") { + if (Article.getActive()) + embedOriginalArticle(Article.getActive()); + } else { + alert(__("Please enable embed_original plugin first.")); + } + }; + this.hotkey_actions["toggle_widescreen"] = function () { + if (!App.isCombinedMode()) { + App._widescreen_mode = !App._widescreen_mode; + + // reset stored sizes because geometry changed + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); + + App.switchPanelMode(App._widescreen_mode); + } else { + alert(__("Widescreen is not available in combined mode.")); + } + }; + this.hotkey_actions["help_dialog"] = function () { + Utils.helpDialog("main"); + }; + this.hotkey_actions["toggle_combined_mode"] = function () { + Notify.progress("Loading, please wait..."); + + const value = App.isCombinedMode() ? "false" : "true"; + + xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { + App.setInitParam("combined_display_mode", + !App.getInitParam("combined_display_mode")); + + Article.close(); + Feeds.reloadCurrent(); + }) + }; + this.hotkey_actions["toggle_cdm_expanded"] = function () { + Notify.progress("Loading, please wait..."); + + const value = App.getInitParam("cdm_expanded") ? "false" : "true"; + + xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { + App.setInitParam("cdm_expanded", !App.getInitParam("cdm_expanded")); + Feeds.reloadCurrent(); + }); + }; + }, + onActionSelected: function(opid) { + switch (opid) { + case "qmcPrefs": + document.location.href = "prefs.php"; + break; + case "qmcLogout": + document.location.href = "backend.php?op=logout"; + break; + case "qmcTagCloud": + Utils.displayDlg(__("Tag cloud"), "printTagCloud"); + break; + case "qmcSearch": + Feeds.search(); + break; + case "qmcAddFeed": + CommonDialogs.quickAddFeed(); + break; + case "qmcDigest": + window.location.href = "backend.php?op=digest"; + break; + case "qmcEditFeed": + if (Feeds.activeIsCat()) + alert(__("You can't edit this kind of feed.")); + else + CommonDialogs.editFeed(Feeds.getActive()); + break; + case "qmcRemoveFeed": + const actid = Feeds.getActive(); + + if (!actid) { + alert(__("Please select some feed first.")); + return; + } + + if (Feeds.activeIsCat()) { + alert(__("You can't unsubscribe from the category.")); + return; + } + + const fn = Feeds.getName(actid); + + if (confirm(__("Unsubscribe from %s?").replace("%s", fn))) { + CommonDialogs.unsubscribeFeed(actid); + } + break; + case "qmcCatchupAll": + Feeds.catchupAll(); + break; + case "qmcShowOnlyUnread": + Feeds.toggleUnread(); + break; + case "qmcToggleWidescreen": + if (!App.isCombinedMode()) { + App._widescreen_mode = !App._widescreen_mode; + + // reset stored sizes because geometry changed + Cookie.set("ttrss_ci_width", 0); + Cookie.set("ttrss_ci_height", 0); + + App.switchPanelMode(App._widescreen_mode); + } else { + alert(__("Widescreen is not available in combined mode.")); + } + break; + case "qmcHKhelp": + Utils.helpDialog("main"); + break; + default: + console.log("quickMenuGo: unknown action: " + opid); + } + }, + isPrefs: function() { + return false; } - } - }; - this.hotkey_actions["create_label"] = function () { - CommonDialogs.addLabel(); - }; - this.hotkey_actions["create_filter"] = function () { - Filters.quickAddFilter(); - }; - this.hotkey_actions["collapse_sidebar"] = function () { - Feeds.reloadCurrent(); - }; - this.hotkey_actions["toggle_embed_original"] = function () { - if (typeof embedOriginalArticle != "undefined") { - if (Article.getActive()) - embedOriginalArticle(Article.getActive()); - } else { - alert(__("Please enable embed_original plugin first.")); - } - }; - this.hotkey_actions["toggle_widescreen"] = function () { - if (!App.isCombinedMode()) { - App._widescreen_mode = !App._widescreen_mode; - - // reset stored sizes because geometry changed - Cookie.set("ttrss_ci_width", 0); - Cookie.set("ttrss_ci_height", 0); - - App.switchPanelMode(App._widescreen_mode); - } else { - alert(__("Widescreen is not available in combined mode.")); - } - }; - this.hotkey_actions["help_dialog"] = function () { - Utils.helpDialog("main"); - }; - this.hotkey_actions["toggle_combined_mode"] = function () { - Notify.progress("Loading, please wait..."); - - const value = App.isCombinedMode() ? "false" : "true"; - - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { - setInitParam("combined_display_mode", - !getInitParam("combined_display_mode")); - - Article.close(); - Feeds.reloadCurrent(); - }) - }; - this.hotkey_actions["toggle_cdm_expanded"] = function () { - Notify.progress("Loading, please wait..."); - - const value = getInitParam("cdm_expanded") ? "false" : "true"; - - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { - setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); - Feeds.reloadCurrent(); }); - }; - }, - onActionSelected: function(opid) { - switch (opid) { - case "qmcPrefs": - document.location.href = "prefs.php"; - break; - case "qmcLogout": - document.location.href = "backend.php?op=logout"; - break; - case "qmcTagCloud": - Utils.displayDlg(__("Tag cloud"), "printTagCloud"); - break; - case "qmcSearch": - Feeds.search(); - break; - case "qmcAddFeed": - CommonDialogs.quickAddFeed(); - break; - case "qmcDigest": - window.location.href = "backend.php?op=digest"; - break; - case "qmcEditFeed": - if (Feeds.activeIsCat()) - alert(__("You can't edit this kind of feed.")); - else - CommonDialogs.editFeed(Feeds.getActive()); - break; - case "qmcRemoveFeed": - const actid = Feeds.getActive(); - if (!actid) { - alert(__("Please select some feed first.")); - return; - } - - if (Feeds.activeIsCat()) { - alert(__("You can't unsubscribe from the category.")); - return; - } - - const fn = Feeds.getName(actid); - - if (confirm(__("Unsubscribe from %s?").replace("%s", fn))) { - CommonDialogs.unsubscribeFeed(actid); - } - break; - case "qmcCatchupAll": - Feeds.catchupAll(); - break; - case "qmcShowOnlyUnread": - Feeds.toggleUnread(); - break; - case "qmcToggleWidescreen": - if (!App.isCombinedMode()) { - App._widescreen_mode = !App._widescreen_mode; - - // reset stored sizes because geometry changed - Cookie.set("ttrss_ci_width", 0); - Cookie.set("ttrss_ci_height", 0); - - App.switchPanelMode(App._widescreen_mode); - } else { - alert(__("Widescreen is not available in combined mode.")); - } - break; - case "qmcHKhelp": - Utils.helpDialog("main"); - break; - default: - console.log("quickMenuGo: unknown action: " + opid); + App = new _App(); + } catch (e) { + exception_error(e); } - }, - isPrefs: function() { - return false; - } -}; + }); +}); function hash_get(key) { const kv = window.location.hash.substring(1).toQueryParams(); diff --git a/prefs.php b/prefs.php index 93773103f..a3d7c8b1b 100644 --- a/prefs.php +++ b/prefs.php @@ -100,13 +100,6 @@ - - -