From 049a37aa0e7d37cafd979e7d470c7649700b5010 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:05:28 +0300 Subject: WIP reshuffling of JS global context into separate logical objects --- plugins/af_psql_trgm/init.php | 2 +- plugins/close_button/init.php | 2 +- plugins/embed_original/init.js | 6 +++--- plugins/no_title_counters/init.js | 2 +- plugins/toggle_sidebar/init.php | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'plugins') diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index fe5b1a959..ff11c1201 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -93,7 +93,7 @@ class Af_Psql_Trgm extends Plugin { print " ". $line["title"].""; - print " (". + print " (". htmlspecialchars($line["feed_title"]).")"; print " ($sm)"; diff --git a/plugins/close_button/init.php b/plugins/close_button/init.php index 66d2af679..62f8780c4 100644 --- a/plugins/close_button/init.php +++ b/plugins/close_button/init.php @@ -21,7 +21,7 @@ class Close_Button extends Plugin { if (!get_pref("COMBINED_DISPLAY_MODE")) { $rv = ""; } diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 3c48b507e..d0731d5d1 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -9,7 +9,7 @@ function embedOriginalArticle(id) { let c = false; - if (isCombinedMode()) { + if (App.isCombinedMode()) { c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; } else if (id == getActiveArticleId()) { c = $$(".post .content")[0]; @@ -22,7 +22,7 @@ function embedOriginalArticle(id) { Element.show(c); c.parentNode.removeChild(iframe); - if (isCombinedMode()) { + if (App.isCombinedMode()) { cdmScrollToArticleId(id, true); } @@ -47,7 +47,7 @@ function embedOriginalArticle(id) { Element.hide(c); c.parentNode.insertBefore(iframe, c); - if (isCombinedMode()) { + if (App.isCombinedMode()) { cdmScrollToArticleId(id, true); } } diff --git a/plugins/no_title_counters/init.js b/plugins/no_title_counters/init.js index 06edfb3ba..1170bf3ef 100644 --- a/plugins/no_title_counters/init.js +++ b/plugins/no_title_counters/init.js @@ -1,6 +1,6 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { ready(function () { - updateTitle = function () { + App.updateTitle = function () { document.title = "Tiny Tiny RSS"; }; }); diff --git a/plugins/toggle_sidebar/init.php b/plugins/toggle_sidebar/init.php index b2b0821a5..2187e10ad 100644 --- a/plugins/toggle_sidebar/init.php +++ b/plugins/toggle_sidebar/init.php @@ -18,7 +18,7 @@ class Toggle_Sidebar extends Plugin { function hook_main_toolbar_button() { ?> - -- cgit v1.2.3-54-g00ecf From 1d82bd4f19de40f0cf966545c372595caa2c8afe Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:42:21 +0300 Subject: further objectification --- index.php | 6 +- js/functions.js | 110 +++++++------ js/tt-rss.js | 449 ++++++++++++++++++++++++--------------------------- js/viewfeed.js | 181 +++++++++++---------- plugins/note/note.js | 2 +- 5 files changed, 364 insertions(+), 384 deletions(-) (limited to 'plugins') diff --git a/index.php b/index.php index 820db9073..8b4b954ef 100644 --- a/index.php +++ b/index.php @@ -139,7 +139,7 @@ @@ -187,7 +187,7 @@
"; + onchange=\"Filters.filterDlgCheckAction(this)\">"; $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions ORDER BY name"); diff --git a/js/FeedTree.js b/js/FeedTree.js index 55eb3dc30..4a28bd2b0 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -48,7 +48,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], menu.addChild(new dijit.MenuItem({ label: __("Edit feed"), onClick: function() { - editFeed(this.getParent().row_id, false); + CommonDialogs.editFeed(this.getParent().row_id, false); }})); /* menu.addChild(new dijit.MenuItem({ diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 9d6a9e86c..afa644251 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -55,13 +55,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio menu.addChild(new dijit.MenuItem({ label: __("Edit feed"), onClick: function() { - editFeed(this.getParent().row_id); + CommonDialogs.editFeed(this.getParent().row_id); }})); menu.addChild(new dijit.MenuItem({ label: __("Unsubscribe"), onClick: function() { - unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); + CommonDialogs.unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); }})); menu.bindDomNode(tnode.domNode); diff --git a/js/functions.js b/js/functions.js index f4e422aec..21fe8c190 100755 --- a/js/functions.js +++ b/js/functions.js @@ -291,7 +291,7 @@ const Utils = { } if (k == "daemon_is_running" && v != 1) { - notify_error("Update daemon is not running.", true); + notify_error("Update daemon is not running.", true); return; } @@ -306,7 +306,7 @@ const Utils = { } if (k == "daemon_stamp_ok" && v != 1) { - notify_error("Update daemon is not updating feeds.", true); + notify_error("Update daemon is not updating feeds.", true); return; } @@ -376,7 +376,10 @@ const Utils = { } App.initSecondStage(); - } + }, + explainError: function(code) { + return this.displayDlg(__("Error explained"), "explainError", code); + }, }; const CommonDialogs = { @@ -674,6 +677,97 @@ const CommonDialogs = { } }); } + }, + unsubscribeFeed: function(feed_id, title) { + + const msg = __("Unsubscribe from %s?").replace("%s", title); + + if (title == undefined || confirm(msg)) { + notify_progress("Removing feed..."); + + const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id}; + + xhrPost("backend.php", query, (transport) => { + if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); + + if (App.isPrefs()) { + Feeds.reload(); + } else { + if (feed_id == Feeds.getActiveFeedId()) + setTimeout(() => { + Feeds.viewfeed({feed: -5}) + }, + 100); + + if (feed_id < 0) Feeds.reload(); + } + }); + } + + return false; + }, + editFeed: function (feed) { + if (feed <= 0) + return alert(__("You can't edit this kind of feed.")); + + const query = {op: "pref-feeds", method: "editfeed", id: feed}; + + console.log("editFeed", query); + + if (dijit.byId("filterEditDlg")) + dijit.byId("filterEditDlg").destroyRecursive(); + + if (dijit.byId("feedEditDlg")) + dijit.byId("feedEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "feedEditDlg", + title: __("Edit Feed"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving data...", true); + + xhrPost("backend.php", dialog.attr('value'), () => { + dialog.hide(); + notify(''); + Feeds.reload(); + }); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + }, + genUrlChangeKey: function(feed, is_cat) { + if (confirm(__("Generate new syndication address for this feed?"))) { + + notify_progress("Trying to change address...", true); + + const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat}; + + xhrJson("backend.php", query, (reply) => { + const new_link = reply.link; + const e = $('gen_feed_url'); + + if (new_link) { + e.innerHTML = e.innerHTML.replace(/\&key=.*$/, + "&key=" + new_link); + + e.href = e.href.replace(/\&key=.*$/, + "&key=" + new_link); + + new Effect.Highlight(e); + + notify(''); + + } else { + notify_error("Could not change feed URL."); + } + }); + } + return false; } }; @@ -994,463 +1088,433 @@ function fatalError(code, msg, ext_info) { } -// noinspection JSUnusedGlobalSymbols -function filterDlgCheckAction(sender) { - const action = sender.value; - - const action_param = $("filterDlg_paramBox"); +const Filters = { + filterDlgCheckAction: function(sender) { + const action = sender.value; - if (!action_param) { - console.log("filterDlgCheckAction: can't find action param box!"); - return; - } - - // if selected action supports parameters, enable params field - if (action == 4 || action == 6 || action == 7 || action == 9) { - new Effect.Appear(action_param, {duration : 0.5}); + const action_param = $("filterDlg_paramBox"); - Element.hide(dijit.byId("filterDlg_actionParam").domNode); - Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); - Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); - - if (action == 7) { - Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); - } else if (action == 9) { - Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); - } else { - Element.show(dijit.byId("filterDlg_actionParam").domNode); + if (!action_param) { + console.log("filterDlgCheckAction: can't find action param box!"); + return; } - } else { - Element.hide(action_param); - } -} - + // if selected action supports parameters, enable params field + if (action == 4 || action == 6 || action == 7 || action == 9) { + new Effect.Appear(action_param, {duration: 0.5}); -function explainError(code) { - return Utils.displayDlg(__("Error explained"), "explainError", code); -} + Element.hide(dijit.byId("filterDlg_actionParam").domNode); + Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); + Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); -function strip_tags(s) { - return s.replace(/<\/?[^>]+(>|$)/g, ""); -} - -// noinspection JSUnusedGlobalSymbols -function uploadIconHandler(rc) { - switch (rc) { - case 0: - notify_info("Upload complete."); - if (App.isPrefs()) { - Feeds.reload(); + if (action == 7) { + Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); + } else if (action == 9) { + Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); } else { - setTimeout('Feeds.reload(false, false)', 50); + Element.show(dijit.byId("filterDlg_actionParam").domNode); } - break; - case 1: - notify_error("Upload failed: icon is too big."); - break; - case 2: - notify_error("Upload failed."); - break; - } -} - -// noinspection JSUnusedGlobalSymbols -function removeFeedIcon(id) { - if (confirm(__("Remove stored feed icon?"))) { - - notify_progress("Removing feed icon...", true); - const query = { op: "pref-feeds", method: "removeicon", feed_id: id }; + } else { + Element.hide(action_param); + } + }, + createNewRuleElement: function(parentNode, replaceNode) { + const form = document.forms["filter_new_rule_form"]; + const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)}; xhrPost("backend.php", query, (transport) => { - notify_info("Feed icon removed."); - if (App.isPrefs()) { - Feeds.reload(); - } else { - setTimeout('Feeds.reload(false, false)', 50); + try { + const li = dojo.create("li"); + + const cb = dojo.create("input", {type: "checkbox"}, li); + + new dijit.form.CheckBox({ + onChange: function () { + toggleSelectListRow2(this) + }, + }, cb); + + dojo.create("input", { + type: "hidden", + name: "rule[]", + value: dojo.formToJson(form) + }, li); + + dojo.create("span", { + onclick: function () { + dijit.byId('filterEditDlg').editRule(this); + }, + innerHTML: transport.responseText + }, li); + + if (replaceNode) { + parentNode.replaceChild(li, replaceNode); + } else { + parentNode.appendChild(li); + } + } catch (e) { + exception_error(e); } }); - } - - return false; -} - -// noinspection JSUnusedGlobalSymbols -function uploadFeedIcon() { - const file = $("icon_file"); + }, + createNewActionElement: function(parentNode, replaceNode) { + const form = document.forms["filter_new_action_form"]; - if (file.value.length == 0) { - alert(__("Please select an image file to upload.")); - } else if (confirm(__("Upload new icon for this feed?"))) { - notify_progress("Uploading, please wait...", true); - return true; + if (form.action_id.value == 7) { + form.action_param.value = form.action_param_label.value; + } else if (form.action_id.value == 9) { + form.action_param.value = form.action_param_plugin.value; } - return false; -} - -function createNewRuleElement(parentNode, replaceNode) { - const form = document.forms["filter_new_rule_form"]; - const query = { op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form) }; - - xhrPost("backend.php", query, (transport) => { - try { - const li = dojo.create("li"); - - const cb = dojo.create("input", { type: "checkbox" }, li); - - new dijit.form.CheckBox({ - onChange: function() { - toggleSelectListRow2(this) }, - }, cb); - - dojo.create("input", { type: "hidden", - name: "rule[]", - value: dojo.formToJson(form) }, li); + const query = { + op: "pref-filters", method: "printactionname", + action: dojo.formToJson(form) + }; - dojo.create("span", { - onclick: function() { - dijit.byId('filterEditDlg').editRule(this); - }, - innerHTML: transport.responseText }, li); + xhrPost("backend.php", query, (transport) => { + try { + const li = dojo.create("li"); + + const cb = dojo.create("input", {type: "checkbox"}, li); + + new dijit.form.CheckBox({ + onChange: function () { + toggleSelectListRow2(this) + }, + }, cb); + + dojo.create("input", { + type: "hidden", + name: "action[]", + value: dojo.formToJson(form) + }, li); + + dojo.create("span", { + onclick: function () { + dijit.byId('filterEditDlg').editAction(this); + }, + innerHTML: transport.responseText + }, li); + + if (replaceNode) { + parentNode.replaceChild(li, replaceNode); + } else { + parentNode.appendChild(li); + } - if (replaceNode) { - parentNode.replaceChild(li, replaceNode); - } else { - parentNode.appendChild(li); + } catch (e) { + exception_error(e); } - } catch (e) { - exception_error(e); - } - }); -} - -function createNewActionElement(parentNode, replaceNode) { - const form = document.forms["filter_new_action_form"]; - - if (form.action_id.value == 7) { - form.action_param.value = form.action_param_label.value; - } else if (form.action_id.value == 9) { - form.action_param.value = form.action_param_plugin.value; - } - - const query = { op: "pref-filters", method: "printactionname", - action: dojo.formToJson(form) }; - - xhrPost("backend.php", query, (transport) => { - try { - const li = dojo.create("li"); - - const cb = dojo.create("input", { type: "checkbox" }, li); - - new dijit.form.CheckBox({ - onChange: function() { - toggleSelectListRow2(this) }, - }, cb); - - dojo.create("input", { type: "hidden", - name: "action[]", - value: dojo.formToJson(form) }, li); - - dojo.create("span", { - onclick: function() { - dijit.byId('filterEditDlg').editAction(this); - }, - innerHTML: transport.responseText }, li); + }); + }, + addFilterRule: function(replaceNode, ruleStr) { + if (dijit.byId("filterNewRuleDlg")) + dijit.byId("filterNewRuleDlg").destroyRecursive(); - if (replaceNode) { - parentNode.replaceChild(li, replaceNode); - } else { - parentNode.appendChild(li); - } + const query = "backend.php?op=pref-filters&method=newrule&rule=" + + param_escape(ruleStr); - } catch (e) { - exception_error(e); - } - }); -} + const rule_dlg = new dijit.Dialog({ + id: "filterNewRuleDlg", + title: ruleStr ? __("Edit rule") : __("Add rule"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode); + this.hide(); + } + }, + href: query + }); + rule_dlg.show(); + }, + addFilterAction: function(replaceNode, actionStr) { + if (dijit.byId("filterNewActionDlg")) + dijit.byId("filterNewActionDlg").destroyRecursive(); -function addFilterRule(replaceNode, ruleStr) { - if (dijit.byId("filterNewRuleDlg")) - dijit.byId("filterNewRuleDlg").destroyRecursive(); + const query = "backend.php?op=pref-filters&method=newaction&action=" + + param_escape(actionStr); - const query = "backend.php?op=pref-filters&method=newrule&rule=" + - param_escape(ruleStr); + const rule_dlg = new dijit.Dialog({ + id: "filterNewActionDlg", + title: actionStr ? __("Edit action") : __("Add action"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Filters.createNewActionElement($("filterDlg_Actions"), replaceNode); + this.hide(); + } + }, + href: query + }); - const rule_dlg = new dijit.Dialog({ - id: "filterNewRuleDlg", - title: ruleStr ? __("Edit rule") : __("Add rule"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - createNewRuleElement($("filterDlg_Matches"), replaceNode); - this.hide(); - } - }, - href: query}); + rule_dlg.show(); + }, + editFilterTest: function(query) { - rule_dlg.show(); -} + if (dijit.byId("filterTestDlg")) + dijit.byId("filterTestDlg").destroyRecursive(); -function addFilterAction(replaceNode, actionStr) { - if (dijit.byId("filterNewActionDlg")) - dijit.byId("filterNewActionDlg").destroyRecursive(); - - const query = "backend.php?op=pref-filters&method=newaction&action=" + - param_escape(actionStr); - - const rule_dlg = new dijit.Dialog({ - id: "filterNewActionDlg", - title: actionStr ? __("Edit action") : __("Add action"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - createNewActionElement($("filterDlg_Actions"), replaceNode); - this.hide(); - } - }, - href: query}); + const test_dlg = new dijit.Dialog({ + id: "filterTestDlg", + title: "Test Filter", + style: "width: 600px", + results: 0, + limit: 100, + max_offset: 10000, + getTestResults: function (query, offset) { + const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; - rule_dlg.show(); -} + console.log("getTestResults:" + offset); -function editFilterTest(query) { + xhrPost("backend.php", updquery, (transport) => { + try { + const result = JSON.parse(transport.responseText); - if (dijit.byId("filterTestDlg")) - dijit.byId("filterTestDlg").destroyRecursive(); + if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { + test_dlg.results += result.length; - const test_dlg = new dijit.Dialog({ - id: "filterTestDlg", - title: "Test Filter", - style: "width: 600px", - results: 0, - limit: 100, - max_offset: 10000, - getTestResults: function(query, offset) { - const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; + console.log("got results:" + result.length); - console.log("getTestResults:" + offset); + $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") + .replace("%f", test_dlg.results) + .replace("%d", offset); - xhrPost("backend.php", updquery, (transport) => { - try { - const result = JSON.parse(transport.responseText); + console.log(offset + " " + test_dlg.max_offset); - if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { - test_dlg.results += result.length; + for (let i = 0; i < result.length; i++) { + const tmp = new Element("table"); + tmp.innerHTML = result[i]; + dojo.parser.parse(tmp); - console.log("got results:" + result.length); + $("prefFilterTestResultList").innerHTML += tmp.innerHTML; + } - $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") - .replace("%f", test_dlg.results) - .replace("%d", offset); + if (test_dlg.results < 30 && offset < test_dlg.max_offset) { - console.log(offset + " " + test_dlg.max_offset); + // get the next batch + window.setTimeout(function () { + test_dlg.getTestResults(query, offset + test_dlg.limit); + }, 0); - for (let i = 0; i < result.length; i++) { - const tmp = new Element("table"); - tmp.innerHTML = result[i]; - dojo.parser.parse(tmp); + } else { + // all done - $("prefFilterTestResultList").innerHTML += tmp.innerHTML; - } + Element.hide("prefFilterLoadingIndicator"); - if (test_dlg.results < 30 && offset < test_dlg.max_offset) { + if (test_dlg.results == 0) { + $("prefFilterTestResultList").innerHTML = "No recent articles matching this filter have been found."; + $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:"; + } else { + $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:") + .replace("%d", test_dlg.results); + } - // get the next batch - window.setTimeout(function () { - test_dlg.getTestResults(query, offset + test_dlg.limit); - }, 0); + } - } else { - // all done + } else if (!result) { + console.log("getTestResults: can't parse results object"); Element.hide("prefFilterLoadingIndicator"); - if (test_dlg.results == 0) { - $("prefFilterTestResultList").innerHTML = "No recent articles matching this filter have been found."; - $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:"; - } else { - $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:") - .replace("%d", test_dlg.results); - } + notify_error("Error while trying to get filter test results."); + } else { + console.log("getTestResults: dialog closed, bailing out."); } + } catch (e) { + exception_error(e); + } - } else if (!result) { - console.log("getTestResults: can't parse results object"); - - Element.hide("prefFilterLoadingIndicator"); - - notify_error("Error while trying to get filter test results."); + }); + }, + href: query + }); - } else { - console.log("getTestResults: dialog closed, bailing out."); - } - } catch (e) { - exception_error(e); - } + dojo.connect(test_dlg, "onLoad", null, function (e) { + test_dlg.getTestResults(query, 0); + }); - }); - }, - href: query}); + test_dlg.show(); + }, + quickAddFilter: function() { + let query; + + if (!App.isPrefs()) { + query = { + op: "pref-filters", method: "newfilter", + feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() + }; + } else { + query = {op: "pref-filters", method: "newfilter"}; + } - dojo.connect(test_dlg, "onLoad", null, function(e) { - test_dlg.getTestResults(query, 0); - }); + console.log('quickAddFilter', query); - test_dlg.show(); + if (dijit.byId("feedEditDlg")) + dijit.byId("feedEditDlg").destroyRecursive(); -} + if (dijit.byId("filterEditDlg")) + dijit.byId("filterEditDlg").destroyRecursive(); -function quickAddFilter() { - let query; + const dialog = new dijit.Dialog({ + id: "filterEditDlg", + title: __("Create Filter"), + style: "width: 600px", + test: function () { + const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; - if (!App.isPrefs()) { - query = { op: "pref-filters", method: "newfilter", - feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() }; - } else { - query = { op: "pref-filters", method: "newfilter" }; - } + Filters.editFilterTest(query); + }, + selectRules: function (select) { + $$("#filterDlg_Matches input[type=checkbox]").each(function (e) { + e.checked = select; + if (select) + e.parentNode.addClassName("Selected"); + else + e.parentNode.removeClassName("Selected"); + }); + }, + selectActions: function (select) { + $$("#filterDlg_Actions input[type=checkbox]").each(function (e) { + e.checked = select; - console.log('quickAddFilter', query); + if (select) + e.parentNode.addClassName("Selected"); + else + e.parentNode.removeClassName("Selected"); - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); + }); + }, + editRule: function (e) { + const li = e.parentNode; + const rule = li.getElementsByTagName("INPUT")[1].value; + Filters.addFilterRule(li, rule); + }, + editAction: function (e) { + const li = e.parentNode; + const action = li.getElementsByTagName("INPUT")[1].value; + Filters.addFilterAction(li, action); + }, + addAction: function () { + Filters.addFilterAction(); + }, + addRule: function () { + Filters.addFilterRule(); + }, + deleteAction: function () { + $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { + e.parentNode.removeChild(e) + }); + }, + deleteRule: function () { + $$("#filterDlg_Matches li[class*=Selected]").each(function (e) { + e.parentNode.removeChild(e) + }); + }, + execute: function () { + if (this.validate()) { - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); + const query = dojo.formToQuery("filter_new_form"); - const dialog = new dijit.Dialog({ - id: "filterEditDlg", - title: __("Create Filter"), - style: "width: 600px", - test: function() { - const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; + xhrPost("backend.php", query, () => { + if (App.isPrefs()) { + updateFilterList(); + } - editFilterTest(query); - }, - selectRules: function(select) { - $$("#filterDlg_Matches input[type=checkbox]").each(function(e) { - e.checked = select; - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); - }); - }, - selectActions: function(select) { - $$("#filterDlg_Actions input[type=checkbox]").each(function(e) { - e.checked = select; + dialog.hide(); + }); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); + if (!App.isPrefs()) { + const selectedText = getSelectionText(); - }); - }, - editRule: function(e) { - const li = e.parentNode; - const rule = li.getElementsByTagName("INPUT")[1].value; - addFilterRule(li, rule); - }, - editAction: function(e) { - const li = e.parentNode; - const action = li.getElementsByTagName("INPUT")[1].value; - addFilterAction(li, action); - }, - addAction: function() { addFilterAction(); }, - addRule: function() { addFilterRule(); }, - deleteAction: function() { - $$("#filterDlg_Actions li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); - }, - deleteRule: function() { - $$("#filterDlg_Matches li[class*=Selected]").each(function(e) { e.parentNode.removeChild(e) }); - }, - execute: function() { - if (this.validate()) { - - const query = dojo.formToQuery("filter_new_form"); - - xhrPost("backend.php", query, (transport) => { - if (App.isPrefs()) { - updateFilterList(); - } + const lh = dojo.connect(dialog, "onLoad", function () { + dojo.disconnect(lh); - dialog.hide(); - }); - } - }, - href: "backend.php?" + dojo.objectToQuery(query)}); + if (selectedText != "") { - if (!App.isPrefs()) { - const selectedText = getSelectionText(); + const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : + Feeds.getActiveFeedId(); - const lh = dojo.connect(dialog, "onLoad", function(){ - dojo.disconnect(lh); + const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1}; - if (selectedText != "") { + Filters.addFilterRule(null, dojo.toJson(rule)); - const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : - Feeds.getActiveFeedId(); + } else { - const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 }; + const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId()}; - addFilterRule(null, dojo.toJson(rule)); + xhrPost("backend.php", query, (transport) => { + const reply = JSON.parse(transport.responseText); - } else { + let title = false; - const query = { op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId() }; + if (reply && reply.title) title = reply.title; - xhrPost("backend.php", query, (transport) => { - const reply = JSON.parse(transport.responseText); + if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) { - let title = false; + console.log(title + " " + Feeds.getActiveFeedId()); - if (reply && reply.title) title = reply.title; + const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : + Feeds.getActiveFeedId(); - if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) { + const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1}; - console.log(title + " " + Feeds.getActiveFeedId()); + Filters.addFilterRule(null, dojo.toJson(rule)); + } + }); + } + }); + } - const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : - Feeds.getActiveFeedId(); + dialog.show(); + }, +}; - const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 }; +/* function strip_tags(s) { + return s.replace(/<\/?[^>]+(>|$)/g, ""); +} */ - addFilterRule(null, dojo.toJson(rule)); - } - }); +// noinspection JSUnusedGlobalSymbols +function uploadIconHandler(rc) { + switch (rc) { + case 0: + notify_info("Upload complete."); + if (App.isPrefs()) { + Feeds.reload(); + } else { + setTimeout('Feeds.reload(false, false)', 50); } - }); + break; + case 1: + notify_error("Upload failed: icon is too big."); + break; + case 2: + notify_error("Upload failed."); + break; } - - dialog.show(); - } -function unsubscribeFeed(feed_id, title) { - - const msg = __("Unsubscribe from %s?").replace("%s", title); +// noinspection JSUnusedGlobalSymbols +function removeFeedIcon(id) { + if (confirm(__("Remove stored feed icon?"))) { - if (title == undefined || confirm(msg)) { - notify_progress("Removing feed..."); + notify_progress("Removing feed icon...", true); - const query = { op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id }; + const query = { op: "pref-feeds", method: "removeicon", feed_id: id }; xhrPost("backend.php", query, (transport) => { - if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); - + notify_info("Feed icon removed."); if (App.isPrefs()) { Feeds.reload(); } else { - if (feed_id == Feeds.getActiveFeedId()) - setTimeout(() => { Feeds.viewfeed({feed:-5}) }, - 100); - - if (feed_id < 0) Feeds.reload(); + setTimeout('Feeds.reload(false, false)', 50); } }); } @@ -1459,33 +1523,16 @@ function unsubscribeFeed(feed_id, title) { } // noinspection JSUnusedGlobalSymbols -function genUrlChangeKey(feed, is_cat) { - if (confirm(__("Generate new syndication address for this feed?"))) { - - notify_progress("Trying to change address...", true); - - const query = { op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat }; - - xhrJson("backend.php", query, (reply) => { - const new_link = reply.link; - const e = $('gen_feed_url'); - - if (new_link) { - e.innerHTML = e.innerHTML.replace(/\&key=.*$/, - "&key=" + new_link); - - e.href = e.href.replace(/\&key=.*$/, - "&key=" + new_link); - - new Effect.Highlight(e); +function uploadFeedIcon() { + const file = $("icon_file"); - notify(''); + if (file.value.length == 0) { + alert(__("Please select an image file to upload.")); + } else if (confirm(__("Upload new icon for this feed?"))) { + notify_progress("Uploading, please wait...", true); + return true; + } - } else { - notify_error("Could not change feed URL."); - } - }); - } return false; } @@ -1541,7 +1588,6 @@ function selectTableRows(id, mode) { } } } - } function getSelectedTableRowIds(id) { @@ -1559,45 +1605,6 @@ function getSelectedTableRowIds(id) { return rows; } -function editFeed(feed) { - if (feed <= 0) - return alert(__("You can't edit this kind of feed.")); - - const query = { op: "pref-feeds", method: "editfeed", id: feed }; - - console.log("editFeed", query); - - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "feedEditDlg", - title: __("Edit Feed"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - notify_progress("Saving data...", true); - - xhrPost("backend.php", dialog.attr('value'), () => { - dialog.hide(); - notify(''); - Feeds.reload(); - }); - } - }, - href: "backend.php?" + dojo.objectToQuery(query)}); - - dialog.show(); -} - -function get_timestamp() { - const date = new Date(); - return Math.round(date.getTime() / 1000); -} - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); diff --git a/js/prefs.js b/js/prefs.js index 67be0b474..0d35355d2 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -82,7 +82,7 @@ const App = { const param = getURLParam('methodparam'); window.setTimeout(function () { - editFeed(param) + CommonDialogs.editFeed(param) }, 100); } }, @@ -100,7 +100,7 @@ const App = { CommonDialogs.addLabel(); return false; case "create_filter": - quickAddFilter(); + Filters.quickAddFilter(); return false; case "help_dialog": Utils.helpDialog("main"); @@ -575,7 +575,7 @@ function editSelectedFeed() { notify(""); - editFeed(rows[0], {}); + CommonDialogs.editFeed(rows[0], {}); } diff --git a/js/tt-rss.js b/js/tt-rss.js index 6dd4a91eb..9c5a78ce2 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -360,7 +360,7 @@ const App = { if (Feeds.activeFeedIsCat()) alert(__("You can't edit this kind of feed.")); else - editFeed(Feeds.getActiveFeedId()); + CommonDialogs.editFeed(Feeds.getActiveFeedId()); }; this.hotkey_actions["feed_catchup"] = function () { if (Feeds.getActiveFeedId() != undefined) { @@ -424,7 +424,7 @@ const App = { CommonDialogs.addLabel(); }; this.hotkey_actions["create_filter"] = function () { - quickAddFilter(); + Filters.quickAddFilter(); }; this.hotkey_actions["collapse_sidebar"] = function () { Feeds.viewCurrentFeed(); @@ -501,7 +501,7 @@ const App = { if (Feeds.activeFeedIsCat()) alert(__("You can't edit this kind of feed.")); else - editFeed(Feeds.getActiveFeedId()); + CommonDialogs.editFeed(Feeds.getActiveFeedId()); break; case "qmcRemoveFeed": var actid = Feeds.getActiveFeedId(); @@ -521,7 +521,7 @@ const App = { var pr = __("Unsubscribe from %s?").replace("%s", fn); if (confirm(pr)) { - unsubscribeFeed(actid); + CommonDialogs.unsubscribeFeed(actid); } break; case "qmcCatchupAll": diff --git a/js/viewfeed.js b/js/viewfeed.js index 1821c4853..3fb9f0749 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1560,7 +1560,7 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Edit feed"), onClick: function () { - editFeed(this.getParent().currentTarget.getAttribute("data-feed-id")); + CommonDialogs.editFeed(this.getParent().currentTarget.getAttribute("data-feed-id")); } })); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index ff11c1201..362b9771f 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -202,7 +202,7 @@ class Af_Psql_Trgm extends Plugin { print "
  • " . " " . + onclick='CommonDialogs.editFeed($f)'>" . Feeds::getFeedTitle($f) . "
  • "; } print ""; diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index cccdf8af7..e0c57d093 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -94,7 +94,7 @@ class Af_Readability extends Plugin { print "
  • " . " ". + onclick='CommonDialogs.editFeed($f)'>". Feeds::getFeedTitle($f) . "
  • "; } print ""; diff --git a/tests/functional/BasicTest.php b/tests/functional/BasicTest.php index c5bc70b4e..eba8a2c89 100644 --- a/tests/functional/BasicTest.php +++ b/tests/functional/BasicTest.php @@ -25,7 +25,7 @@ class BasicTest extends PHPUnit_Extensions_Selenium2TestCase { public function testBasicDialogs() { $this->testLogin(); - $this->execute(["script" => "quickAddFilter()", "args" => []]); + $this->execute(["script" => "Filters.quickAddFilter()", "args" => []]); $this->byCssSelector("#filterEditDlg")->displayed(); $this->execute(["script" => "dijit.byId('filterEditDlg').hide();", "args" => []]); -- cgit v1.2.3-54-g00ecf From 3678315bead3f7264dc2aa9c7feb6e0a0f20ea63 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:32:13 +0300 Subject: Article, Headlines: shorten several method names --- classes/article.php | 2 +- classes/feeds.php | 4 +- js/feedlist.js | 8 +- js/functions.js | 2 +- js/tt-rss.js | 48 +++++----- js/viewfeed.js | 212 ++++++++++++++++++++--------------------- plugins/close_button/init.php | 2 +- plugins/embed_original/init.js | 6 +- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- 10 files changed, 144 insertions(+), 144 deletions(-) (limited to 'plugins') diff --git a/classes/article.php b/classes/article.php index 60a956c8d..20febdf3b 100755 --- a/classes/article.php +++ b/classes/article.php @@ -727,7 +727,7 @@ class Article extends Handler_Protected { if (!$zoom_mode) { $rv['content'] .= "$tags_str (+)"; + href=\"#\" onclick=\"Article.editTags($id)\">(+)"; $rv['content'] .= "
    "; if ($score > 500) { diff --git a/js/feedlist.js b/js/feedlist.js index 53274b8ba..400328317 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -212,7 +212,7 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); + window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); if (!this.getActiveFeedId()) { this.viewfeed({feed: -3}); @@ -304,7 +304,7 @@ const Feeds = { if (feed != this.getActiveFeedId() || this.activeFeedIsCat() != is_cat) { this._search_query = false; - Article.setActiveArticleId(0); + Article.setActive(0); } if (offset != 0) { @@ -371,7 +371,7 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - Headlines.catchupBatchedArticles(() => { + Headlines.catchupBatched(() => { xhrPost("backend.php", query, (transport) => { try { window.clearTimeout(this._infscroll_timeout); @@ -494,7 +494,7 @@ const Feeds = { rows.each(function (row) { row.removeClassName("Unread"); - if (row.getAttribute("data-article-id") != Article.getActiveArticleId()) { + if (row.getAttribute("data-article-id") != Article.getActive()) { new Effect.Fade(row, {duration: 0.5}); } diff --git a/js/functions.js b/js/functions.js index a4d9893d4..a3b257979 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1454,7 +1454,7 @@ const Filters = { } else { - const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActiveArticleId()}; + const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()}; xhrPost("backend.php", query, (transport) => { const reply = JSON.parse(transport.responseText); diff --git a/js/tt-rss.js b/js/tt-rss.js index e6dbd1107..8750dcdd2 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -90,7 +90,7 @@ const App = { }, initSecondStage: function () { Feeds.reload(); - Article.closeArticlePanel(); + Article.close(); if (parseInt(getCookie("ttrss_fh_width")) > 0) { dijit.byId("feeds-holder").domNode.setStyle( @@ -190,7 +190,7 @@ const App = { switchPanelMode: function(wide) { if (App.isCombinedMode()) return; - const article_id = Article.getActiveArticleId(); + const article_id = Article.getActive(); if (wide) { dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); @@ -226,7 +226,7 @@ const App = { } - Article.closeArticlePanel(); + Article.close(); if (article_id) Article.view(article_id); @@ -246,22 +246,22 @@ const App = { if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) }; this.hotkey_actions["next_article"] = function () { - Headlines.moveToPost('next'); + Headlines.move('next'); }; this.hotkey_actions["prev_article"] = function () { - Headlines.moveToPost('prev'); + Headlines.move('prev'); }; this.hotkey_actions["next_article_noscroll"] = function () { - Headlines.moveToPost('next', true); + Headlines.move('next', true); }; this.hotkey_actions["prev_article_noscroll"] = function () { - Headlines.moveToPost('prev', true); + Headlines.move('prev', true); }; this.hotkey_actions["next_article_noexpand"] = function () { - Headlines.moveToPost('next', true, true); + Headlines.move('next', true, true); }; this.hotkey_actions["prev_article_noexpand"] = function () { - Headlines.moveToPost('prev', true, true); + Headlines.move('prev', true, true); }; this.hotkey_actions["search_dialog"] = function () { Feeds.search(); @@ -276,33 +276,33 @@ const App = { Headlines.selectionToggleUnread({no_error: 1}); }; this.hotkey_actions["edit_tags"] = function () { - const id = Article.getActiveArticleId(); + const id = Article.getActive(); if (id) { - Article.editArticleTags(id); + Article.editTags(id); } }; this.hotkey_actions["open_in_new_window"] = function () { - if (Article.getActiveArticleId()) { - Article.openArticleInNewWindow(Article.getActiveArticleId()); + if (Article.getActive()) { + Article.openInNewWindow(Article.getActive()); } }; this.hotkey_actions["catchup_below"] = function () { - Headlines.catchupRelativeToArticle(1); + Headlines.catchupRelativeTo(1); }; this.hotkey_actions["catchup_above"] = function () { - Headlines.catchupRelativeToArticle(0); + Headlines.catchupRelativeTo(0); }; this.hotkey_actions["article_scroll_down"] = function () { - Article.scrollArticle(40); + Article.scroll(40); }; this.hotkey_actions["article_scroll_up"] = function () { - Article.scrollArticle(-40); + Article.scroll(-40); }; this.hotkey_actions["close_article"] = function () { if (App.isCombinedMode()) { - Article.cdmCollapseActive(); + Article.cdmUnsetActive(); } else { - Article.closeArticlePanel(); + Article.close(); } }; this.hotkey_actions["email_article"] = function () { @@ -368,7 +368,7 @@ const App = { } }; this.hotkey_actions["feed_reverse"] = function () { - Headlines.reverseHeadlineOrder(); + Headlines.reverse(); }; this.hotkey_actions["feed_toggle_vgroup"] = function () { xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { @@ -402,7 +402,7 @@ const App = { document.location.href = "prefs.php"; }; this.hotkey_actions["select_article_cursor"] = function () { - const id = Article.getArticleUnderPointer(); + const id = Article.getUnderPointer(); if (id) { const row = $("RROW-" + id); @@ -431,8 +431,8 @@ const App = { }; this.hotkey_actions["toggle_embed_original"] = function () { if (typeof embedOriginalArticle != "undefined") { - if (Article.getActiveArticleId()) - embedOriginalArticle(Article.getActiveArticleId()); + if (Article.getActive()) + embedOriginalArticle(Article.getActive()); } else { alert(__("Please enable embed_original plugin first.")); } @@ -462,7 +462,7 @@ const App = { setInitParam("combined_display_mode", !getInitParam("combined_display_mode")); - Article.closeArticlePanel(); + Article.close(); Feeds.viewCurrentFeed(); }) }; diff --git a/js/viewfeed.js b/js/viewfeed.js index a609a65d1..83e943696 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -26,8 +26,8 @@ const ArticleCache = { const Article = { _active_article_id: 0, - setSelectionScore: function() { - const ids = Headlines.getSelectedArticleIds2(); + selectionSetScore: function() { + const ids = Headlines.getSelected(); if (ids.length > 0) { console.log(ids); @@ -63,7 +63,7 @@ const Article = { alert(__("No articles are selected.")); } }, - changeScore: function(id, pic) { + setScore: function(id, pic) { const score = pic.getAttribute("score"); const new_score = prompt(__("Please enter new score for this article:"), score); @@ -80,12 +80,30 @@ const Article = { }); } }, - closeArticlePanel: function () { + cdmUnsetActive: function(event) { + const row = $("RROW-" + Article.getActive()); + + if (row) { + row.removeClassName("active"); + const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); + + if (cb && !row.hasClassName("Selected")) + cb.attr("checked", false); + + Article.setActive(0); + + if (event) + event.stopPropagation(); + + return false; + } + }, + close: function () { if (dijit.byId("content-insert")) dijit.byId("headlines-wrap-inner").removeChild( dijit.byId("content-insert")); }, - displayArticleUrl: function (id) { + displayUrl: function (id) { const query = {op: "rpc", method: "getlinktitlebyid", id: id}; xhrJson("backend.php", query, (reply) => { @@ -94,14 +112,14 @@ const Article = { } }); }, - openArticleInNewWindow: function (id) { + openInNewWindow: function (id) { const w = window.open(""); w.opener = null; w.location = "backend.php?op=article&method=redirect&id=" + id; - Article.setActiveArticleId(id); + Article.setActive(id); }, - renderArticle: function (article) { + render: function (article) { Utils.cleanupMemory("content-insert"); dijit.byId("headlines-wrap-inner").addChild( @@ -117,7 +135,7 @@ const Article = { c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); - Headlines.correctHeadlinesOffset(Article.getActiveArticleId()); + Headlines.correctHeadlinesOffset(Article.getActive()); try { c.focus(); @@ -125,7 +143,7 @@ const Article = { } }, view: function(id, noexpand) { - this.setActiveArticleId(id); + this.setActive(id); if (!noexpand) { console.log("loading article", id); @@ -134,7 +152,7 @@ const Article = { /* only request uncached articles */ - this.getRelativePostIds(id).each((n) => { + this.getRelativeIds(id).each((n) => { if (!ArticleCache.get(n)) cids.push(n); }); @@ -143,7 +161,7 @@ const Article = { if (cached_article) { console.log('rendering cached', id); - this.renderArticle(cached_article); + this.render(cached_article); return false; } @@ -154,8 +172,8 @@ const Article = { if (reply) { reply.each(function (article) { - if (Article.getActiveArticleId() == article['id']) { - Article.renderArticle(article['content']); + if (Article.getActive() == article['id']) { + Article.render(article['content']); } ArticleCache.set(article['id'], article['content']); }); @@ -163,7 +181,7 @@ const Article = { } else { console.error("Invalid object received: " + transport.responseText); - Article.renderArticle("
    " + + Article.render("
    " + __('Could not display article (invalid object received - see error console for details)') + "
    "); } @@ -180,25 +198,7 @@ const Article = { return false; }, - cdmCollapseActive: function(event) { - const row = $("RROW-" + Article.getActiveArticleId()); - - if (row) { - row.removeClassName("active"); - const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]); - - if (cb && !row.hasClassName("Selected")) - cb.attr("checked", false); - - Article.setActiveArticleId(0); - - if (event) - event.stopPropagation(); - - return false; - } - }, - editArticleTags: function(id) { + editTags: function(id) { const query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); if (dijit.byId("editTagsDlg")) @@ -247,7 +247,7 @@ const Article = { dialog.show(); }, - cdmScrollToArticleId: function(id, force) { + cdmScrollToId: function(id, force) { const ctr = $("headlines-frame"); const e = $("RROW-" + id); @@ -262,8 +262,8 @@ const Article = { Element.hide("floatingTitle"); } }, - setActiveArticleId: function(id) { - console.log("setActiveArticleId", id); + setActive: function(id) { + console.log("setActive", id); $$("div[id*=RROW][class*=active]").each((e) => { e.removeClassName("active"); @@ -290,7 +290,7 @@ const Article = { if (row.hasClassName("Unread")) { - Headlines.catchupBatchedArticles(() => { + Headlines.catchupBatched(() => { Feeds.decrementFeedCounter(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); Headlines.toggleUnread(id, 0); Headlines.updateFloatingTitle(true); @@ -310,10 +310,10 @@ const Article = { Headlines.updateSelectedPrompt(); }, - getActiveArticleId: function() { + getActive: function() { return this._active_article_id; }, - scrollArticle: function(offset) { + scroll: function(offset) { if (!App.isCombinedMode()) { const ci = $("content-insert"); if (ci) { @@ -327,13 +327,13 @@ const Article = { } }, - getRelativePostIds: function(id, limit) { + getRelativeIds: function(id, limit) { const tmp = []; if (!limit) limit = 6; //3 - const ids = Headlines.getLoadedArticleIds(); + const ids = Headlines.getLoaded(); for (let i = 0; i < ids.length; i++) { if (ids[i] == id) { @@ -353,7 +353,7 @@ const Article = { mouseOut: function(id) { this.post_under_pointer = false; }, - getArticleUnderPointer: function() { + getUnderPointer: function() { return this.post_under_pointer; } }; @@ -369,21 +369,21 @@ const Headlines = { if (App.isCombinedMode()) { - if (!in_body && (event.ctrlKey || id == Article.getActiveArticleId() || getInitParam("cdm_expanded"))) { - Article.openArticleInNewWindow(id); + if (!in_body && (event.ctrlKey || id == Article.getActive() || getInitParam("cdm_expanded"))) { + Article.openInNewWindow(id); } - Article.setActiveArticleId(id); + Article.setActive(id); if (!getInitParam("cdm_expanded")) - Article.cdmScrollToArticleId(id); + Article.cdmScrollToId(id); return in_body; } else { if (event.ctrlKey) { - Article.openArticleInNewWindow(id); - Article.setActiveArticleId(id); + Article.openInNewWindow(id); + Article.setActive(id); } else { Article.view(id); } @@ -400,7 +400,7 @@ const Headlines = { }, 50); } }, - loadMoreHeadlines: 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; @@ -413,7 +413,7 @@ const Headlines = { switch (view_mode) { case "marked": case "published": - console.warn("loadMoreHeadlines: ", view_mode, "not implemented"); + console.warn("loadMore: ", view_mode, "not implemented"); break; case "unread": offset = unread_in_buffer; @@ -424,13 +424,13 @@ const Headlines = { break; } - console.log("loadMoreHeadlines, offset=", offset); + console.log("loadMore, offset=", offset); Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), offset: offset}); }, scrollHandler: function() { try { - Headlines.unpackVisibleArticles(); + Headlines.unpackVisible(); if (App.isCombinedMode()) { Headlines.updateFloatingTitle(); @@ -447,9 +447,9 @@ const Headlines = { if ($("headlines-frame").scrollTop <= row.offsetTop && row.offsetTop - $("headlines-frame").scrollTop < 100 && - row.getAttribute("data-article-id") != Article.getActiveArticleId()) { + row.getAttribute("data-article-id") != Article.getActive()) { - Article.setActiveArticleId(row.getAttribute("data-article-id")); + Article.setActive(row.getAttribute("data-article-id")); break; } } @@ -465,7 +465,7 @@ const Headlines = { hsp.innerHTML = " " + __("Loading, please wait...") + ""; - Headlines.loadMoreHeadlines(); + Headlines.loadMore(); return; } } @@ -527,7 +527,7 @@ const Headlines = { ft.setAttribute("data-article-id", id); ft.innerHTML = header.innerHTML; ft.firstChild.innerHTML = "" + ft.firstChild.innerHTML; + "onclick=\"Article.cdmScrollToId(" + id + ", true)\">" + ft.firstChild.innerHTML; this.initFloatingMenu(); @@ -557,7 +557,7 @@ const Headlines = { } } }, - unpackVisibleArticles: function() { + unpackVisible: function() { if (!App.isCombinedMode() || !getInitParam("cdm_expanded")) return; const rows = $$("#headlines-frame div[id*=RROW][data-content]"); @@ -665,7 +665,7 @@ const Headlines = { } else if (headlines_count > 0 && feed_id == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { const c = dijit.byId("headlines-frame"); - //const ids = Headlines.getSelectedArticleIds2(); + //const ids = Headlines.getSelected(); let hsp = $("headlines-spacer"); @@ -740,7 +740,7 @@ const Headlines = { notify(""); }, - reverseHeadlineOrder: function() { + reverse: function() { const toolbar = document.forms["main_toolbar_form"]; const order_by = dijit.getEnclosingWidget(toolbar.order_by); @@ -761,7 +761,7 @@ const Headlines = { const cmode = params.cmode || 2; const callback = params.callback; const no_error = params.no_error || false; - const ids = params.ids || Headlines.getSelectedArticleIds2(); + const ids = params.ids || Headlines.getSelected(); if (ids.length == 0) { if (!no_error) @@ -800,7 +800,7 @@ const Headlines = { }); }, selectionToggleMarked: function(ids) { - const rows = ids || Headlines.getSelectedArticleIds2(); + const rows = ids || Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -821,7 +821,7 @@ const Headlines = { }); }, selectionTogglePublished: function(ids) { - const rows = ids || Headlines.getSelectedArticleIds2(); + const rows = ids || Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -895,28 +895,28 @@ const Headlines = { } }, - moveToPost: function(mode, noscroll, noexpand) { - const rows = Headlines.getLoadedArticleIds(); + move: function(mode, noscroll, noexpand) { + const rows = Headlines.getLoaded(); let prev_id = false; let next_id = false; - if (!$('RROW-' + Article.getActiveArticleId())) { - Article.setActiveArticleId(0); + if (!$('RROW-' + Article.getActive())) { + Article.setActive(0); } - if (!Article.getActiveArticleId()) { + if (!Article.getActive()) { next_id = rows[0]; prev_id = rows[rows.length - 1] } else { for (let i = 0; i < rows.length; i++) { - if (rows[i] == Article.getActiveArticleId()) { + if (rows[i] == Article.getActive()) { // Account for adjacent identical article ids. if (i > 0) prev_id = rows[i - 1]; for (let j = i + 1; j < rows.length; j++) { - if (rows[j] != Article.getActiveArticleId()) { + if (rows[j] != Article.getActive()) { next_id = rows[j]; break; } @@ -926,23 +926,23 @@ const Headlines = { } } - console.log("cur: " + Article.getActiveArticleId() + " next: " + next_id); + console.log("cur: " + Article.getActive() + " next: " + next_id); if (mode == "next") { - if (next_id || Article.getActiveArticleId()) { + if (next_id || Article.getActive()) { if (App.isCombinedMode()) { - const article = $("RROW-" + Article.getActiveArticleId()); + const article = $("RROW-" + Article.getActive()); const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop + article.offsetHeight > ctr.scrollTop + ctr.offsetHeight) { - Article.scrollArticle(ctr.offsetHeight / 4); + Article.scroll(ctr.offsetHeight / 4); } else if (next_id) { - Article.setActiveArticleId(next_id); - Article.cdmScrollToArticleId(next_id, true); + Article.setActive(next_id); + Article.cdmScrollToId(next_id, true); } } else if (next_id) { @@ -953,21 +953,21 @@ const Headlines = { } if (mode == "prev") { - if (prev_id || Article.getActiveArticleId()) { + if (prev_id || Article.getActive()) { if (App.isCombinedMode()) { - const article = $("RROW-" + Article.getActiveArticleId()); + const article = $("RROW-" + Article.getActive()); const prev_article = $("RROW-" + prev_id); const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop < ctr.scrollTop) { - Article.scrollArticle(-ctr.offsetHeight / 3); + Article.scroll(-ctr.offsetHeight / 3); } else if (!noscroll && prev_article && prev_article.offsetTop < ctr.scrollTop) { - Article.scrollArticle(-ctr.offsetHeight / 4); + Article.scroll(-ctr.offsetHeight / 4); } else if (prev_id) { - Article.setActiveArticleId(prev_id); - Article.cdmScrollToArticleId(prev_id, noscroll); + Article.setActive(prev_id); + Article.cdmScrollToId(prev_id, noscroll); } } else if (prev_id) { @@ -978,7 +978,7 @@ const Headlines = { } }, updateSelectedPrompt: function() { - const count = Headlines.getSelectedArticleIds2().length; + const count = Headlines.getSelected().length; const elem = $("selected_prompt"); if (elem) { @@ -1016,7 +1016,7 @@ const Headlines = { } }, selectionRemoveLabel: function(id, ids) { - if (!ids) ids = Headlines.getSelectedArticleIds2(); + if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); @@ -1034,7 +1034,7 @@ const Headlines = { }); }, selectionAssignLabel: function(id, ids) { - if (!ids) ids = Headlines.getSelectedArticleIds2(); + if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); @@ -1052,7 +1052,7 @@ const Headlines = { }); }, deleteSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1082,7 +1082,7 @@ const Headlines = { Feeds.viewCurrentFeed(); }); }, - getSelectedArticleIds2: function() { + getSelected: function() { const rv = []; $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( @@ -1091,12 +1091,12 @@ const Headlines = { }); // consider active article a honorary member of selected articles - if (Article.getActiveArticleId()) - rv.push(Article.getActiveArticleId()); + if (Article.getActive()) + rv.push(Article.getActive()); return rv.uniq(); }, - getLoadedArticleIds: function() { + getLoaded: function() { const rv = []; const children = $$("#headlines-frame > div[id*=RROW-]"); @@ -1164,7 +1164,7 @@ const Headlines = { } }, archiveSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1204,7 +1204,7 @@ const Headlines = { }); }, catchupSelection: function() { - const rows = Headlines.getSelectedArticleIds2(); + const rows = Headlines.getSelected(); if (rows.length == 0) { alert(__("No articles are selected.")); @@ -1224,8 +1224,8 @@ const Headlines = { Headlines.selectionToggleUnread({callback: Feeds.viewCurrentFeed, no_error: 1}); }, - catchupBatchedArticles: function(callback) { - console.log("catchupBatchedArticles, size=", this.catchup_id_batch.length); + catchupBatched: function(callback) { + console.log("catchupBatched, size=", this.catchup_id_batch.length); if (this.catchup_id_batch.length > 0) { @@ -1257,16 +1257,16 @@ const Headlines = { if (callback) callback(); } }, - catchupRelativeToArticle: function(below, id) { + catchupRelativeTo: function(below, id) { - if (!id) id = Article.getActiveArticleId(); + if (!id) id = Article.getActive(); if (!id) { alert(__("No article is selected.")); return; } - const visible_ids = this.getLoadedArticleIds(); + const visible_ids = this.getLoaded(); const ids_to_mark = []; @@ -1372,14 +1372,14 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Open original article"), onClick: function (event) { - Article.openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); + Article.openInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); } })); menu.addChild(new dijit.MenuItem({ label: __("Display article URL"), onClick: function (event) { - Article.displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id")); + Article.displayUrl(this.getParent().currentTarget.getAttribute("data-article-id")); } })); @@ -1389,7 +1389,7 @@ const Headlines = { label: __("Toggle unread"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1401,7 +1401,7 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Toggle starred"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1413,7 +1413,7 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Toggle published"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; @@ -1427,14 +1427,14 @@ const Headlines = { menu.addChild(new dijit.MenuItem({ label: __("Mark above as read"), onClick: function () { - Headlines.catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id")); + Headlines.catchupRelativeTo(0, this.getParent().currentTarget.getAttribute("data-article-id")); } })); menu.addChild(new dijit.MenuItem({ label: __("Mark below as read"), onClick: function () { - Headlines.catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id")); + Headlines.catchupRelativeTo(1, this.getParent().currentTarget.getAttribute("data-article-id")); } })); @@ -1457,7 +1457,7 @@ const Headlines = { labelId: bare_id, onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; @@ -1471,7 +1471,7 @@ const Headlines = { label: name, labelId: bare_id, onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); + let ids = Headlines.getSelected(); // cast to string const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; diff --git a/plugins/close_button/init.php b/plugins/close_button/init.php index 62f8780c4..8678d577c 100644 --- a/plugins/close_button/init.php +++ b/plugins/close_button/init.php @@ -21,7 +21,7 @@ class Close_Button extends Plugin { if (!get_pref("COMBINED_DISPLAY_MODE")) { $rv = ""; } diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 95a5ef9e5..6f797556b 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -11,7 +11,7 @@ function embedOriginalArticle(id) { if (App.isCombinedMode()) { c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; - } else if (id == Article.getActiveArticleId()) { + } else if (id == Article.getActive()) { c = $$(".post .content")[0]; } @@ -23,7 +23,7 @@ function embedOriginalArticle(id) { c.parentNode.removeChild(iframe); if (App.isCombinedMode()) { - Article.cdmScrollToArticleId(id, true); + Article.cdmScrollToId(id, true); } return; @@ -48,7 +48,7 @@ function embedOriginalArticle(id) { c.parentNode.insertBefore(iframe, c); if (App.isCombinedMode()) { - Article.cdmScrollToArticleId(id, true); + Article.cdmScrollToId(id, true); } } } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 1dc383b00..538970fc3 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,7 +1,7 @@ function emailArticle(id) { try { if (!id) { - var ids = Headlines.getSelectedArticleIds2(); + var ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index a3be90e95..6b8520928 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,7 +1,7 @@ function mailtoArticle(id) { try { if (!id) { - const ids = Headlines.getSelectedArticleIds2(); + const ids = Headlines.getSelected(); if (ids.length == 0) { alert(__("No articles are selected.")); -- cgit v1.2.3-54-g00ecf From 0a18d0b1edb208e5811c419a1119d131b7041173 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 08:57:22 +0300 Subject: Feeds: shorten some method names finally rename "view as rss" --- classes/article.php | 2 +- classes/dlg.php | 2 +- classes/feeds.php | 19 ++++--- classes/pref/feeds.php | 2 +- index.php | 8 +-- js/feedlist.js | 122 ++++++++++++++++++++-------------------- js/functions.js | 18 +++--- js/tt-rss.js | 70 +++++++++++------------ js/viewfeed.js | 40 ++++++------- plugins/af_psql_trgm/init.php | 2 +- plugins/toggle_sidebar/init.php | 2 +- 11 files changed, 144 insertions(+), 143 deletions(-) (limited to 'plugins') diff --git a/classes/article.php b/classes/article.php index 20febdf3b..282748ed1 100755 --- a/classes/article.php +++ b/classes/article.php @@ -877,7 +877,7 @@ class Article extends Handler_Protected { $tags_str = ""; for ($i = 0; $i < $maxtags; $i++) { - $tags_str .= "" . $tags[$i] . ", "; + $tags_str .= "" . $tags[$i] . ", "; } $tags_str = mb_substr($tags_str, 0, mb_strlen($tags_str)-2); diff --git a/classes/dlg.php b/classes/dlg.php index 02249ea96..aa695ee18 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -139,7 +139,7 @@ class Dlg extends Handler_Protected { $key_escaped = str_replace("'", "\\'", $key); - echo "' . $key . ' '; } diff --git a/classes/feeds.php b/classes/feeds.php index 647414609..c9e5ca496 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -50,8 +50,8 @@ class Feeds extends Handler_Protected { $reply .= " + title=\"".__("Show as feed")."\" + onclick=\"Utils.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> "; @@ -137,7 +137,8 @@ class Feeds extends Handler_Protected { //$reply .= ""; - $reply .= ""; + $reply .= ""; $reply .= ""; @@ -392,7 +393,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
    ". "
    $feed_icon_img
    ". - "". + "". $line["feed_title"]." $vf_catchup_link
    "; @@ -434,7 +435,7 @@ class Feeds extends Handler_Protected { if (@$line["feed_title"]) { $rgba = @$rgba_cache[$feed_id]; - $reply['content'] .= "". + $reply['content'] .= "". truncate_string($line["feed_title"],30).""; } } @@ -451,7 +452,7 @@ class Feeds extends Handler_Protected { if ($line["feed_title"] && !$vfeed_group_enabled) { - $reply['content'] .= " $feed_icon_img"; @@ -488,7 +489,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
    ". "
    $feed_icon_img
    ". - "". + "". $line["feed_title"]." $vf_catchup_link
    "; } @@ -547,7 +548,7 @@ class Feeds extends Handler_Protected { $tmp_content .= ""; } @@ -561,7 +562,7 @@ class Feeds extends Handler_Protected { if (!get_pref("VFEED_GROUP_BY_FEED") && $line["feed_title"]) { $tmp_content .= "$feed_icon_img"; + onclick=\"Feeds.open({feed:$feed_id})\">$feed_icon_img
    "; } $tmp_content .= "
    "; //score wrapper2 diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 2184a0b42..f47d24501 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected { print "

    "; - print " "; print " -- cgit v1.2.3-54-g00ecf From 35ded4bc844d74f120196012c194be9ab5517688 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:30:32 +0300 Subject: edit phrasing of some alert()s --- js/PrefFeedTree.js | 10 +++++----- js/PrefFilterTree.js | 6 +++--- js/PrefLabelTree.js | 4 ++-- js/functions.js | 4 ++-- js/prefs.js | 8 ++++---- js/viewfeed.js | 18 +++++++++--------- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) (limited to 'plugins') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index dbb188a34..7beeadd38 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -161,7 +161,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } return false; @@ -202,7 +202,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No categories are selected.")); + alert(__("No categories selected.")); } return false; @@ -223,7 +223,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -239,7 +239,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -391,7 +391,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, execute: function () { diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 37a99be89..9a2dd6c1c 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -107,7 +107,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -123,7 +123,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -250,7 +250,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); } return false; diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 45edb34a1..914df9a19 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -134,7 +134,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f } } else { - alert(__("No labels are selected.")); + alert(__("No labels selected.")); } }, removeSelected: function() { @@ -154,7 +154,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }); } } else { - alert(__("No labels are selected.")); + alert(__("No labels selected.")); } return false; diff --git a/js/functions.js b/js/functions.js index 3a9a26f9b..3118da0f0 100755 --- a/js/functions.js +++ b/js/functions.js @@ -589,7 +589,7 @@ const CommonDialogs = { } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, execute: function () { @@ -670,7 +670,7 @@ const CommonDialogs = { }); } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, diff --git a/js/prefs.js b/js/prefs.js index 771120048..3578a7007 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -194,7 +194,7 @@ const Prefs = { } } else { - alert(__("No profiles are selected.")); + alert(__("No profiles selected.")); } }, activateProfile: function () { @@ -337,7 +337,7 @@ const Users = { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } @@ -376,14 +376,14 @@ const Users = { } } else { - alert(__("No users are selected.")); + alert(__("No users selected.")); } }, editSelected: function() { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } diff --git a/js/viewfeed.js b/js/viewfeed.js index e7703ed55..0365feeeb 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -60,7 +60,7 @@ const Article = { } } else { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); } }, setScore: function(id, pic) { @@ -765,7 +765,7 @@ const Headlines = { if (ids.length == 0) { if (!no_error) - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -803,7 +803,7 @@ const Headlines = { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -824,7 +824,7 @@ const Headlines = { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1019,7 +1019,7 @@ const Headlines = { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1037,7 +1037,7 @@ const Headlines = { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1055,7 +1055,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1175,7 +1175,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1215,7 +1215,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 538970fc3..d6c28048b 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -4,7 +4,7 @@ function emailArticle(id) { var ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 6b8520928..47321923a 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -4,7 +4,7 @@ function mailtoArticle(id) { const ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } -- cgit v1.2.3-54-g00ecf From d9c5c93cef313127b9b5010fbe279fdbddedadec Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 20:07:57 +0300 Subject: move some more stuff out of common.js rework client-side cookie functions a bit limit dojo cachebust based on server scripts modification time remove param_escape() --- classes/dlg.php | 10 ++-- classes/pref/feeds.php | 4 +- include/functions.php | 12 +++++ index.php | 2 +- js/Article.js | 2 +- js/CommonDialogs.js | 34 ++++++++++++ js/CommonFilters.js | 4 +- js/Feeds.js | 2 +- js/PrefFilterTree.js | 2 +- js/PrefLabelTree.js | 2 +- js/PrefUsers.js | 2 +- js/Utils.js | 2 +- js/common.js | 126 ++++++++++--------------------------------- js/tt-rss.js | 32 +++++------ plugins/af_psql_trgm/init.js | 2 +- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- plugins/note/note.js | 2 +- plugins/share/share.js | 2 +- prefs.php | 2 +- 20 files changed, 111 insertions(+), 137 deletions(-) (limited to 'plugins') diff --git a/classes/dlg.php b/classes/dlg.php index 7e66c4b5e..32c41ee34 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -52,7 +52,7 @@ class Dlg extends Handler_Protected { print " "; - print ""; print "

    "; @@ -85,7 +85,7 @@ class Dlg extends Handler_Protected { print "
    "; - print ""; print "
    "; @@ -150,7 +150,7 @@ class Dlg extends Handler_Protected { print "
    "; print ""; print "
    "; @@ -179,7 +179,7 @@ class Dlg extends Handler_Protected { print " "; - print ""; print ""; @@ -195,7 +195,7 @@ class Dlg extends Handler_Protected { print " "; print ""; print ""; } diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 3b949073c..7ae7a04c1 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -745,9 +745,9 @@ class Pref_Feeds extends Handler_Protected { - - "; diff --git a/include/functions.php b/include/functions.php index baed6fb20..dcb2e7518 100755 --- a/include/functions.php +++ b/include/functions.php @@ -2566,3 +2566,15 @@ function arr_qmarks($arr) { return str_repeat('?,', count($arr) - 1) . '?'; } + + function get_scripts_timestamp() { + $files = glob("js/*.js"); + $ts = 0; + + foreach ($files as $file) { + $file_ts = filemtime($file); + if ($file_ts > $ts) $ts = $file_ts; + } + + return $ts; + } \ No newline at end of file diff --git a/index.php b/index.php index 4a85ff236..6035ac186 100644 --- a/index.php +++ b/index.php @@ -91,7 +91,7 @@ @@ -139,7 +124,7 @@ function bwLimitChange(elem) {
    - +
    0) { ?> diff --git a/js/AppBase.js b/js/AppBase.js index ce040e8c9..9ab2f507e 100644 --- a/js/AppBase.js +++ b/js/AppBase.js @@ -7,15 +7,15 @@ define(["dojo/_base/declare"], function (declare) { hotkey_prefix: 0, hotkey_prefix_pressed: false, hotkey_prefix_timeout: 0, + constructor: function() { + window.onerror = this.Error.onWindowError; + }, 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) { @@ -176,7 +176,7 @@ define(["dojo/_base/declare"], function (declare) { if (callback) callback(transport); } catch (e) { - exception_error(e); + this.Error.report(e); } }); @@ -355,5 +355,67 @@ define(["dojo/_base/declare"], function (declare) { explainError: function(code) { return this.displayDlg(__("Error explained"), "explainError", code); }, + Error: { + report: function(error, params) { + params = params || {}; + + if (!error) return; + + console.error("[Error.report]", error, params); + + const message = params.message ? params.message : error.toString(); + + try { + xhrPost("backend.php", + {op: "rpc", method: "log", + file: params.filename ? params.filename : error.fileName, + line: params.lineno ? params.lineno : error.lineNumber, + msg: message, + context: error.stack}, + (transport) => { + console.warn("[Error.report] log response", transport.responseText); + }); + } catch (re) { + console.error("[Error.report] exception while saving logging error on server", re); + } + + try { + if (dijit.byId("exceptionDlg")) + dijit.byId("exceptionDlg").destroyRecursive(); + + let content = "

    " + message + "

    "; + + if (error.stack) + content += "
    Stack trace:
    " + + ""; + + content += "
    "; + + content += ""; + content += "
    "; + + const dialog = new dijit.Dialog({ + id: "exceptionDlg", + title: "Unhandled exception", + style: "width: 600px", + content: content + }); + + dialog.show(); + } catch (de) { + console.error("[Error.report] exception while showing error dialog", de); + + alert(error.stack ? error.stack : message); + } + + }, + onWindowError: function (message, filename, lineno, colno, error) { + // called without context (this) from window.onerror + App.Error.report(error, + {message: message, filename: filename, lineno: lineno, colno: colno}); + }, + } }); }); diff --git a/js/Article.js b/js/Article.js index d3ae8eed7..04cba8ab7 100644 --- a/js/Article.js +++ b/js/Article.js @@ -168,7 +168,7 @@ define(["dojo/_base/declare"], function (declare) { Notify.close(); } catch (e) { - exception_error(e); + App.Error.report(e); } }) } @@ -206,7 +206,7 @@ define(["dojo/_base/declare"], function (declare) { if (tooltip) tooltip.attr('label', data.content_full); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); } diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index b9cee8873..81ad2ffce 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -152,7 +152,7 @@ define(["dojo/_base/declare"], function (declare) { } catch (e) { console.error(transport.responseText); - exception_error(e); + App.Error.report(e); } }); } diff --git a/js/CommonFilters.js b/js/CommonFilters.js index d2a3e6317..97a676c98 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -67,7 +67,7 @@ define(["dojo/_base/declare"], function (declare) { parentNode.appendChild(li); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -117,7 +117,7 @@ define(["dojo/_base/declare"], function (declare) { } } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -238,7 +238,7 @@ define(["dojo/_base/declare"], function (declare) { console.log("getTestResults: dialog closed, bailing out."); } } catch (e) { - exception_error(e); + App.Error.report(e); } }); diff --git a/js/FeedTree.js b/js/FeedTree.js index 37e3de2d1..75d1c901b 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -207,7 +207,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], } } } catch (e) { - exception_error(e); + App.Error.report(e); } }, findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) { @@ -242,7 +242,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], this.expandParentNodes(feed, is_cat, parents.slice(0)); } } catch (e) { - exception_error(e); + App.Error.report(e); } }, selectFeed: function(feed, is_cat) { diff --git a/js/Feeds.js b/js/Feeds.js index eb9a468ad..fbcb56150 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -198,13 +198,13 @@ define(["dojo/_base/declare"], function (declare) { Feeds.init(); App.setLoadingProgress(25); } catch (e) { - exception_error(e); + App.Error.report(e); } }); tree.startup(); } catch (e) { - exception_error(e); + App.Error.report(e); } }, init: function() { @@ -380,7 +380,7 @@ define(["dojo/_base/declare"], function (declare) { Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }); diff --git a/js/common.js b/js/common.js index de6d13a78..427e3034c 100755 --- a/js/common.js +++ b/js/common.js @@ -4,6 +4,16 @@ let _label_base_index = -1024; let loading_progress = 0; +/* error reporting shim */ + +// TODO: deprecated; remove +function exception_error(e, e_compat, filename, lineno, colno) { + if (typeof e == "string") + e = e_compat; + + App.Error.report(e, {filename: filename, lineno: lineno, colno: colno}); +} + /* xhr shorthand helpers */ function xhrPost(url, params, complete) { @@ -118,71 +128,6 @@ const Cookie = { } }; -/* error reporting */ - -function report_error(message, filename, lineno, colno, error) { - exception_error(error, null, filename, lineno); -} - -function exception_error(e, e_compat, filename, lineno, colno) { - if (typeof e == "string") e = e_compat; - - if (!e) return; // no exception object, nothing to report. - - try { - console.error(e); - const msg = e.toString(); - - try { - xhrPost("backend.php", - {op: "rpc", method: "log", - file: e.fileName ? e.fileName : filename, - line: e.lineNumber ? e.lineNumber : lineno, - msg: msg, context: e.stack}, - (transport) => { - console.warn(transport.responseText); - }); - - } catch (e) { - console.error("Exception while trying to log the error.", e); - } - - let content = "

    " + msg + "

    "; - - if (e.stack) { - content += "
    Stack trace:
    " + - ""; - } - - content += "
    "; - - content += "
    "; - - content += ""; - content += "
    "; - - if (dijit.byId("exceptionDlg")) - dijit.byId("exceptionDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "exceptionDlg", - title: "Unhandled exception", - style: "width: 600px", - content: content}); - - dialog.show(); - - } catch (ei) { - console.error("Exception while trying to report an exception:", ei); - console.error("Original exception:", e); - - alert("Exception occured while trying to report an exception.\n" + - ei.stack + "\n\nOriginal exception:\n" + e.stack); - } -} - /* runtime notifications */ const Notify = { diff --git a/js/prefs.js b/js/prefs.js index dafdbcdee..c89c0494f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -58,10 +58,6 @@ require(["dojo/_base/kernel", try { const _App = declare("fox.App", AppBase, { constructor: function() { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - parser.parse(); this.setLoadingProgress(50); @@ -73,7 +69,7 @@ require(["dojo/_base/kernel", try { this.backendSanityCallback(transport); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }, @@ -149,7 +145,7 @@ require(["dojo/_base/kernel", App = new _App(); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }); \ No newline at end of file diff --git a/js/tt-rss.js b/js/tt-rss.js index 97d34fbc1..8931e9860 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -65,10 +65,6 @@ require(["dojo/_base/kernel", _widescreen_mode: false, hotkey_actions: {}, constructor: function () { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - parser.parse(); this.setLoadingProgress(30); @@ -91,7 +87,7 @@ require(["dojo/_base/kernel", try { App.backendSanityCallback(transport); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }, @@ -555,7 +551,7 @@ require(["dojo/_base/kernel", App = new _App(); } catch (e) { - exception_error(e); + App.Error.report(e); } }); }); diff --git a/plugins/embed_original/init.js b/plugins/embed_original/init.js index 6f797556b..1e9fcb253 100644 --- a/plugins/embed_original/init.js +++ b/plugins/embed_original/init.js @@ -1,60 +1,56 @@ function embedOriginalArticle(id) { - try { - const hasSandbox = "sandbox" in document.createElement("iframe"); + const hasSandbox = "sandbox" in document.createElement("iframe"); - if (!hasSandbox) { - alert(__("Sorry, your browser does not support sandboxed iframes.")); - return; - } + if (!hasSandbox) { + alert(__("Sorry, your browser does not support sandboxed iframes.")); + return; + } - let c = false; + let c = false; + + if (App.isCombinedMode()) { + c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; + } else if (id == Article.getActive()) { + c = $$(".post .content")[0]; + } + + if (c) { + const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0]; + + if (iframe) { + Element.show(c); + c.parentNode.removeChild(iframe); + + if (App.isCombinedMode()) { + Article.cdmScrollToId(id, true); + } - if (App.isCombinedMode()) { - c = $$("div#RROW-" + id + " div[class=content-inner]")[0]; - } else if (id == Article.getActive()) { - c = $$(".post .content")[0]; + return; } + } - if (c) { - const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0]; + const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id }; - if (iframe) { - Element.show(c); - c.parentNode.removeChild(iframe); + xhrJson("backend.php", query, (reply) => { + if (reply) { + const iframe = new Element("iframe", { + class: "embeddedContent", + src: reply.url, + width: (c.parentNode.offsetWidth - 5) + 'px', + height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px', + style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;", + sandbox: 'allow-scripts', + }); + + if (c) { + Element.hide(c); + c.parentNode.insertBefore(iframe, c); if (App.isCombinedMode()) { Article.cdmScrollToId(id, true); } - - return; } } + }); - const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id }; - - xhrJson("backend.php", query, (reply) => { - if (reply) { - const iframe = new Element("iframe", { - class: "embeddedContent", - src: reply.url, - width: (c.parentNode.offsetWidth - 5) + 'px', - height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px', - style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;", - sandbox: 'allow-scripts', - }); - - if (c) { - Element.hide(c); - c.parentNode.insertBefore(iframe, c); - - if (App.isCombinedMode()) { - Article.cdmScrollToId(id, true); - } - } - } - }); - - } catch (e) { - exception_error("embedOriginalArticle", e); - } } diff --git a/plugins/import_export/import_export.js b/plugins/import_export/import_export.js index 56a2a5c3e..8dc5f7570 100644 --- a/plugins/import_export/import_export.js +++ b/plugins/import_export/import_export.js @@ -50,7 +50,7 @@ function exportData() { "Error occured, could not export data."; } } catch (e) { - exception_error("exportData", e, transport.responseText); + App.Error.report(e); } Notify.close(); @@ -71,7 +71,7 @@ function exportData() { } catch (e) { - exception_error("exportData", e); + App.Error.report(e); } } @@ -100,7 +100,7 @@ function dataImportComplete(iframe) { dialog.show(); } catch (e) { - exception_error("dataImportComplete", e); + App.Error.report(e); } } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index b72289c2a..87e354b42 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,57 +1,52 @@ function emailArticle(id) { - try { - if (!id) { - var ids = Headlines.getSelected(); + if (!id) { + let ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; - } - - id = ids.toString(); + if (ids.length == 0) { + alert(__("No articles selected.")); + return; } - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); - - var query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); - - dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - xhrJson("backend.php", this.attr('value'), (reply) => { - if (reply) { - const error = reply['error']; - - if (error) { - alert(__('Error sending email:') + ' ' + error); - } else { - Notify.info('Your message has been sent.'); - dialog.hide(); - } + id = ids.toString(); + } + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); + + const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); + + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + execute: function() { + if (this.validate()) { + xhrJson("backend.php", this.attr('value'), (reply) => { + if (reply) { + const error = reply['error']; + + if (error) { + alert(__('Error sending email:') + ' ' + error); + } else { + Notify.info('Your message has been sent.'); + dialog.hide(); } - }); - } - }, - href: query}); - /* var tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); + } + }); + } + }, + href: query}); - new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', - "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", - { tokens: '', paramName: "search" }); - }); */ + /* var tmph = dojo.connect(dialog, 'onLoad', function() { + dojo.disconnect(tmph); - dialog.show(); + new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', + "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", + { tokens: '', paramName: "search" }); + }); */ - } catch (e) { - exception_error("emailArticle", e); - } + dialog.show(); } diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index dacff725e..92a90f8e9 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,32 +1,27 @@ function mailtoArticle(id) { - try { - if (!id) { - const ids = Headlines.getSelected(); + if (!id) { + const ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; - } - - id = ids.toString(); + if (ids.length == 0) { + alert(__("No articles selected.")); + return; } - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); + id = ids.toString(); + } - const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); - dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - href: query}); + const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); - dialog.show(); + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + href: query}); - } catch (e) { - exception_error("emailArticle", e); - } + dialog.show(); } diff --git a/plugins/nsfw/init.js b/plugins/nsfw/init.js index 40ad2b0ba..adb6d43c0 100644 --- a/plugins/nsfw/init.js +++ b/plugins/nsfw/init.js @@ -1,12 +1,7 @@ function nsfwShow(elem) { - try { - content = elem.parentNode.getElementsBySelector("div.nswf.content")[0]; + let content = elem.parentNode.getElementsBySelector("div.nswf.content")[0]; - if (content) { - Element.toggle(content); - } - - } catch (e) { - exception_error("nswfSHow", e); + if (content) { + Element.toggle(content); } } diff --git a/plugins/shorten_expanded/init.js b/plugins/shorten_expanded/init.js index d9995e8ac..a5424ea38 100644 --- a/plugins/shorten_expanded/init.js +++ b/plugins/shorten_expanded/init.js @@ -1,29 +1,20 @@ var _shorten_expanded_threshold = 1.5; //window heights function expandSizeWrapper(id) { - try { - const row = $(id); + const row = $(id); - console.log(row); + if (row) { + const content = row.select(".contentSizeWrapper")[0]; + const link = row.select(".expandPrompt")[0]; - if (row) { - const content = row.select(".contentSizeWrapper")[0]; - const link = row.select(".expandPrompt")[0]; - - if (content) content.removeClassName("contentSizeWrapper"); - if (link) Element.hide(link); - - } - } catch (e) { - exception_error("expandSizeWrapper", e); + if (content) content.removeClassName("contentSizeWrapper"); + if (link) Element.hide(link); } return false; - } require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { - ready(function() { PluginHost.register(PluginHost.HOOK_ARTICLE_RENDERED_CDM, function(row) { window.setTimeout(function() { @@ -48,5 +39,4 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) { return true; }); }); - }); diff --git a/register.php b/register.php index 6c76eed5a..1bd1b2544 100644 --- a/register.php +++ b/register.php @@ -135,13 +135,13 @@ f.sub_btn.disabled = true; } } catch (e) { - exception_error("checkUsername_callback", e); + App.Error.report(e); } } }); } catch (e) { - exception_error("checkUsername", e); + App.Error.report(e); } return false; @@ -171,7 +171,7 @@ return true; } catch (e) { - exception_error("validateRegForm", e); + alert(e.stack); return false; } } -- cgit v1.2.3-54-g00ecf From e76d1fb995e25d78f0131ac56660846b0e9ecb9a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 14:21:50 +0300 Subject: plugins: mail, mailto: remove code from global context --- classes/feeds.php | 4 +-- js/tt-rss.js | 8 ++--- plugins/mail/init.php | 2 +- plugins/mail/mail.js | 94 ++++++++++++++++++++++++++----------------------- plugins/mailto/init.js | 45 +++++++++++++---------- plugins/mailto/init.php | 2 +- 6 files changed, 82 insertions(+), 73 deletions(-) (limited to 'plugins') diff --git a/classes/feeds.php b/classes/feeds.php index 58d4f68d9..9fe528723 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -124,12 +124,12 @@ class Feeds extends Handler_Protected { } if (PluginHost::getInstance()->get_plugin("mail")) { - $reply .= ""; } if (PluginHost::getInstance()->get_plugin("mailto")) { - $reply .= ""; } diff --git a/js/tt-rss.js b/js/tt-rss.js index 8931e9860..fc87ae24d 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -302,12 +302,10 @@ require(["dojo/_base/kernel", } }; this.hotkey_actions["email_article"] = function () { - if (typeof emailArticle != "undefined") { - emailArticle(); - } else if (typeof mailtoArticle != "undefined") { - mailtoArticle(); + if (typeof Plugins.Mail != "undefined") { + Plugins.Mail.onHotkey(Headlines.getSelected()); } else { - alert(__("Please enable mail plugin first.")); + alert(__("Please enable mail or mailto plugin first.")); } }; this.hotkey_actions["select_all"] = function () { diff --git a/plugins/mail/init.php b/plugins/mail/init.php index d8f92853e..1609a05c3 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -72,7 +72,7 @@ class Mail extends Plugin { function hook_article_button($line) { return "Zoom"; } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 87e354b42..eb7b7e6b6 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,52 +1,56 @@ -function emailArticle(id) { - if (!id) { - let ids = Headlines.getSelected(); +Plugins.Mail = { + send: function(id) { + if (!id) { + let ids = Headlines.getSelected(); + + if (ids.length == 0) { + alert(__("No articles selected.")); + return; + } - if (ids.length == 0) { - alert(__("No articles selected.")); - return; + id = ids.toString(); } - id = ids.toString(); - } + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); - - const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); - - const dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - xhrJson("backend.php", this.attr('value'), (reply) => { - if (reply) { - const error = reply['error']; - - if (error) { - alert(__('Error sending email:') + ' ' + error); - } else { - Notify.info('Your message has been sent.'); - dialog.hide(); - } - - } - }); - } - }, - href: query}); + const query = "backend.php?op=pluginhandler&plugin=mail&method=emailArticle¶m=" + encodeURIComponent(id); - /* var tmph = dojo.connect(dialog, 'onLoad', function() { - dojo.disconnect(tmph); - - new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', - "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", - { tokens: '', paramName: "search" }); - }); */ - - dialog.show(); -} + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + xhrJson("backend.php", this.attr('value'), (reply) => { + if (reply) { + const error = reply['error']; + if (error) { + alert(__('Error sending email:') + ' ' + error); + } else { + Notify.info('Your message has been sent.'); + dialog.hide(); + } + } + }); + } + }, + href: query + }); + + /* var tmph = dojo.connect(dialog, 'onLoad', function() { + dojo.disconnect(tmph); + + new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', + "backend.php?op=pluginhandler&plugin=mail&method=completeEmails", + { tokens: '', paramName: "search" }); + }); */ + + dialog.show(); + }, + onHotkey: function(id) { + Plugins.Mail.send(id); + } +}; diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 92a90f8e9..f81f70fc7 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,27 +1,34 @@ -function mailtoArticle(id) { - if (!id) { - const ids = Headlines.getSelected(); +Plugins.Mailto = { + send: function (id) { + if (!id) { + const ids = Headlines.getSelected(); - if (ids.length == 0) { - alert(__("No articles selected.")); - return; - } + if (ids.length == 0) { + alert(__("No articles selected.")); + return; + } - id = ids.toString(); - } + id = ids.toString(); + } - if (dijit.byId("emailArticleDlg")) - dijit.byId("emailArticleDlg").destroyRecursive(); + if (dijit.byId("emailArticleDlg")) + dijit.byId("emailArticleDlg").destroyRecursive(); - const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); + const query = "backend.php?op=pluginhandler&plugin=mailto&method=emailArticle¶m=" + encodeURIComponent(id); - const dialog = new dijit.Dialog({ - id: "emailArticleDlg", - title: __("Forward article by email"), - style: "width: 600px", - href: query}); + const dialog = new dijit.Dialog({ + id: "emailArticleDlg", + title: __("Forward article by email"), + style: "width: 600px", + href: query}); - dialog.show(); -} + dialog.show(); + } +}; +// override default hotkey action if enabled +Plugins.Mail = Plugins.Mail || {}; +Plugins.Mail.onHotkey = function(id) { + Plugins.Mailto.send(id); +}; \ No newline at end of file diff --git a/plugins/mailto/init.php b/plugins/mailto/init.php index 60c58b707..3dbc8d643 100644 --- a/plugins/mailto/init.php +++ b/plugins/mailto/init.php @@ -21,7 +21,7 @@ class MailTo extends Plugin { function hook_article_button($line) { return "Zoom"; } -- cgit v1.2.3-54-g00ecf