]> git.wh0rd.org - tt-rss.git/blob - plugins/embed_original/init.js
plugins: run eslint const/let fixes
[tt-rss.git] / plugins / embed_original / init.js
1 function embedOriginalArticle(id) {
2 try {
3 const 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 const query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
11 param_escape(id);
12
13 let 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 const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];
23
24 if (iframe) {
25 Element.show(c);
26 c.parentNode.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 const ti = JSON.parse(transport.responseText);
40
41 if (ti) {
42
43 const iframe = new Element("iframe", {
44 class: "embeddedContent",
45 src: ti.url,
46 width: (c.parentNode.offsetWidth-5)+'px',
47 height: (c.parentNode.parentNode.offsetHeight-c.parentNode.firstChild.offsetHeight-5)+'px',
48 style: "overflow: auto; border: none; min-height: "+(document.body.clientHeight/2)+"px;",
49 sandbox: 'allow-scripts',
50 });
51
52 if (c) {
53 Element.hide(c);
54 c.parentNode.insertBefore(iframe,c);
55
56 if (isCdmMode()) {
57 cdmScrollToArticleId(id, true);
58 }
59 }
60 }
61
62 } });
63
64
65 } catch (e) {
66 exception_error("embedOriginalArticle", e);
67 }
68 }