From 84affc7b1d71769038dfd25d74e40d6bf744e5fb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 09:33:44 +0300 Subject: rework dojo singleton modules to better work with phpstorm completion (ugh) - declare() is not needed there anyway remove event.observe from login form (not needed) load pluginhost via amd --- js/Article.js | 32 ++++++++++++----------- js/ArticleCache.js | 14 +++++----- js/CommonDialogs.js | 6 +++-- js/CommonFilters.js | 6 +++-- js/Feeds.js | 6 +++-- js/Headlines.js | 74 +++++++++++++++++++++++++++-------------------------- js/PluginHost.js | 2 +- js/PrefHelpers.js | 6 +++-- js/PrefUsers.js | 7 ++--- js/prefs.js | 5 ---- js/tt-rss.js | 11 +++----- 11 files changed, 87 insertions(+), 82 deletions(-) (limited to 'js') diff --git a/js/Article.js b/js/Article.js index 1a60f8740..d3ae8eed7 100644 --- a/js/Article.js +++ b/js/Article.js @@ -1,9 +1,9 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - return declare("fox.Article", null, { + Article = { _active_article_id: 0, - selectionSetScore: function() { + selectionSetScore: function () { const ids = Headlines.getSelected(); if (ids.length > 0) { @@ -40,7 +40,7 @@ define(["dojo/_base/declare"], function (declare) { alert(__("No articles selected.")); } }, - setScore: function(id, pic) { + setScore: function (id, pic) { const score = pic.getAttribute("score"); const new_score = prompt(__("Please enter new score for this article:"), score); @@ -57,7 +57,7 @@ define(["dojo/_base/declare"], function (declare) { }); } }, - cdmUnsetActive: function(event) { + cdmUnsetActive: function (event) { const row = $("RROW-" + Article.getActive()); if (row) { @@ -119,7 +119,7 @@ define(["dojo/_base/declare"], function (declare) { } catch (e) { } }, - view: function(id, noexpand) { + view: function (id, noexpand) { this.setActive(id); if (!noexpand) { @@ -175,7 +175,7 @@ define(["dojo/_base/declare"], function (declare) { return false; }, - editTags: function(id) { + editTags: function (id) { const query = "backend.php?op=article&method=editArticleTags¶m=" + encodeURIComponent(id); if (dijit.byId("editTagsDlg")) @@ -224,7 +224,7 @@ define(["dojo/_base/declare"], function (declare) { dialog.show(); }, - cdmScrollToId: function(id, force) { + cdmScrollToId: function (id, force) { const ctr = $("headlines-frame"); const e = $("RROW-" + id); @@ -239,7 +239,7 @@ define(["dojo/_base/declare"], function (declare) { Element.hide("floatingTitle"); } }, - setActive: function(id) { + setActive: function (id) { console.log("setActive", id); $$("div[id*=RROW][class*=active]").each((e) => { @@ -287,10 +287,10 @@ define(["dojo/_base/declare"], function (declare) { Headlines.updateSelectedPrompt(); }, - getActive: function() { + getActive: function () { return this._active_article_id; }, - scroll: function(offset) { + scroll: function (offset) { if (!App.isCombinedMode()) { const ci = $("content-insert"); if (ci) { @@ -304,7 +304,7 @@ define(["dojo/_base/declare"], function (declare) { } }, - getRelativeIds: function(id, limit) { + getRelativeIds: function (id, limit) { const tmp = []; @@ -324,14 +324,16 @@ define(["dojo/_base/declare"], function (declare) { return tmp; }, - mouseIn: function(id) { + mouseIn: function (id) { this.post_under_pointer = id; }, - mouseOut: function(id) { + mouseOut: function (id) { this.post_under_pointer = false; }, - getUnderPointer: function() { + getUnderPointer: function () { return this.post_under_pointer; } - }); + } + + return Article; }); \ No newline at end of file diff --git a/js/ArticleCache.js b/js/ArticleCache.js index a4e8e091f..ce34d00d9 100644 --- a/js/ArticleCache.js +++ b/js/ArticleCache.js @@ -1,9 +1,9 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - return declare("fox.ArticleCache", null, { + ArticleCache = { has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null, - set: function(id, obj) { + set: function (id, obj) { if (this.has_storage) try { sessionStorage["article:" + id] = obj; @@ -11,17 +11,19 @@ define(["dojo/_base/declare"], function (declare) { sessionStorage.clear(); } }, - get: function(id) { + get: function (id) { if (this.has_storage) return sessionStorage["article:" + id]; }, - clear: function() { + clear: function () { if (this.has_storage) sessionStorage.clear(); }, - del: function(id) { + del: function (id) { if (this.has_storage) sessionStorage.removeItem("article:" + id); }, - }); + } + + return ArticleCache; }); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index cf21370d6..b9cee8873 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -2,7 +2,7 @@ /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { // noinspection JSUnusedGlobalSymbols - return declare("fox.CommonDialogs", null, { + CommonDialogs = { closeInfoBox: function() { const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); @@ -443,5 +443,7 @@ define(["dojo/_base/declare"], function (declare) { } return false; } - }); + }; + + return CommonDialogs; }); \ No newline at end of file diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 2c9c7b5a4..d2a3e6317 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -1,7 +1,7 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - return declare("fox.CommonFilters", null, { + Filters = { filterDlgCheckAction: function(sender) { const action = sender.value; @@ -387,5 +387,7 @@ define(["dojo/_base/declare"], function (declare) { } dialog.show(); }, - }); + }; + + return Filters; }); diff --git a/js/Feeds.js b/js/Feeds.js index 878e503d7..eb9a468ad 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -1,7 +1,7 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - return declare("fox.Feeds", null, { + Feeds = { counters_last_request: 0, _active_feed_id: 0, _active_feed_is_cat: false, @@ -636,5 +636,7 @@ define(["dojo/_base/declare"], function (declare) { App.handleRpcJson(transport, true); }); }, - }); + }; + + return Feeds; }); diff --git a/js/Headlines.js b/js/Headlines.js index 3ec83170e..fbe1bd98a 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -1,13 +1,13 @@ 'use strict'; /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - return declare("fox.Headlines", null, { + Headlines = { vgroup_last_feed: undefined, _headlines_scroll_timeout: 0, loaded_article_ids: [], current_first_id: 0, catchup_id_batch: [], - click: function(event, id, in_body) { + click: function (event, id, in_body) { in_body = in_body || false; if (App.isCombinedMode()) { @@ -34,16 +34,16 @@ define(["dojo/_base/declare"], function (declare) { return false; } }, - initScrollHandler: function() { + initScrollHandler: function () { $("headlines-frame").onscroll = (event) => { clearTimeout(this._headlines_scroll_timeout); - this._headlines_scroll_timeout = window.setTimeout(function() { + this._headlines_scroll_timeout = window.setTimeout(function () { //console.log('done scrolling', event); Headlines.scrollHandler(); }, 50); } }, - loadMore: function() { + loadMore: function () { const view_mode = document.forms["main_toolbar_form"].view_mode.value; const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; const num_all = $$("#headlines-frame > div[id*=RROW]").length; @@ -71,7 +71,7 @@ define(["dojo/_base/declare"], function (declare) { Feeds.open({feed: Feeds.getActive(), is_cat: Feeds.activeIsCat(), offset: offset}); }, - scrollHandler: function() { + scrollHandler: function () { try { Headlines.unpackVisible(); @@ -149,7 +149,7 @@ define(["dojo/_base/declare"], function (declare) { console.warn("scrollHandler", e); } }, - updateFloatingTitle: function(unread_only) { + updateFloatingTitle: function (unread_only) { if (!App.isCombinedMode()/* || !App.getInitParam("cdm_expanded")*/) return; const hf = $("headlines-frame"); @@ -200,7 +200,7 @@ define(["dojo/_base/declare"], function (declare) { } } }, - unpackVisible: function() { + unpackVisible: function () { if (!App.isCombinedMode() || !App.getInitParam("cdm_expanded")) return; const rows = $$("#headlines-frame div[id*=RROW][data-content]"); @@ -221,7 +221,7 @@ define(["dojo/_base/declare"], function (declare) { } } }, - onLoaded: function(transport, offset) { + onLoaded: function (transport, offset) { const reply = App.handleRpcJson(transport); console.log("Headlines.onLoaded: offset=", offset); @@ -383,7 +383,7 @@ define(["dojo/_base/declare"], function (declare) { Notify.close(); }, - reverse: function() { + reverse: function () { const toolbar = document.forms["main_toolbar_form"]; const order_by = dijit.getEnclosingWidget(toolbar.order_by); @@ -398,7 +398,7 @@ define(["dojo/_base/declare"], function (declare) { Feeds.reloadCurrent(); }, - selectionToggleUnread: function(params) { + selectionToggleUnread: function (params) { params = params || {}; const cmode = params.cmode || 2; @@ -442,7 +442,7 @@ define(["dojo/_base/declare"], function (declare) { if (callback) callback(transport); }); }, - selectionToggleMarked: function(ids) { + selectionToggleMarked: function (ids) { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { @@ -463,7 +463,7 @@ define(["dojo/_base/declare"], function (declare) { App.handleRpcJson(transport); }); }, - selectionTogglePublished: function(ids) { + selectionTogglePublished: function (ids) { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { @@ -486,7 +486,7 @@ define(["dojo/_base/declare"], function (declare) { }); } }, - toggleMark: function(id, client_only) { + toggleMark: function (id, client_only) { const query = {op: "rpc", id: id, method: "mark"}; const row = $("RROW-" + id); @@ -511,7 +511,7 @@ define(["dojo/_base/declare"], function (declare) { }); } }, - togglePub: function(id, client_only) { + togglePub: function (id, client_only) { const row = $("RROW-" + id); if (row) { @@ -538,7 +538,7 @@ define(["dojo/_base/declare"], function (declare) { } }, - move: function(mode, noscroll, noexpand) { + move: function (mode, noscroll, noexpand) { const rows = Headlines.getLoaded(); let prev_id = false; @@ -620,7 +620,7 @@ define(["dojo/_base/declare"], function (declare) { } } }, - updateSelectedPrompt: function() { + updateSelectedPrompt: function () { const count = Headlines.getSelected().length; const elem = $("selected_prompt"); @@ -631,7 +631,7 @@ define(["dojo/_base/declare"], function (declare) { count > 0 ? Element.show(elem) : Element.hide(elem); } }, - toggleUnread: function(id, cmode) { + toggleUnread: function (id, cmode) { const row = $("RROW-" + id); if (row) { @@ -658,7 +658,7 @@ define(["dojo/_base/declare"], function (declare) { }); } }, - selectionRemoveLabel: function(id, ids) { + selectionRemoveLabel: function (id, ids) { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { @@ -676,7 +676,7 @@ define(["dojo/_base/declare"], function (declare) { this.onLabelsUpdated(transport); }); }, - selectionAssignLabel: function(id, ids) { + selectionAssignLabel: function (id, ids) { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { @@ -694,7 +694,7 @@ define(["dojo/_base/declare"], function (declare) { this.onLabelsUpdated(transport); }); }, - deleteSelection: function() { + deleteSelection: function () { const rows = Headlines.getSelected(); if (rows.length == 0) { @@ -725,7 +725,7 @@ define(["dojo/_base/declare"], function (declare) { Feeds.reloadCurrent(); }); }, - getSelected: function() { + getSelected: function () { const rv = []; $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( @@ -739,7 +739,7 @@ define(["dojo/_base/declare"], function (declare) { return rv.uniq(); }, - getLoaded: function() { + getLoaded: function () { const rv = []; const children = $$("#headlines-frame > div[id*=RROW-]"); @@ -752,7 +752,7 @@ define(["dojo/_base/declare"], function (declare) { return rv; }, - onRowChecked: function(elem) { + onRowChecked: function (elem) { // account for dojo checkboxes elem = elem.domNode || elem; @@ -760,7 +760,7 @@ define(["dojo/_base/declare"], function (declare) { this.updateSelectedPrompt(); }, - select: function(mode) { + select: function (mode) { // mode = all,none,unread,invert,marked,published let query = "#headlines-frame > div[id*=RROW]"; @@ -814,7 +814,7 @@ define(["dojo/_base/declare"], function (declare) { Headlines.updateSelectedPrompt(); } }, - archiveSelection: function() { + archiveSelection: function () { const rows = Headlines.getSelected(); if (rows.length == 0) { @@ -854,7 +854,7 @@ define(["dojo/_base/declare"], function (declare) { Feeds.reloadCurrent(); }); }, - catchupSelection: function() { + catchupSelection: function () { const rows = Headlines.getSelected(); if (rows.length == 0) { @@ -875,7 +875,7 @@ define(["dojo/_base/declare"], function (declare) { Headlines.selectionToggleUnread({callback: Feeds.reloadCurrent, no_error: 1}); }, - catchupBatched: function(callback) { + catchupBatched: function (callback) { console.log("catchupBatched, size=", this.catchup_id_batch.length); if (this.catchup_id_batch.length > 0) { @@ -908,7 +908,7 @@ define(["dojo/_base/declare"], function (declare) { if (callback) callback(); } }, - catchupRelativeTo: function(below, id) { + catchupRelativeTo: function (below, id) { if (!id) id = Article.getActive(); @@ -970,7 +970,7 @@ define(["dojo/_base/declare"], function (declare) { } } }, - onLabelsUpdated: function(transport) { + onLabelsUpdated: function (transport) { const data = JSON.parse(transport.responseText); if (data) { @@ -981,11 +981,11 @@ define(["dojo/_base/declare"], function (declare) { }); } }, - onActionChanged: function(elem) { + onActionChanged: function (elem) { eval(elem.value); elem.attr('value', 'false'); }, - correctHeadlinesOffset: function(id) { + correctHeadlinesOffset: function (id) { const container = $("headlines-frame"); const row = $("RROW-" + id); @@ -1005,7 +1005,7 @@ define(["dojo/_base/declare"], function (declare) { container.scrollTop = row.offsetTop + row.offsetHeight - viewport; } }, - initFloatingMenu: function() { + initFloatingMenu: function () { if (!dijit.byId("floatingMenu")) { const menu = new dijit.Menu({ @@ -1018,7 +1018,7 @@ define(["dojo/_base/declare"], function (declare) { menu.startup(); } }, - headlinesMenuCommon: function(menu) { + headlinesMenuCommon: function (menu) { menu.addChild(new dijit.MenuItem({ label: __("Open original article"), @@ -1146,7 +1146,7 @@ define(["dojo/_base/declare"], function (declare) { } }, - initHeadlinesMenu: function() { + initHeadlinesMenu: function () { if (!dijit.byId("headlinesMenu")) { const menu = new dijit.Menu({ @@ -1209,5 +1209,7 @@ define(["dojo/_base/declare"], function (declare) { menu.startup(); } } - }); + } + + return Headlines; }); \ No newline at end of file diff --git a/js/PluginHost.js b/js/PluginHost.js index 9dbd91756..8e5ff32ec 100644 --- a/js/PluginHost.js +++ b/js/PluginHost.js @@ -1,6 +1,6 @@ // based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system -const PluginHost = { +PluginHost = { HOOK_ARTICLE_RENDERED: 1, HOOK_ARTICLE_RENDERED_CDM: 2, HOOK_ARTICLE_SET_ACTIVE: 3, diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 343253c9d..749e954cc 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -1,5 +1,5 @@ define(["dojo/_base/declare"], function (declare) { - return declare("fox.PrefHelpers", null, { + Prefs = { clearFeedAccessKeys: function() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { Notify.progress("Clearing URLs..."); @@ -148,5 +148,7 @@ define(["dojo/_base/declare"], function (declare) { Notify.close(); }); } - }); + } + + return Prefs; }); diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 20790ec5d..4f24f67cf 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -1,8 +1,7 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { - - return declare("fox.PrefUsers", null, { + Users = { reload: function(sort) { const user_search = $("user_search"); const search = user_search ? user_search.value : ""; @@ -115,7 +114,9 @@ define(["dojo/_base/declare"], function (declare) { getSelection :function() { return Tables.getSelected("prefUserList"); } - }); + } + + return Users; }); diff --git a/js/prefs.js b/js/prefs.js index 3600c5fb1..ea5d847a9 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -60,11 +60,6 @@ require(["dojo/_base/kernel", report_error(message, filename, lineno, colno, error); }; - CommonDialogs = fox.CommonDialogs(); - Filters = fox.CommonFilters(); - Users = fox.PrefUsers(); - Prefs = fox.PrefHelpers(); - parser.parse(); this.setLoadingProgress(50); diff --git a/js/tt-rss.js b/js/tt-rss.js index 446c6393b..78ef10067 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -8,6 +8,7 @@ let Feeds; let Headlines; let Article; let ArticleCache; +let PluginHost; require(["dojo/_base/kernel", "dojo/_base/declare", @@ -45,8 +46,9 @@ require(["dojo/_base/kernel", "dijit/tree/dndSource", "dijit/tree/ForestStoreModel", "dojo/data/ItemFileWriteStore", - "fox/CommonDialogs", + "fox/PluginHost", "fox/CommonFilters", + "fox/CommonDialogs", "fox/Feeds", "fox/Headlines", "fox/Article", @@ -65,13 +67,6 @@ require(["dojo/_base/kernel", report_error(message, filename, lineno, colno, error); }; - CommonDialogs = fox.CommonDialogs(); - Filters = fox.CommonFilters(); - Feeds = fox.Feeds(); - Headlines = fox.Headlines(); - Article = fox.Article(); - ArticleCache = fox.ArticleCache(); - parser.parse(); if (!this.genericSanityCheck()) -- cgit v1.2.3