summaryrefslogtreecommitdiff
path: root/plugins/share/share.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-17 08:52:39 +0300
committerAndrew Dolgov <[email protected]>2021-02-17 08:52:39 +0300
commit7adcada324dc6960cf4a120b1397c1bd60521d9b (patch)
treec12f6a0aec54689ac18840dc6c533697e0818f95 /plugins/share/share.js
parent0fc783e2b350b8ac6ff275fd9b201674cbcf2c16 (diff)
share plugin: cleanup, fix icon not highlighting properly
Diffstat (limited to 'plugins/share/share.js')
-rw-r--r--plugins/share/share.js58
1 files changed, 31 insertions, 27 deletions
diff --git a/plugins/share/share.js b/plugins/share/share.js
index 3fc42d654..09fb145c9 100644
--- a/plugins/share/share.js
+++ b/plugins/share/share.js
@@ -1,9 +1,7 @@
-/* global Plugins, xhrJson, Notify, fox, xhrPost, __ */
+/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */
Plugins.Share = {
shareArticle: function(id) {
- const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + encodeURIComponent(id);
-
const dialog = new fox.SingleUseDialog({
id: "shareArticleDlg",
title: __("Share article by URL"),
@@ -17,20 +15,23 @@ Plugins.Share = {
xhrJson("backend.php", query, (reply) => {
if (reply) {
const new_link = reply.link;
- const e = $('gen_article_url');
+ const target = dialog.domNode.querySelector(".target-url");
- if (new_link) {
+ if (new_link && target) {
- e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
+ target.innerHTML = target.innerHTML.replace(/&amp;key=.*$/,
"&amp;key=" + new_link);
- e.href = e.href.replace(/\&key=.*$/,
+ target.href = target.href.replace(/&key=.*$/,
"&key=" + new_link);
- new Effect.Highlight(e);
+ // eslint-disable-next-line no-new
+ new Effect.Highlight(target);
+
+ const icon = document.querySelector(".share-icon-" + id);
- const img = $("SHARE-IMG-" + id);
- img.addClassName("shared");
+ if (icon)
+ icon.addClassName("is-shared");
Notify.close();
@@ -44,32 +45,35 @@ Plugins.Share = {
},
unshare: function () {
if (confirm(__("Remove sharing for this article?"))) {
+ xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "unshare", id: id}, (transport) => {
+ Notify.info(transport.responseText);
- const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
-
- xhrPost("backend.php", query, () => {
- try {
- const img = $("SHARE-IMG-" + id);
+ const icon = document.querySelector(".share-icon-" + id);
- if (img) {
- img.removeClassName("shared");
- img.up("div[id*=RROW]").removeClassName("shared");
- }
+ if (icon)
+ icon.removeClassName("is-shared");
- dialog.hide();
- } catch (e) {
- console.error(e);
- }
+ dialog.hide();
});
}
},
- href: query
+ content: __("Loading, please wait...")
});
- dialog.show();
+ const tmph = dojo.connect(dialog, 'onShow', function () {
+ dojo.disconnect(tmph);
- const img = $("SHARE-IMG-" + id);
- img.addClassName("shared");
+ xhrPost("backend.php", {op: "pluginhandler", plugin: "share", method: "shareDialog", id: id}, (transport) => {
+ dialog.attr('content', transport.responseText)
+
+ const icon = document.querySelector(".share-icon-" + id);
+
+ if (icon)
+ icon.addClassName("is-shared");
+ });
+ });
+
+ dialog.show();
}
}