From 78cc470193448048759b3f315ee630e50acb064b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 10:51:14 +0300 Subject: remove some plugin JS code out of global context --- classes/article.php | 4 ++-- js/prefs.js | 2 ++ js/tt-rss.js | 2 ++ plugins/af_psql_trgm/init.js | 12 ++++-------- plugins/af_psql_trgm/init.php | 2 +- plugins/note/init.php | 2 +- plugins/note/note.js | 43 +++++++++++++++++++------------------------ plugins/share/init.php | 4 ++-- plugins/share/share.js | 25 ++++++++++++------------- plugins/share/share_prefs.js | 25 ++++++++++++------------- 10 files changed, 57 insertions(+), 64 deletions(-) diff --git a/classes/article.php b/classes/article.php index 282748ed1..248dcdb9e 100755 --- a/classes/article.php +++ b/classes/article.php @@ -907,8 +907,8 @@ class Article extends Handler_Protected { static function format_article_note($id, $note, $allow_edit = true) { - $str = "
-
". + $str = "
+
". ($allow_edit ? __('(edit note)') : "")."
$note
"; return $str; diff --git a/js/prefs.js b/js/prefs.js index ea5d847a9..edb11bc7d 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -7,6 +7,8 @@ let Filters; let Users; let Prefs; +const Plugins = {}; + require(["dojo/_base/kernel", "dojo/_base/declare", "dojo/ready", diff --git a/js/tt-rss.js b/js/tt-rss.js index 78ef10067..3c6fd88dc 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -10,6 +10,8 @@ let Article; let ArticleCache; let PluginHost; +const Plugins = {}; + require(["dojo/_base/kernel", "dojo/_base/declare", "dojo/ready", diff --git a/plugins/af_psql_trgm/init.js b/plugins/af_psql_trgm/init.js index af2facfc1..af337ca6b 100644 --- a/plugins/af_psql_trgm/init.js +++ b/plugins/af_psql_trgm/init.js @@ -1,6 +1,5 @@ -function showTrgmRelated(id) { - try { - +Plugins.Psql_Trgm = { + showRelated: function (id) { const query = "backend.php?op=pluginhandler&plugin=af_psql_trgm&method=showrelated¶m=" + encodeURIComponent(id); if (dijit.byId("trgmRelatedDlg")) @@ -10,16 +9,13 @@ function showTrgmRelated(id) { id: "trgmRelatedDlg", title: __("Related articles"), style: "width: 600px", - execute: function() { + execute: function () { }, href: query, }); dialog.show(); - - } catch (e) { - exception_error("showTrgmRelated", e); } -} +}; diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 514f5731a..57ad355f9 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -115,7 +115,7 @@ class Af_Psql_Trgm extends Plugin { function hook_article_button($line) { return ""; } diff --git a/plugins/note/init.php b/plugins/note/init.php index 354591b75..ac908a5ba 100644 --- a/plugins/note/init.php +++ b/plugins/note/init.php @@ -24,7 +24,7 @@ class Note extends Plugin { function hook_article_button($line) { return ""; } diff --git a/plugins/note/note.js b/plugins/note/note.js index 836481c40..21c1ae51e 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,46 +1,41 @@ -function editArticleNote(id) { - try { - - var query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); +Plugins.Note = { + edit: function(id) { + const query = "backend.php?op=pluginhandler&plugin=note&method=edit¶m=" + encodeURIComponent(id); if (dijit.byId("editNoteDlg")) dijit.byId("editNoteDlg").destroyRecursive(); - dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "editNoteDlg", title: __("Edit article note"), style: "width: 600px", - execute: function() { + execute: function () { if (this.validate()) { Notify.progress("Saving article note...", true); xhrJson("backend.php", this.attr('value'), (reply) => { - Notify.close(); - dialog.hide(); + Notify.close(); + dialog.hide(); - if (reply) { - ArticleCache.del(id); + if (reply) { + ArticleCache.del(id); - var elem = $("POSTNOTE-" + id); + var elem = $("POSTNOTE-" + id); - if (elem) { - Element.hide(elem); - elem.innerHTML = reply.note; + if (elem) { + Element.hide(elem); + elem.innerHTML = reply.note; - if (reply.raw_length != 0) - new Effect.Appear(elem); - } - } - }); + if (reply.raw_length != 0) + new Effect.Appear(elem); + } + } + }); } }, href: query, }); dialog.show(); - - } catch (e) { - exception_error("editArticleNote", e); } -} - +}; \ No newline at end of file diff --git a/plugins/share/init.php b/plugins/share/init.php index 94571bb1b..6ac08b751 100644 --- a/plugins/share/init.php +++ b/plugins/share/init.php @@ -40,7 +40,7 @@ class Share extends Plugin { print "

" . __("You can disable all articles shared by unique URLs here.") . "

"; - print " "; print "

"; @@ -74,7 +74,7 @@ class Share extends Plugin { return ""; } diff --git a/plugins/share/share.js b/plugins/share/share.js index a22e01715..7366c2aff 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -1,20 +1,20 @@ -function shareArticle(id) { - try { +Plugins.Share = { + shareArticle: function(id) { if (dijit.byId("shareArticleDlg")) dijit.byId("shareArticleDlg").destroyRecursive(); - var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id); + const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle¶m=" + encodeURIComponent(id); - dialog = new dijit.Dialog({ + const dialog = new dijit.Dialog({ id: "shareArticleDlg", title: __("Share article by URL"), style: "width: 600px", - newurl: function() { + newurl: function () { if (confirm(__("Generate new share URL for this article?"))) { Notify.progress("Trying to change URL...", true); - const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id }; + const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id}; xhrJson("backend.php", query, (reply) => { if (reply) { @@ -44,12 +44,12 @@ function shareArticle(id) { } }, - unshare: function() { + unshare: function () { if (confirm(__("Remove sharing for this article?"))) { Notify.progress("Trying to unshare...", true); - const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id }; + const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id}; xhrPost("backend.php", query, () => { notify("Article unshared."); @@ -62,16 +62,15 @@ function shareArticle(id) { } }, - href: query}); + href: query + }); dialog.show(); const img = $("SHARE-IMG-" + id); if (img) img.src = img.src.replace("notshared.png", "share.png"); - - } catch (e) { - exception_error("shareArticle", e); } -} +}; + diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js index 92975f8f4..071a6667c 100644 --- a/plugins/share/share_prefs.js +++ b/plugins/share/share_prefs.js @@ -1,16 +1,15 @@ -function clearArticleAccessKeys() { - if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { - Notify.progress("Clearing URLs..."); - - const query = { op: "pluginhandler", plugin: "share", method: "clearArticleKeys" }; - - xhrPost("backend.php", query, () => { - Notify.info("Shared URLs cleared."); - }); - } - - return false; -} +Plugins.Share = { + clearKeys: function() { + if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { + Notify.progress("Clearing URLs..."); + const query = {op: "pluginhandler", plugin: "share", method: "clearArticleKeys"}; + xhrPost("backend.php", query, () => { + Notify.info("Shared URLs cleared."); + }); + } + return false; + } +}; -- cgit v1.2.3