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() {
?>
-
";
@@ -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
From 71fc6d45bd761a9d2715faa68f2b8c0271ee7169 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov
Date: Mon, 3 Dec 2018 13:38:13 +0300
Subject: refactor error reporting to AppBase; keep exception_error() for now
as a shim
---
plugins/embed_original/init.js | 86 ++++++++++++++++------------------
plugins/import_export/import_export.js | 6 +--
plugins/mail/mail.js | 83 +++++++++++++++-----------------
plugins/mailto/init.js | 37 +++++++--------
plugins/nsfw/init.js | 11 ++---
plugins/shorten_expanded/init.js | 22 +++------
6 files changed, 108 insertions(+), 137 deletions(-)
(limited to 'plugins')
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;
});
});
-
});
--
cgit v1.2.3
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
---
plugins/mail/init.php | 2 +-
plugins/mail/mail.js | 94 ++++++++++++++++++++++++++-----------------------
plugins/mailto/init.js | 45 +++++++++++++----------
plugins/mailto/init.php | 2 +-
4 files changed, 77 insertions(+), 66 deletions(-)
(limited to 'plugins')
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 "";
}
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 "";
}
--
cgit v1.2.3