ttrss/plugins/embed_original/init.js

69 lines
1.5 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
const query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
2013-03-21 12:36:48 +00:00
param_escape(id);
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=cdmContentInner]")[0];
} else if (id == getActiveArticleId()) {
c = $$("div[class=postContent]")[0];
}
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;
}
}
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
2018-11-30 05:39:45 +00:00
const ti = JSON.parse(transport.responseText);
2013-03-21 12:36:48 +00:00
if (ti) {
2018-11-30 05:39:45 +00:00
const iframe = new Element("iframe", {
2013-03-21 12:36:48 +00:00
class: "embeddedContent",
src: ti.url,
2013-04-05 07:28:32 +00:00
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;",
2013-03-21 12:39:57 +00:00
sandbox: 'allow-scripts',
2013-03-21 12:36:48 +00:00
});
if (c) {
2013-04-05 07:28:32 +00:00
Element.hide(c);
c.parentNode.insertBefore(iframe,c);
2013-03-21 12:36:48 +00:00
if (isCdmMode()) {
cdmScrollToArticleId(id, true);
}
}
}
} });
} catch (e) {
exception_error("embedOriginalArticle", e);
}
}