ttrss/plugins/share/share.js

81 lines
1.8 KiB
JavaScript
Raw Normal View History

Plugins.Share = {
shareArticle: function(id) {
2011-12-21 04:46:39 +00:00
if (dijit.byId("shareArticleDlg"))
dijit.byId("shareArticleDlg").destroyRecursive();
const query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + encodeURIComponent(id);
2011-12-21 04:46:39 +00:00
const dialog = new dijit.Dialog({
2011-12-21 04:46:39 +00:00
id: "shareArticleDlg",
title: __("Share article by URL"),
style: "width: 600px",
newurl: function () {
2018-11-30 10:05:59 +00:00
if (confirm(__("Generate new share URL for this article?"))) {
2018-12-02 17:56:30 +00:00
Notify.progress("Trying to change URL...", true);
const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id};
2018-11-30 12:23:48 +00:00
xhrJson("backend.php", query, (reply) => {
if (reply) {
const new_link = reply.link;
const e = $('gen_article_url');
2018-11-30 12:23:48 +00:00
if (new_link) {
2018-11-30 12:23:48 +00:00
e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
"&key=" + new_link);
2018-11-30 12:23:48 +00:00
e.href = e.href.replace(/\&key=.*$/,
"&key=" + new_link);
2018-11-30 12:23:48 +00:00
new Effect.Highlight(e);
2018-11-30 12:23:48 +00:00
const img = $("SHARE-IMG-" + id);
img.addClassName("shared");
2018-12-02 17:56:30 +00:00
Notify.close();
2018-11-30 12:23:48 +00:00
} else {
2018-12-02 17:56:30 +00:00
Notify.error("Could not change URL.");
2018-11-30 12:23:48 +00:00
}
}
});
}
},
unshare: function () {
2018-11-30 10:05:59 +00:00
if (confirm(__("Remove sharing for this article?"))) {
const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
2018-11-30 12:23:48 +00:00
xhrPost("backend.php", query, () => {
2018-12-09 08:48:29 +00:00
try {
const img = $("SHARE-IMG-" + id);
2018-12-09 08:48:29 +00:00
if (img) {
img.removeClassName("shared");
img.up("div[id*=RROW]").removeClassName("shared");
}
2018-12-09 08:48:29 +00:00
dialog.hide();
} catch (e) {
console.error(e);
}
2018-11-30 12:23:48 +00:00
});
}
},
href: query
});
2011-12-21 04:46:39 +00:00
dialog.show();
2018-11-30 12:23:48 +00:00
const img = $("SHARE-IMG-" + id);
img.addClassName("shared");
2011-12-21 04:46:39 +00:00
}
};
2011-12-21 04:46:39 +00:00