]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/embed_original/init.js
plugins: add some xhrPost refactoring
[tt-rss.git] / plugins / embed_original / init.js
index 517f2cd54a3c0c39346ebe16bcd42785a566aaa5..6bc13ddfa88dd9575024092626804df6677983c8 100644 (file)
@@ -1,16 +1,13 @@
 function embedOriginalArticle(id) {
        try {
-               var hasSandbox = "sandbox" in document.createElement("iframe");
+               const hasSandbox = "sandbox" in document.createElement("iframe");
 
                if (!hasSandbox) {
                        alert(__("Sorry, your browser does not support sandboxed iframes."));
                        return;
                }
 
-               var query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
-                       param_escape(id);
-
-               var c = false;
+               let c = false;
 
                if (isCdmMode()) {
                        c = $$("div#RROW-" + id + " div[class=cdmContentInner]")[0];
@@ -19,11 +16,11 @@ function embedOriginalArticle(id) {
                }
 
                if (c) {
-                       var iframe = c.getElementsByClassName("embeddedContent")[0];
+                       const iframe = c.parentNode.getElementsByClassName("embeddedContent")[0];
 
                        if (iframe) {
-                               Element.show(c.firstChild);
-                               c.removeChild(iframe);
+                               Element.show(c);
+                               c.parentNode.removeChild(iframe);
 
                                if (isCdmMode()) {
                                        cdmScrollToArticleId(id, true);
@@ -33,35 +30,29 @@ function embedOriginalArticle(id) {
                        }
                }
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               var ti = JSON.parse(transport.responseText);
-
-                               if (ti) {
-
-                                       var iframe = new Element("iframe", {
-                                               class: "embeddedContent",
-                                               src: ti.url,
-                                               sandbox: 'allow-scripts',
-                                       });
-
-                                       if (c) {
-                                               Element.hide(c.firstChild);
-
-                                               if (c.firstChild.nextSibling)
-                                                       c.insertBefore(iframe, c.firstChild.nextSibling);
-                                               else
-                                                       c.appendChild(iframe);
-
-                                               if (isCdmMode()) {
-                                                       cdmScrollToArticleId(id, true);
-                                               }
+               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);
                                        }
                                }
-
-                       } });
-
+                       }
+               });
 
        } catch (e) {
                exception_error("embedOriginalArticle", e);