]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
prefs: add loading progressbar
[tt-rss.git] / functions.js
index eb036e3c4e17b8e2885ecbba239a9063fba95ccb..83e24bf09944835818a7013e194f15ae371f0453 100644 (file)
@@ -1,7 +1,7 @@
 var hotkeys_enabled = true;
-var debug_mode_enabled = false;
 var xmlhttp_rpc = Ajax.getTransport();
-var hotkey_zone = 0;
+var notify_silent = false;
+var last_progress_point = 0;
 
 /* add method to remove element from array */
 
@@ -75,10 +75,13 @@ function open_article_callback(transport) {
 
                        debug("open_article_callback, received link: " + link);
 
-                       if (link) {
-                               debug("link url: " + link.firstChild.nodeValue);
+                       if (link && id) {
 
-                               var w = window.open(link.firstChild.nodeValue, "_blank");
+                               var wname = "ttrss_article_" + id.firstChild.nodeValue;
+
+                               debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
+
+                               var w = window.open(link.firstChild.nodeValue, wname);
 
                                if (!w) { notify_error("Failed to load article in new window"); }
 
@@ -132,8 +135,17 @@ function hide_notify() {
        }
 } 
 
+function notify_silent_next() {
+       notify_silent = true;
+}
+
 function notify_real(msg, no_hide, n_type) {
 
+       if (notify_silent) {
+               notify_silent = false;
+               return;
+       }
+
        var n = document.getElementById("notify");
        var nb = document.getElementById("notify_body");
 
@@ -249,6 +261,8 @@ function getVisibleUnreadHeadlines() {
 
        var rows = new Array();
 
+       if (!content) return rows;
+
        for (i = 0; i < content.rows.length; i++) {
                var row_id = content.rows[i].id.replace("RROW-", "");
                if (row_id.length > 0 && content.rows[i].className.match("Unread")) {
@@ -264,6 +278,8 @@ function getVisibleHeadlineIds() {
 
        var rows = new Array();
 
+       if (!content) return rows;
+
        for (i = 0; i < content.rows.length; i++) {
                var row_id = content.rows[i].id.replace("RROW-", "");
                if (row_id.length > 0) {
@@ -1191,7 +1207,7 @@ function infobox_submit_callback2(transport) {
 
        try {
                // called from prefs, reload tab
-               if (active_tab) {
+               if (typeof active_tab != 'undefined' && active_tab) {
                        selectTab(active_tab, false);
                }
        } catch (e) { }
@@ -1237,6 +1253,8 @@ function infobox_callback2(transport) {
                                { tokens: ',', paramName: "search" });
                }
 
+               disableHotkeys();
+
                notify("");
        } catch (e) {
                exception_error("infobox_callback2", e);
@@ -1245,22 +1263,33 @@ function infobox_callback2(transport) {
 
 function createFilter() {
 
-       var form = document.forms['filter_add_form'];
-       var reg_exp = form.reg_exp.value;
-
-       if (reg_exp == "") {
-               alert(__("Can't add filter: nothing to match on."));
-               return false;
-       }
-
-       var query = Form.serialize("filter_add_form");
+       try {
 
-       new Ajax.Request("backend.php?" + query, {
-               onComplete: function (transport) {
-                       infobox_submit_callback2(transport);
-               } });
+               var form = document.forms['filter_add_form'];
+               var reg_exp = form.reg_exp.value;
+       
+               if (reg_exp == "") {
+                       alert(__("Can't add filter: nothing to match on."));
+                       return false;
+               }
+       
+               var query = Form.serialize("filter_add_form");
        
-       return true;
+               // we can be called from some other tab in Prefs                
+               if (typeof active_tab != 'undefined' && active_tab) {
+                       active_tab = "filterConfig";
+               }
+       
+               new Ajax.Request("backend.php?" + query, {
+                       onComplete: function (transport) {
+                               infobox_submit_callback2(transport);
+                       } });
+               
+               return true;
+
+       } catch (e) {
+               exception_error("createFilter", e);
+       }
 }
 
 function toggleSubmitNotEmpty(e, submit_id) {
@@ -1354,7 +1383,7 @@ function debug(msg) {
        }
 
        var c = document.getElementById('debug_output');
-       if (c && c.style.display == "block") {
+       if (c && Element.visible(c)) {
                while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
                        c.removeChild(c.lastChild);
                }
@@ -1452,7 +1481,7 @@ function filterDlgCheckAction(sender) {
                }
 
        } catch (e) {
-               exception_error(e, "filterDlgCheckAction");
+               exception_error("filterDlgCheckAction", e);
        }
 
 }
@@ -1462,9 +1491,11 @@ function explainError(code) {
 }
 
 // this only searches loaded headlines list, not in CDM
-function getRelativePostIds(id) {
+function getRelativePostIds(id, limit) {
+
+       if (!limit) limit = 3;
 
-       debug("getRelativePostIds: " + id);
+       debug("getRelativePostIds: " + id + " limit=" + limit);
 
        var ids = new Array();
        var container = document.getElementById("headlinesList");
@@ -1476,13 +1507,23 @@ function getRelativePostIds(id) {
                        var r_id = rows[i].id.replace("RROW-", "");
 
                        if (r_id == id) {
-                               if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
+/*                             if (i > 0) ids.push(rows[i-1].id.replace("RROW-", ""));
                                if (i > 1) ids.push(rows[i-2].id.replace("RROW-", ""));
                                if (i > 2) ids.push(rows[i-3].id.replace("RROW-", ""));
 
                                if (i < rows.length-1) ids.push(rows[i+1].id.replace("RROW-", ""));
                                if (i < rows.length-2) ids.push(rows[i+2].id.replace("RROW-", ""));
-                               if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", ""));
+                               if (i < rows.length-3) ids.push(rows[i+3].id.replace("RROW-", "")); */
+
+                               for (var k = 1; k <= limit; k++) {
+                                       var nid = false;
+
+                                       if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
+                                       if (nid) ids.push(nid);
+
+                                       if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
+                                       if (nid) ids.push(nid);
+                               }
 
                                return ids;
                        }
@@ -1497,8 +1538,13 @@ function openArticleInNewWindow(id) {
                debug("openArticleInNewWindow: " + id);
 
                var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id;
+               var wname = "ttrss_article_" + id;
+
+               debug(query + " " + wname);
 
-               debug(query);
+               var w = window.open("", wname);
+
+               if (!w) notify_error("Failed to open window for the article");
 
                new Ajax.Request(query, {
                        onComplete: function(transport) { 
@@ -1619,59 +1665,43 @@ function displayHelpInfobox(topic_id) {
        return false;
 }
 
-var _border_color_normal = "#88b0f0";
-var _border_color_highlight = "#72eda8";
-var _border_color_flash = "#f0fff0";
-
-function highlightHotkeyZone(zone) {
+function focus_element(id) {
        try {
-               var feeds = document.getElementById("feeds-holder");
-               var headlines = document.getElementById("headlines-frame");
-               var content = document.getElementById("content-frame");
-
-               feeds.style.borderColor = _border_color_normal;
-               headlines.style.borderColor = _border_color_normal;
-               content.style.borderColor = _border_color_normal;
+               var e = document.getElementById(id);
+               if (e) e.focus();
+       } catch (e) {
+               exception_error("focus_element", e);
+       }
+       return false;
+}
 
-               if (zone == 1) {
-                       feeds.style.borderColor = _border_color_highlight;
+function loading_set_progress(p) {
+       try {
+               if (p < last_progress_point || !Element.visible("overlay")) return;
 
-                       new Effect.Highlight(feeds, {duration: 0.5, startcolor: 
-                               _border_color_flash,
-                               queue: { position:'end', scope: 'EFCHL-Q', limit: 1 } } );
-               }
+               debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
 
-               if (zone == 2) {
-                       headlines.style.borderColor = _border_color_highlight;
+               var o = document.getElementById("l_progress_i");
 
-                       new Effect.Highlight(headlines, {duration: 0.5, startcolor: 
-                               _border_color_flash,
-                               queue: { position:'end', scope: 'EFCHL-Q', limit: 1 } } );
-               }
+//             o.style.width = (p * 2) + "px";
 
-               if (zone == 3 && content) {                     
-                       content.style.borderColor = _border_color_highlight;
+               new Effect.Scale(o, p, { 
+                       scaleY : false,
+                       scaleFrom : last_progress_point,
+                       scaleMode: { originalWidth : 200 },
+                       queue: { position: 'end', scope: 'LSP-Q', limit: 3 } }); 
 
-                       new Effect.Highlight(content, {duration: 0.5, startcolor: 
-                               _border_color_flash,
-                               queue: { position:'end', scope: 'EFCHL-Q', limit: 1 } } );
-               }
+               last_progress_point = p;
 
        } catch (e) {
-               exception_error("highlightHotkeyZone", e);
+               exception_error("loading_set_progress", e);
        }
 }
 
-
-function setHotkeyZone(zone) {
-       try {
-               hotkey_zone = zone;
-
-               highlightHotkeyZone(zone);
-
-
-       } catch (e) {
-               exception_error("setHotkeyZone", e);
+function remove_splash() {
+       if (Element.visible("overlay")) {
+               debug("about to remove splash, OMG!");
+               Element.hide("overlay");
+               debug("removed splash!");
        }
 }
-