ttrss/plugins/embed_original/init.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2013-03-21 12:36:48 +00:00
function embedOriginalArticle(id) {
try {
2018-11-30 05:39:45 +00:00
const hasSandbox = "sandbox" in document.createElement("iframe");
2013-03-21 12:36:48 +00:00
if (!hasSandbox) {
alert(__("Sorry, your browser does not support sandboxed iframes."));
return;
}
2018-11-30 05:39:45 +00:00
let c = false;
2013-03-21 12:36:48 +00:00
if (isCdmMode()) {
c = $$("div#RROW-" + id + " div[class=content-inner]")[0];
2013-03-21 12:36:48 +00:00
} else if (id == getActiveArticleId()) {
c = $$(".post .content")[0];
2013-03-21 12:36:48 +00:00
}
if (c) {
2018-11-30 05:39:45 +00:00
const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];
2013-03-21 12:36:48 +00:00
if (iframe) {
2013-04-05 07:28:32 +00:00
Element.show(c);
c.parentNode.removeChild(iframe);
2013-03-21 12:36:48 +00:00
if (isCdmMode()) {
cdmScrollToArticleId(id, true);
}
return;
}
}
2018-11-30 12:23:48 +00:00
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 (isCdmMode()) {
cdmScrollToArticleId(id, true);
2013-03-21 12:36:48 +00:00
}
}
2018-11-30 12:23:48 +00:00
}
});
2013-03-21 12:36:48 +00:00
} catch (e) {
exception_error("embedOriginalArticle", e);
}
}