plugins: mail, mailto: remove code from global context

This commit is contained in:
Andrew Dolgov 2018-12-03 14:21:50 +03:00
parent 71fc6d45bd
commit e76d1fb995
6 changed files with 80 additions and 71 deletions

View File

@ -124,12 +124,12 @@ class Feeds extends Handler_Protected {
} }
if (PluginHost::getInstance()->get_plugin("mail")) { if (PluginHost::getInstance()->get_plugin("mail")) {
$reply .= "<option value=\"emailArticle(false)\">".__('Forward by email'). $reply .= "<option value=\"Plugins.Mail.send()\">".__('Forward by email').
"</option>"; "</option>";
} }
if (PluginHost::getInstance()->get_plugin("mailto")) { if (PluginHost::getInstance()->get_plugin("mailto")) {
$reply .= "<option value=\"mailtoArticle(false)\">".__('Forward by email'). $reply .= "<option value=\"Plugins.Mailto.send()\">".__('Forward by email').
"</option>"; "</option>";
} }

View File

@ -302,12 +302,10 @@ require(["dojo/_base/kernel",
} }
}; };
this.hotkey_actions["email_article"] = function () { this.hotkey_actions["email_article"] = function () {
if (typeof emailArticle != "undefined") { if (typeof Plugins.Mail != "undefined") {
emailArticle(); Plugins.Mail.onHotkey(Headlines.getSelected());
} else if (typeof mailtoArticle != "undefined") {
mailtoArticle();
} else { } else {
alert(__("Please enable mail plugin first.")); alert(__("Please enable mail or mailto plugin first."));
} }
}; };
this.hotkey_actions["select_all"] = function () { this.hotkey_actions["select_all"] = function () {

View File

@ -72,7 +72,7 @@ class Mail extends Plugin {
function hook_article_button($line) { function hook_article_button($line) {
return "<img src=\"plugins/mail/mail.png\" return "<img src=\"plugins/mail/mail.png\"
class='tagsPic' style=\"cursor : pointer\" class='tagsPic' style=\"cursor : pointer\"
onclick=\"emailArticle(".$line["id"].")\" onclick=\"Plugins.Mail.send(".$line["id"].")\"
alt='Zoom' title='".__('Forward by email')."'>"; alt='Zoom' title='".__('Forward by email')."'>";
} }

View File

@ -1,4 +1,5 @@
function emailArticle(id) { Plugins.Mail = {
send: function(id) {
if (!id) { if (!id) {
let ids = Headlines.getSelected(); let ids = Headlines.getSelected();
@ -19,7 +20,7 @@ function emailArticle(id) {
id: "emailArticleDlg", id: "emailArticleDlg",
title: __("Forward article by email"), title: __("Forward article by email"),
style: "width: 600px", style: "width: 600px",
execute: function() { execute: function () {
if (this.validate()) { if (this.validate()) {
xhrJson("backend.php", this.attr('value'), (reply) => { xhrJson("backend.php", this.attr('value'), (reply) => {
if (reply) { if (reply) {
@ -36,7 +37,8 @@ function emailArticle(id) {
}); });
} }
}, },
href: query}); href: query
});
/* var tmph = dojo.connect(dialog, 'onLoad', function() { /* var tmph = dojo.connect(dialog, 'onLoad', function() {
dojo.disconnect(tmph); dojo.disconnect(tmph);
@ -47,6 +49,8 @@ function emailArticle(id) {
}); */ }); */
dialog.show(); dialog.show();
} },
onHotkey: function(id) {
Plugins.Mail.send(id);
}
};

View File

@ -1,4 +1,5 @@
function mailtoArticle(id) { Plugins.Mailto = {
send: function (id) {
if (!id) { if (!id) {
const ids = Headlines.getSelected(); const ids = Headlines.getSelected();
@ -22,6 +23,12 @@ function mailtoArticle(id) {
href: query}); 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);
};

View File

@ -21,7 +21,7 @@ class MailTo extends Plugin {
function hook_article_button($line) { function hook_article_button($line) {
return "<img src=\"plugins/mailto/mail.png\" return "<img src=\"plugins/mailto/mail.png\"
class='tagsPic' style=\"cursor : pointer\" class='tagsPic' style=\"cursor : pointer\"
onclick=\"mailtoArticle(".$line["id"].")\" onclick=\"Plugins.Mailto.send(".$line["id"].")\"
alt='Zoom' title='".__('Forward by email')."'>"; alt='Zoom' title='".__('Forward by email')."'>";
} }