]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
loading progress bar for main window
[tt-rss.git] / functions.js
index d8f7a235c8eee12700c9634a62943bb5ecc7a74b..c37a7812c60e87c284ca09911370be31b0335e76 100644 (file)
@@ -1,6 +1,7 @@
 var hotkeys_enabled = true;
 var debug_mode_enabled = false;
 var xmlhttp_rpc = Ajax.getTransport();
+var notify_silent = false;
 
 /* add method to remove element from array */
 
@@ -68,11 +69,21 @@ function open_article_callback(transport) {
        try {
 
                if (transport.responseXML) {
+                       
                        var link = transport.responseXML.getElementsByTagName("link")[0];
                        var id = transport.responseXML.getElementsByTagName("id")[0];
 
-                       if (link) {
-                               window.open(link.firstChild.nodeValue, "_blank");
+                       debug("open_article_callback, received link: " + link);
+
+                       if (link && id) {
+
+                               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"); }
 
                                if (id) {
                                        id = id.firstChild.nodeValue;
@@ -80,7 +91,11 @@ function open_article_callback(transport) {
                                                window.setTimeout("toggleUnread(" + id + ", 0)", 100);
                                        }
                                }
+                       } else {
+                               notify_error("Can't open article: received invalid article link");
                        }
+               } else {
+                       notify_error("Can't open article: received invalid XML");
                }
 
        } catch (e) {
@@ -120,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");
 
@@ -196,153 +220,6 @@ function printLockingError() {
        notify_info("Please wait until operation finishes.");
 }
 
-function hotkey_handler(e) {
-
-       try {
-
-               var keycode;
-               var shift_key = false;
-
-               try {
-                       shift_key = e.shiftKey;
-               } catch (e) {
-
-               }
-       
-               if (!hotkeys_enabled) return;
-       
-               if (window.event) {
-                       keycode = window.event.keyCode;
-               } else if (e) {
-                       keycode = e.which;
-               }
-
-               if (keycode == 82) { // r
-                       return scheduleFeedUpdate(true);
-               }
-
-               if (keycode == 83) { // s
-                       return displayDlg("search", getActiveFeedId());
-               }
-
-               if (keycode == 85) { // u
-                       if (getActiveFeedId()) {
-                               return viewfeed(getActiveFeedId(), "ForceUpdate");
-                       }
-               }
-       
-               if (keycode == 65) { // a
-                       return toggleDispRead();
-               }
-       
-               var feedlist = document.getElementById('feedList');
-       
-               if (keycode == 74) { // j
-                       var feed = getActiveFeedId();
-                       var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
-                       if (new_feed) viewfeed(new_feed, '');
-               }
-       
-               if (keycode == 75) { // k
-                       var feed = getActiveFeedId();
-                       var new_feed = getRelativeFeedId(feedlist, feed, 'next');
-                       if (new_feed) viewfeed(new_feed, '');
-               }
-
-               if (keycode == 78 || keycode == 40) { // n, down
-                       if (typeof moveToPost != 'undefined') {
-                               return moveToPost('next');
-                       }
-               }
-       
-               if (keycode == 80 || keycode == 38) { // p, up
-                       if (typeof moveToPost != 'undefined') {
-                               return moveToPost('prev');
-                       }
-               }
-               
-               if (keycode == 68 && shift_key) { // d
-                       if (!debug_mode_enabled) {
-                               document.getElementById('debug_output').style.display = 'block';
-                               debug('debug mode activated');
-                       } else {
-                               document.getElementById('debug_output').style.display = 'none';
-                       }
-
-                       debug_mode_enabled = !debug_mode_enabled;
-               }
-
-               if (keycode == 190 && shift_key) { // >
-                       viewFeedGoPage(1);
-               }
-               
-               if (keycode == 188 && shift_key) { // <
-                       viewFeedGoPage(-1);
-               }
-
-               if (keycode == 191 && shift_key) { // ?
-                       viewFeedGoPage(0);
-               }
-
-               if (keycode == 69 && shift_key) { // e
-                       return editFeedDlg(getActiveFeedId());
-               }
-
-               if (keycode == 70 && shift_key) { // f
-                       if (getActiveFeedId()) {
-                               return catchupCurrentFeed();
-                       }
-               }
-
-               if (keycode == 80 && shift_key) { // p 
-                       if (getActiveFeedId()) {
-                               return catchupPage();
-                       }
-               }
-
-               if (keycode == 86) { // v
-                       if (getActiveArticleId()) {
-                               openArticleInNewWindow(getActiveArticleId());
-                       }
-               }
-
-               if (keycode == 84) { // t
-
-                       var id = getActiveArticleId();
-
-                       if (id) {                               
-
-                               var cb = document.getElementById("RCHK-" + id);
-
-                               if (cb) {
-                                       cb.checked = !cb.checked;
-                                       toggleSelectRowById(cb, "RROW-" + id);
-                               }
-                       }
-               }
-
-               if (keycode == 67) { // c
-                       var id = getActiveArticleId();
-
-                       if (id) {                               
-                               toggleUnread(id, 0);
-                       }
-               }
-
-               if (typeof localHotkeyHandler != 'undefined') {
-                       try {
-                               return localHotkeyHandler(e);
-                       } catch (e) {
-                               exception_error("hotkey_handler, local:", e);
-                       }
-               }
-
-               debug("KP=" + keycode);
-       } catch (e) {
-               exception_error("hotkey_handler", e);
-       }
-}
-
 function cleanSelectedList(element) {
        var content = document.getElementById(element);
 
@@ -409,13 +286,23 @@ function getVisibleHeadlineIds() {
 }
 
 function getFirstVisibleHeadlineId() {
-       var rows = getVisibleHeadlineIds();
-       return rows[0];
+       if (isCdmMode()) {
+               var rows = cdmGetVisibleArticles();
+               return rows[0];
+       } else {
+               var rows = getVisibleHeadlineIds();
+               return rows[0];
+       }
 }
 
 function getLastVisibleHeadlineId() {
-       var rows = getVisibleHeadlineIds();
-       return rows[rows.length-1];
+       if (isCdmMode()) {
+               var rows = cdmGetVisibleArticles();
+               return rows[rows.length-1];
+       } else {
+               var rows = getVisibleHeadlineIds();
+               return rows[rows.length-1];
+       }
 }
 
 function markHeadline(id) {
@@ -778,6 +665,15 @@ function all_counters_callback2(transport) {
        }
 }
 
+function get_feed_unread(id) {
+       try {
+               return parseInt(document.getElementById("FEEDU-" + id).innerHTML);      
+       } catch (e) {
+               exception_error("get_feed_unread", e, true);
+               return -1;
+       }
+}
+
 function get_feed_entry_unread(doc, elem) {
 
        var id = elem.id.replace("FEEDR-", "");
@@ -919,6 +815,8 @@ function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
                return;
        }
 
+//     debug("cat: " + node.id);
+
        if (node.hasChildNodes() && node.firstChild.nextSibling != false) {  
                for (i = 0; i < node.childNodes.length; i++) {
                        if (node.childNodes[i].nodeName != "LI") { continue; }
@@ -927,14 +825,18 @@ function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
 
                                var has_unread = (node.childNodes[i].className != "feed" &&
                                        node.childNodes[i].className != "label" && 
-                                       node.childNodes[i].className != "virt" && 
+                                       !(!getInitParam("hide_read_shows_special") && 
+                                               node.childNodes[i].className == "virt") && 
+                                       node.childNodes[i].className != "error" && 
                                        node.childNodes[i].className != "tag");
        
-       //                      debug(node.childNodes[i].id + " --> " + has_unread);
+//                             debug(node.childNodes[i].id + " --> " + has_unread);
        
                                if (hide && !has_unread) {
                                        //node.childNodes[i].style.display = "none";
-                                       Effect.Fade(node.childNodes[i], {duration : 0.3});
+                                       var id = node.childNodes[i].id;
+                                       Effect.Fade(node.childNodes[i], {duration : 0.3, 
+                                               queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
                                }
        
                                if (!hide) {
@@ -952,6 +854,8 @@ function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
                }
        }       
 
+//     debug("end cat: " + node.id + " unread " + cat_unread);
+
        if (cat_unread == 0) {
                if (cat_node.style == undefined) {
                        debug("ERROR: supplied cat_node " + cat_node + 
@@ -960,7 +864,8 @@ function hideOrShowFeedsCategory(doc, node, hide, cat_node) {
                }
                if (hide) {
                        //cat_node.style.display = "none";
-                       Effect.Fade(cat_node, {duration : 0.3});
+                       Effect.Fade(cat_node, {duration : 0.3, 
+                               queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
                } else {
                        cat_node.style.display = "list-item";
                }
@@ -1014,38 +919,40 @@ function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
        }
 
        for (i = 0; i < content.rows.length; i++) {
-               if (!classcheck || content.rows[i].className.match(classcheck)) {
+               if (Element.visible(content.rows[i])) {
+                       if (!classcheck || content.rows[i].className.match(classcheck)) {
+               
+                               if (content.rows[i].id.match(prefix)) {
+                                       selectTableRow(content.rows[i], do_select);
+                               
+                                       var row_id = content.rows[i].id.replace(prefix, "");
+                                       var check = document.getElementById(check_prefix + row_id);
+       
+                                       if (check) {
+                                               check.checked = do_select;
+                                       }
+                               } else if (reset_others) {
+                                       selectTableRow(content.rows[i], false);
+       
+                                       var row_id = content.rows[i].id.replace(prefix, "");
+                                       var check = document.getElementById(check_prefix + row_id);
+       
+                                       if (check) {
+                                               check.checked = false;
+                                       }
        
-                       if (content.rows[i].id.match(prefix)) {
-                               selectTableRow(content.rows[i], do_select);
-                       
-                               var row_id = content.rows[i].id.replace(prefix, "");
-                               var check = document.getElementById(check_prefix + row_id);
-
-                               if (check) {
-                                       check.checked = do_select;
                                }
                        } else if (reset_others) {
                                selectTableRow(content.rows[i], false);
-
+       
                                var row_id = content.rows[i].id.replace(prefix, "");
                                var check = document.getElementById(check_prefix + row_id);
-
+       
                                if (check) {
                                        check.checked = false;
                                }
-
-                       }
-               } else if (reset_others) {
-                       selectTableRow(content.rows[i], false);
-
-                       var row_id = content.rows[i].id.replace(prefix, "");
-                       var check = document.getElementById(check_prefix + row_id);
-
-                       if (check) {
-                               check.checked = false;
+       
                        }
-
                }
        }
 }
@@ -1195,7 +1102,9 @@ function checkboxToggleElement(elem, id) {
 function appearBlockElement(id, h_id) {
 
        try {
-               Effect.Fade(h_id);
+               if (h_id) {
+                       Effect.Fade(h_id);
+               }
                Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
        } catch (e) {
                exception_error("appearBlockElement", e);
@@ -1203,7 +1112,6 @@ function appearBlockElement(id, h_id) {
 
 }
 
-
 function hideParentElement(e) {
        e.parentNode.style.display = "none";
 }
@@ -1295,7 +1203,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) { }
@@ -1341,6 +1249,8 @@ function infobox_callback2(transport) {
                                { tokens: ',', paramName: "search" });
                }
 
+               disableHotkeys();
+
                notify("");
        } catch (e) {
                exception_error("infobox_callback2", e);
@@ -1349,22 +1259,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");
+       
+               // we can be called from some other tab in Prefs                
+               if (typeof active_tab != 'undefined' && active_tab) {
+                       active_tab = "filterConfig";
+               }
        
-       return true;
+               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) {
@@ -1549,14 +1470,14 @@ function filterDlgCheckAction(sender) {
                }
 
                // if selected action supports parameters, enable params field
-               if (action == 4) {
+               if (action == 4 || action == 6) {
                        action_param.disabled = false;
                } else {
                        action_param.disabled = true;
                }
 
        } catch (e) {
-               exception_error(e, "filterDlgCheckAction");
+               exception_error("filterDlgCheckAction", e);
        }
 
 }
@@ -1566,9 +1487,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");
@@ -1580,13 +1503,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;
                        }
@@ -1601,8 +1534,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);
+
+               var w = window.open("", wname);
 
-               debug(query);
+               if (!w) notify_error("Failed to open window for the article");
 
                new Ajax.Request(query, {
                        onComplete: function(transport) { 
@@ -1687,3 +1625,58 @@ function labelTest() {
        }
 }
 
+function isCdmMode() {
+       return !document.getElementById("headlinesList");
+}
+
+function getSelectedArticleIds2() {
+       var rows = new Array();
+       var cdm_mode = isCdmMode();
+
+       if (cdm_mode) {
+               rows = cdmGetSelectedArticles();
+       } else {        
+               rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
+       }
+
+       var ids = new Array();
+
+       for (var i = 0; i < rows.length; i++) {
+               var chk = document.getElementById("RCHK-" + rows[i]);
+               if (chk && chk.checked) {
+                       ids.push(rows[i]);
+               }
+       }
+
+       return ids;
+}
+
+function displayHelpInfobox(topic_id) {
+
+       var url = "backend.php?op=help&tid=" + param_escape(topic_id);
+
+       var w = window.open(url, "ttrss_help", 
+               "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
+
+       return false;
+}
+
+function focus_element(id) {
+       try {
+               var e = document.getElementById(id);
+               if (e) e.focus();
+       } catch (e) {
+               exception_error("focus_element", e);
+       }
+       return false;
+}
+
+function loading_set_progress(v) {
+       try {
+               var o = document.getElementById("l_progress_i");
+               o.style.width = (v*2) + "px";
+
+       } catch (e) {
+               exception_error("loading_set_progress", e);
+       }
+}