1
0
mirror of https://tt-rss.org/git/tt-rss.git synced 2024-07-01 12:40:50 +02:00
ttrss/plugins/share/share.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

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