summaryrefslogtreecommitdiff
path: root/plugins/share
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-11-30 15:23:48 +0300
committerAndrew Dolgov <[email protected]>2018-11-30 15:23:48 +0300
commit2f961ee830af21166d22bf3fae104291f614e7dd (patch)
tree1bc280bf9d8f480b70200fcf6dcc1d9406874bd2 /plugins/share
parent764434a491ee0b42b70d262fa49aee2b6a9e93a8 (diff)
plugins: add some xhrPost refactoring
Diffstat (limited to 'plugins/share')
-rw-r--r--plugins/share/share.js59
-rw-r--r--plugins/share/share_prefs.js10
2 files changed, 31 insertions, 38 deletions
diff --git a/plugins/share/share.js b/plugins/share/share.js
index 0fb2f1244..11748d8fe 100644
--- a/plugins/share/share.js
+++ b/plugins/share/share.js
@@ -14,36 +14,33 @@ function shareArticle(id) {
notify_progress("Trying to change URL...", true);
- var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
+ const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };
- new Ajax.Request("backend.php", {
- parameters: query,
- onComplete: function(transport) {
- var reply = JSON.parse(transport.responseText);
- var new_link = reply.link;
+ xhrJson("backend.php", query, (reply) => {
+ if (reply) {
+ const new_link = reply.link;
+ const e = $('gen_article_url');
- var e = $('gen_article_url');
+ if (new_link) {
- if (new_link) {
+ e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
+ "&amp;key=" + new_link);
- e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
- "&amp;key=" + new_link);
+ e.href = e.href.replace(/\&key=.*$/,
+ "&key=" + new_link);
- e.href = e.href.replace(/\&key=.*$/,
- "&key=" + new_link);
+ new Effect.Highlight(e);
- new Effect.Highlight(e);
+ const img = $("SHARE-IMG-" + id);
+ if (img) img.src = img.src.replace("notshared.png", "share.png");
- var img = $("SHARE-IMG-" + id);
- if (img) img.src = img.src.replace("notshared.png", "share.png");
-
- notify('');
-
- } else {
- notify_error("Could not change URL.");
- }
- } });
+ notify('');
+ } else {
+ notify_error("Could not change URL.");
+ }
+ }
+ });
}
},
@@ -52,18 +49,16 @@ function shareArticle(id) {
notify_progress("Trying to unshare...", true);
- var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
+ const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };
- new Ajax.Request("backend.php", {
- parameters: query,
- onComplete: function(transport) {
- notify("Article unshared.");
+ xhrPost("backend.php", query, () => {
+ notify("Article unshared.");
- var img = $("SHARE-IMG-" + id);
- if (img) img.src = img.src.replace("share.png", "notshared.png");
+ var img = $("SHARE-IMG-" + id);
+ if (img) img.src = img.src.replace("share.png", "notshared.png");
- dialog.hide();
- } });
+ dialog.hide();
+ });
}
},
@@ -71,7 +66,7 @@ function shareArticle(id) {
dialog.show();
- var img = $("SHARE-IMG-" + id);
+ const img = $("SHARE-IMG-" + id);
if (img) img.src = img.src.replace("notshared.png", "share.png");
} catch (e) {
diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js
index e4c22262a..79ca37284 100644
--- a/plugins/share/share_prefs.js
+++ b/plugins/share/share_prefs.js
@@ -2,13 +2,11 @@ function clearArticleAccessKeys() {
if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) {
notify_progress("Clearing URLs...");
- var query = "?op=pluginhandler&plugin=share&method=clearArticleKeys";
+ const query = { op: "pluginhandler", plugin: "share", method: "clearArticleKeys" };
- new Ajax.Request("backend.php", {
- parameters: query,
- onComplete: function(transport) {
- notify_info("Shared URLs cleared.");
- } });
+ xhrPost("backend.php", query, () => {
+ notify_info("Shared URLs cleared.");
+ });
}
return false;