]> git.wh0rd.org - tt-rss.git/blob - plugins/embed_original/init.js
combined mode (and more) css class name updates
[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 let c = false;
11
12 if (isCdmMode()) {
13 c = $$("div#RROW-" + id + " div[class=content-inner]")[0];
14 } else if (id == getActiveArticleId()) {
15 c = $$("div[class=postContent]")[0];
16 }
17
18 if (c) {
19 const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];
20
21 if (iframe) {
22 Element.show(c);
23 c.parentNode.removeChild(iframe);
24
25 if (isCdmMode()) {
26 cdmScrollToArticleId(id, true);
27 }
28
29 return;
30 }
31 }
32
33 const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id };
34
35 xhrJson("backend.php", query, (reply) => {
36 if (reply) {
37 const iframe = new Element("iframe", {
38 class: "embeddedContent",
39 src: reply.url,
40 width: (c.parentNode.offsetWidth - 5) + 'px',
41 height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px',
42 style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;",
43 sandbox: 'allow-scripts',
44 });
45
46 if (c) {
47 Element.hide(c);
48 c.parentNode.insertBefore(iframe, c);
49
50 if (isCdmMode()) {
51 cdmScrollToArticleId(id, true);
52 }
53 }
54 }
55 });
56
57 } catch (e) {
58 exception_error("embedOriginalArticle", e);
59 }
60 }