1
0
mirror of https://tt-rss.org/git/tt-rss.git synced 2024-06-29 12:20:51 +02:00
ttrss/plugins/share/share.js
Andrew Dolgov 3d11c61f32 * OPML import: don't reload everything, just feed tree
* dialogs: use auto-destroying dialog for almost all dialogs instead of destroying them manually
* some general dialog-related cleanup
2021-02-12 15:22:10 +03:00

76 lines
1.7 KiB
JavaScript

/* global 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"),
newurl: function () {
if (confirm(__("Generate new share URL for this article?"))) {
Notify.progress("Trying to change URL...", true);
const query = {op: "pluginhandler", plugin: "share", method: "newkey", id: id};
xhrJson("backend.php", query, (reply) => {
if (reply) {
const new_link = reply.link;
const e = $('gen_article_url');
if (new_link) {
e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
"&key=" + new_link);
e.href = e.href.replace(/\&key=.*$/,
"&key=" + new_link);
new Effect.Highlight(e);
const img = $("SHARE-IMG-" + id);
img.addClassName("shared");
Notify.close();
} else {
Notify.error("Could not change URL.");
}
}
});
}
},
unshare: function () {
if (confirm(__("Remove sharing for this article?"))) {
const query = {op: "pluginhandler", plugin: "share", method: "unshare", id: id};
xhrPost("backend.php", query, () => {
try {
const img = $("SHARE-IMG-" + id);
if (img) {
img.removeClassName("shared");
img.up("div[id*=RROW]").removeClassName("shared");
}
dialog.hide();
} catch (e) {
console.error(e);
}
});
}
},
href: query
});
dialog.show();
const img = $("SHARE-IMG-" + id);
img.addClassName("shared");
}
}