]> 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 865491142ea31b4515bf2a3c2cae633eb1412b55..6bc13ddfa88dd9575024092626804df6677983c8 100644 (file)
@@ -7,9 +7,6 @@ function embedOriginalArticle(id) {
                        return;
                }
 
-               const query = "op=pluginhandler&plugin=embed_original&method=getUrl&id=" +
-                       param_escape(id);
-
                let c = false;
 
                if (isCdmMode()) {
@@ -33,34 +30,29 @@ function embedOriginalArticle(id) {
                        }
                }
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               const ti = JSON.parse(transport.responseText);
-
-                               if (ti) {
-
-                                       const iframe = new Element("iframe", {
-                                               class: "embeddedContent",
-                                               src: ti.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);
-                                               }
+               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);