summaryrefslogtreecommitdiff
path: root/plugins/embed_original/init.js
blob: 1e9fcb2533051d93b3a8352f9840f4f78b94a7b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function embedOriginalArticle(id) {
	const hasSandbox = "sandbox" in document.createElement("iframe");

	if (!hasSandbox) {
		alert(__("Sorry, your browser does not support sandboxed iframes."));
		return;
	}

	let c = false;

	if (App.isCombinedMode()) {
		c = $$("div#RROW-" + id + " div[class=content-inner]")[0];
	} else if (id == Article.getActive()) {
		c = $$(".post .content")[0];
	}

	if (c) {
		const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];

		if (iframe) {
			Element.show(c);
			c.parentNode.removeChild(iframe);

			if (App.isCombinedMode()) {
				Article.cdmScrollToId(id, true);
			}

			return;
		}
	}

	const query = { op: "pluginhandler", plugin: "embed_original", method: "getUrl", id: id };

	xhrJson("backend.php", query, (reply) => {
		if (reply) {
			const iframe = new Element("iframe", {
				class: "embeddedContent",
				src: reply.url,
				width: (c.parentNode.offsetWidth - 5) + 'px',
				height: (c.parentNode.parentNode.offsetHeight - c.parentNode.firstChild.offsetHeight - 5) + 'px',
				style: "overflow: auto; border: none; min-height: " + (document.body.clientHeight / 2) + "px;",
				sandbox: 'allow-scripts',
			});

			if (c) {
				Element.hide(c);
				c.parentNode.insertBefore(iframe, c);

				if (App.isCombinedMode()) {
					Article.cdmScrollToId(id, true);
				}
			}
		}
	});

}