]> git.wh0rd.org Git - tt-rss.git/commitdiff
plugins: add some xhrPost refactoring
authorAndrew Dolgov <noreply@fakecake.org>
Fri, 30 Nov 2018 12:23:48 +0000 (15:23 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Fri, 30 Nov 2018 12:23:48 +0000 (15:23 +0300)
js/viewfeed.js
plugins/embed_original/init.js
plugins/mail/mail.js
plugins/share/share.js
plugins/share/share_prefs.js

index 23e057587aeae9b7437aa22b38d9e623f6176916..966d0d68883db5a9b86bb480ee94bbc870e4fc18 100755 (executable)
@@ -1690,31 +1690,6 @@ function setSelectionScore() {
        }
 }
 
-/*
-function updateScore(id) {
-       const pic = $$("#RROW-" + id + " .hlScorePic")[0];
-
-       if (pic) {
-
-               const query = "op=article&method=getScore&id=" + param_escape(id);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function (transport) {
-                               console.log(transport.responseText);
-
-                               const reply = JSON.parse(transport.responseText);
-
-                               if (reply) {
-                                       pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
-                                       pic.setAttribute("score", reply["score"]);
-                                       pic.setAttribute("title", reply["score"]);
-                               }
-                       }
-               });
-       }
-} */
-
 function changeScore(id, pic) {
        const score = pic.getAttribute("score");
 
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);
index db0503ff95774173256400e0885d549939c3b80d..929b352433fc7fb5c1b6ec49a79b6b810316548c 100644 (file)
@@ -22,15 +22,9 @@ function emailArticle(id) {
                        style: "width: 600px",
                        execute: function() {
                                if (this.validate()) {
-
-                                       new Ajax.Request("backend.php", {
-                                               parameters: dojo.objectToQuery(this.attr('value')),
-                                               onComplete: function(transport) {
-                                                       console.log(transport.responseText);
-
-                                                       var reply = JSON.parse(transport.responseText);
-
-                                                       var error = reply['error'];
+                                       xhrJson("backend.php", this.attr('value'), (reply) => {
+                                               if (reply) {
+                                                       const error = reply['error'];
 
                                                        if (error) {
                                                                alert(__('Error sending email:') + ' ' + error);
@@ -39,7 +33,8 @@ function emailArticle(id) {
                                                                dialog.hide();
                                                        }
 
-                                       } });
+                                               }
+                                       });
                                }
                        },
                        href: query});
index 0fb2f1244e2ea8eb69a4e637b3030d202fa34df2..11748d8fe73e0dfb26d35017b7f8ea74c6dc076e 100644 (file)
@@ -14,36 +14,33 @@ function shareArticle(id) {
 
                                        notify_progress("Trying to change URL...", true);
 
-                                       var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
+                                       const query = { op: "pluginhandler", plugin: "share", method: "newkey", id: id };
 
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function(transport) {
-                                                               var reply = JSON.parse(transport.responseText);
-                                                               var new_link = reply.link;
+                                       xhrJson("backend.php", query, (reply) => {
+                                               if (reply) {
+                                                       const new_link = reply.link;
+                                                       const e = $('gen_article_url');
 
-                                                               var e = $('gen_article_url');
+                                                       if (new_link) {
 
-                                                               if (new_link) {
+                                                               e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
+                                                                       "&amp;key=" + new_link);
 
-                                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/,
-                                                                               "&amp;key=" + new_link);
+                                                               e.href = e.href.replace(/\&key=.*$/,
+                                                                       "&key=" + new_link);
 
-                                                                       e.href = e.href.replace(/\&key=.*$/,
-                                                                               "&key=" + new_link);
+                                                               new Effect.Highlight(e);
 
-                                                                       new Effect.Highlight(e);
+                                                               const img = $("SHARE-IMG-" + id);
+                                                               if (img) img.src = img.src.replace("notshared.png", "share.png");
 
-                                                                       var img = $("SHARE-IMG-" + id);
-                                                                       if (img) img.src = img.src.replace("notshared.png", "share.png");
-
-                                                                       notify('');
-
-                                                               } else {
-                                                                       notify_error("Could not change URL.");
-                                                               }
-                                               } });
+                                                               notify('');
 
+                                                       } else {
+                                                               notify_error("Could not change URL.");
+                                                       }
+                                               }
+                                       });
                                }
 
                        },
@@ -52,18 +49,16 @@ function shareArticle(id) {
 
                                        notify_progress("Trying to unshare...", true);
 
-                                       var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
+                                       const query = { op: "pluginhandler", plugin: "share", method: "unshare", id: id };
 
-                                       new Ajax.Request("backend.php", {
-                                               parameters: query,
-                                               onComplete: function(transport) {
-                                                       notify("Article unshared.");
+                                       xhrPost("backend.php", query, () => {
+                                               notify("Article unshared.");
 
-                                                       var img = $("SHARE-IMG-" + id);
-                                                       if (img) img.src = img.src.replace("share.png", "notshared.png");
+                                               var img = $("SHARE-IMG-" + id);
+                                               if (img) img.src = img.src.replace("share.png", "notshared.png");
 
-                                                       dialog.hide();
-                                               } });
+                                               dialog.hide();
+                                       });
                                }
 
                        },
@@ -71,7 +66,7 @@ function shareArticle(id) {
 
                dialog.show();
 
-               var img = $("SHARE-IMG-" + id);
+               const img = $("SHARE-IMG-" + id);
                if (img) img.src = img.src.replace("notshared.png", "share.png");
 
        } catch (e) {
index e4c22262a53b0915713e056007a386422fe36712..79ca37284f805543b37864718b096df7572e641b 100644 (file)
@@ -2,13 +2,11 @@ function clearArticleAccessKeys() {
        if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) {
                notify_progress("Clearing URLs...");
 
-               var query = "?op=pluginhandler&plugin=share&method=clearArticleKeys";
+               const query = { op: "pluginhandler", plugin: "share", method: "clearArticleKeys" };
 
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                               notify_info("Shared URLs cleared.");
-                       } });
+               xhrPost("backend.php", query, () => {
+                       notify_info("Shared URLs cleared.");
+               });
        }
 
        return false;