]> git.wh0rd.org - tt-rss.git/blame - plugins/embed_original/init.js
plugins: run eslint const/let fixes
[tt-rss.git] / plugins / embed_original / init.js
CommitLineData
a479f3ef
AD
1function embedOriginalArticle(id) {
2 try {
dbb4cdbe 3 const hasSandbox = "sandbox" in document.createElement("iframe");
a479f3ef
AD
4
5 if (!hasSandbox) {
6 alert(__("Sorry, your browser does not support sandboxed iframes."));
7 return;
8 }
9
dbb4cdbe 10 const query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
a479f3ef
AD
11 param_escape(id);
12
dbb4cdbe 13 let c = false;
a479f3ef
AD
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) {
dbb4cdbe 22 const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];
a479f3ef
AD
23
24 if (iframe) {
44db06b6
SS
25 Element.show(c);
26 c.parentNode.removeChild(iframe);
a479f3ef
AD
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) {
dbb4cdbe 39 const ti = JSON.parse(transport.responseText);
a479f3ef
AD
40
41 if (ti) {
42
dbb4cdbe 43 const iframe = new Element("iframe", {
a479f3ef
AD
44 class: "embeddedContent",
45 src: ti.url,
44db06b6
SS
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;",
3873151b 49 sandbox: 'allow-scripts',
a479f3ef
AD
50 });
51
52 if (c) {
44db06b6
SS
53 Element.hide(c);
54 c.parentNode.insertBefore(iframe,c);
a479f3ef
AD
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}