]> git.wh0rd.org - tt-rss.git/blob - plugins/share/share.js
Merge pull request #1 from gothfox/master
[tt-rss.git] / plugins / share / share.js
1 function shareArticle(id) {
2 try {
3 if (dijit.byId("shareArticleDlg"))
4 dijit.byId("shareArticleDlg").destroyRecursive();
5
6 var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + param_escape(id);
7
8 dialog = new dijit.Dialog({
9 id: "shareArticleDlg",
10 title: __("Share article by URL"),
11 style: "width: 600px",
12 newurl: function() {
13
14 var ok = confirm(__("Generate new share URL for this article?"));
15
16 if (ok) {
17
18 notify_progress("Trying to change URL...", true);
19
20 var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
21
22 new Ajax.Request("backend.php", {
23 parameters: query,
24 onComplete: function(transport) {
25 var reply = JSON.parse(transport.responseText);
26 var new_link = reply.link;
27
28 var e = $('gen_article_url');
29
30 if (new_link) {
31
32 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
33 "&key=" + new_link);
34
35 e.href = e.href.replace(/\&key=.*$/,
36 "&key=" + new_link);
37
38 new Effect.Highlight(e);
39
40 var img = $("SHARE-IMG-" + id);
41 if (img) img.src = img.src.replace("notshared.png", "share.png");
42
43 notify('');
44
45 } else {
46 notify_error("Could not change URL.");
47 }
48 } });
49
50 }
51
52 },
53 unshare: function() {
54
55 var ok = confirm(__("Remove sharing for this article?"));
56
57 if (ok) {
58
59 notify_progress("Trying to unshare...", true);
60
61 var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
62
63 new Ajax.Request("backend.php", {
64 parameters: query,
65 onComplete: function(transport) {
66 notify("Article unshared.");
67
68 var img = $("SHARE-IMG-" + id);
69 if (img) img.src = img.src.replace("share.png", "notshared.png");
70
71 dialog.hide();
72 } });
73 }
74
75 },
76 href: query});
77
78 dialog.show();
79
80 var img = $("SHARE-IMG-" + id);
81 if (img) img.src = img.src.replace("notshared.png", "share.png");
82
83 } catch (e) {
84 exception_error("shareArticle", e);
85 }
86 }
87
88