]> git.wh0rd.org - tt-rss.git/blob - plugins/embed_original/init.js
minor tweaks to embed_original
[tt-rss.git] / plugins / embed_original / init.js
1 function embedOriginalArticle(id) {
2 try {
3 var hasSandbox = "sandbox" in document.createElement("iframe");
4
5 if (!hasSandbox) {
6 alert(__("Sorry, your browser does not support sandboxed iframes."));
7 return;
8 }
9
10 var query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
11 param_escape(id);
12
13 var c = false;
14
15 if (isCdmMode()) {
16 c = $$("div#RROW-" + id + " div[class=cdmContentInner]")[0];
17 } else if (id == getActiveArticleId()) {
18 c = $$("div[class=postContent]")[0];
19 }
20
21 if (c) {
22 var iframe = c.getElementsByClassName("embeddedContent")[0];
23
24 if (iframe) {
25 Element.show(c.firstChild);
26 c.removeChild(iframe);
27
28 if (isCdmMode()) {
29 cdmScrollToArticleId(id, true);
30 }
31
32 return;
33 }
34 }
35
36 new Ajax.Request("backend.php", {
37 parameters: query,
38 onComplete: function(transport) {
39 var ti = JSON.parse(transport.responseText);
40
41 if (ti) {
42
43 var iframe = new Element("iframe", {
44 class: "embeddedContent",
45 src: ti.url,
46 sandbox: 'allow-scripts',
47 });
48
49 if (c) {
50 Element.hide(c.firstChild);
51
52 if (c.firstChild.nextSibling)
53 c.insertBefore(iframe, c.firstChild.nextSibling);
54 else
55 c.appendChild(iframe);
56
57 if (isCdmMode()) {
58 cdmScrollToArticleId(id, true);
59 }
60 }
61 }
62
63 } });
64
65
66 } catch (e) {
67 exception_error("embedOriginalArticle", e);
68 }
69 }