]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
pref-feeds tweaks
[tt-rss.git] / functions.js
index 5414e2bb878c0b551aa9bca9a97c77165eab8902..2857072b7854dd902dc191d595e79d642016bcc0 100644 (file)
@@ -209,7 +209,10 @@ function hotkey_handler(e) {
 
                }
        
-               if (!hotkeys_enabled) return;
+               if (!hotkeys_enabled) {
+                       debug("hotkeys disabled");
+                       return;
+               }
        
                if (window.event) {
                        keycode = window.event.keyCode;
@@ -329,6 +332,12 @@ function hotkey_handler(e) {
                        }
                }
 
+               if (keycode == 67 && shift_key) { // c
+                       if (typeof collapse_feedlist != 'undefined') {
+                               return collapse_feedlist();
+                       }
+               }
+
                if (typeof localHotkeyHandler != 'undefined') {
                        try {
                                return localHotkeyHandler(e);
@@ -718,14 +727,14 @@ function parse_counters(reply, scheduled_call) {
        }
 }
 
-function parse_counters_reply(xmlhttp, scheduled_call) {
+function parse_counters_reply(transport, scheduled_call) {
 
-       if (!xmlhttp.responseXML) {
+       if (!transport.responseXML) {
                notify_error("Backend did not return valid XML", true);
                return;
        }
 
-       var reply = xmlhttp.responseXML.firstChild;
+       var reply = transport.responseXML.firstChild;
        
        if (!reply) {
                notify_error("Backend did not return expected XML object", true);
@@ -778,6 +787,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 +937,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 +947,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 +976,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 +986,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";
                }
@@ -1195,7 +1222,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 +1232,6 @@ function appearBlockElement(id, h_id) {
 
 }
 
-
 function hideParentElement(e) {
        e.parentNode.style.display = "none";
 }
@@ -1275,39 +1303,34 @@ function closeInfoBox(cleanup) {
 
 function displayDlg(id, param) {
 
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
-
        notify_progress("Loading, please wait...", true);
 
-       xmlhttp.open("GET", "backend.php?op=dlg&id=" +
-               param_escape(id) + "&param=" + param_escape(param), true);
-       xmlhttp.onreadystatechange=infobox_callback;
-       xmlhttp.send(null);
-
        disableHotkeys();
 
+       var query = "backend.php?op=dlg&id=" +
+               param_escape(id) + "&param=" + param_escape(param);
+
+       new Ajax.Request(query, {
+               onComplete: function (transport) {
+                       infobox_callback2(transport);
+               } });
+
        return false;
 }
 
-function infobox_submit_callback() {
-       if (xmlhttp.readyState == 4) {
-               closeInfoBox();
-
-               try {
-                       // called from prefs, reload tab
-                       if (active_tab) {
-                               selectTab(active_tab, false);
-                       }
-               } catch (e) { }
+function infobox_submit_callback2(transport) {
+       closeInfoBox();
 
-               if (xmlhttp.responseText) {
-                       notify_info(xmlhttp.responseText);
+       try {
+               // called from prefs, reload tab
+               if (active_tab) {
+                       selectTab(active_tab, false);
                }
+       } catch (e) { }
 
-       } 
+       if (transport.responseText) {
+               notify_info(transport.responseText);
+       }
 }
 
 function infobox_callback2(transport) {
@@ -1352,18 +1375,7 @@ function infobox_callback2(transport) {
        }
 }
 
-function infobox_callback() {
-       if (xmlhttp.readyState == 4) {
-               infobox_callback2(xmlhttp);
-       }
-}
-
-function addFilter() {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
+function createFilter() {
 
        var form = document.forms['filter_add_form'];
        var reg_exp = form.reg_exp.value;
@@ -1375,10 +1387,11 @@ function addFilter() {
 
        var query = Form.serialize("filter_add_form");
 
-       xmlhttp.open("GET", "backend.php?" + query, true);
-       xmlhttp.onreadystatechange=infobox_submit_callback;
-       xmlhttp.send(null);
-
+       new Ajax.Request("backend.php?" + query, {
+               onComplete: function (transport) {
+                       infobox_submit_callback2(transport);
+               } });
+       
        return true;
 }
 
@@ -1394,12 +1407,7 @@ function isValidURL(s) {
        return s.match("http://") != null || s.match("https://") != null || s.match("feed://") != null;
 }
 
-function qaddFeed() {
-
-       if (!xmlhttp_ready(xmlhttp)) {
-               printLockingError();
-               return
-       }
+function subscribeToFeed() {
 
        var form = document.forms['feed_add_form'];
        var feed_url = form.feed_url.value;
@@ -1421,14 +1429,11 @@ function qaddFeed() {
        
        debug("subscribe q: " + query);
 
-/*     xmlhttp.open("GET", "backend.php?" + query, true);
-       xmlhttp.onreadystatechange=dlg_frefresh_callback;
-       xmlhttp.send(null); */
-
-       xmlhttp.open("POST", "backend.php", true);
-       xmlhttp.onreadystatechange=dlg_frefresh_callback;
-       xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
-       xmlhttp.send(query);
+       new Ajax.Request("backend.php", {
+               parameters: query,
+               onComplete: function(transport) { 
+                       dlg_frefresh_callback(transport); 
+               } });
 
        return false;
 }
@@ -1516,7 +1521,7 @@ function fatalError(code, message) {
        
                        if (message == "") message = "Unknown error";
 
-                       fc.innerHTML = "<img src='images/sign_excl.png'> " + message + " (Code " + code + ")";
+                       fc.innerHTML = "<img src='images/sign_excl.gif'> " + message + " (Code " + code + ")";
        
                        fe.style.display = "block";
                }
@@ -1667,35 +1672,126 @@ Position.Center = function(element, parent) {
         element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
 }
 
-function labeltest_callback() {
-       var container = document.getElementById('label_test_result');
-       if (xmlhttp.readyState == 4) {
 
-               container.innerHTML=xmlhttp.responseText;
+function labeltest_callback(transport) {
+       try {
+               var container = document.getElementById('label_test_result');
+       
+               container.innerHTML = transport.responseText;
                if (!Element.visible(container)) {
                        Effect.SlideDown(container, { duration : 0.5 });
                }
+
                notify("");
+       } catch (e) {
+               exception_error("labeltest_callback", e);
        }
 }
 
 function labelTest() {
 
-       var container = document.getElementById('label_test_result');
+       try {
+               var container = document.getElementById('label_test_result');
+       
+               var form = document.forms['label_edit_form'];
+       
+               var sql_exp = form.sql_exp.value;
+               var description = form.description.value;
+       
+               notify_progress("Loading, please wait...");
+       
+               var query = "backend.php?op=pref-labels&subop=test&expr=" +
+                       param_escape(sql_exp) + "&descr=" + param_escape(description);
+       
+               new Ajax.Request(query, {
+                       onComplete: function (transport) {
+                               labeltest_callback(transport);
+                       } });
+       
+               return false;
+
+       } catch (e) {
+               exception_error("labelTest", e);
+       }
+}
+
+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();
 
-       var form = document.forms['label_edit_form'];
+       for (var i = 0; i < rows.length; i++) {
+               var chk = document.getElementById("RCHK-" + rows[i]);
+               if (chk && chk.checked) {
+                       ids.push(rows[i]);
+               }
+       }
 
-       var sql_exp = form.sql_exp.value;
-       var description = form.description.value;
+       return ids;
+}
 
-       notify_progress("Loading, please wait...");
+function displayHelpInfobox(topic_id) {
 
-       xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
-               param_escape(sql_exp) + "&descr=" + param_escape(description), true);
+       var url = "backend.php?op=help&tid=" + param_escape(topic_id);
 
-       xmlhttp.onreadystatechange=labeltest_callback;
-       xmlhttp.send(null);
+       var w = window.open(url, "ttrss_help", 
+               "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
 
        return false;
 }
 
+// http://www.dynamic-tools.net/toolbox/copyToClipboard/
+
+/*
+function copyToClipboard(s)
+{
+       if( window.clipboardData && clipboardData.setData )
+       {
+               clipboardData.setData("Text", s);
+       }
+       else
+       {
+               // You have to sign the code to enable this or allow the action in about:config by changing
+               user_pref("signed.applets.codebase_principal_support", true);
+               netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+               var clip Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
+               if (!clip) return;
+
+               // create a transferable
+               var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
+               if (!trans) return;
+
+               // specify the data we wish to handle. Plaintext in this case.
+               trans.addDataFlavor('text/unicode');
+
+               // To get the data from the transferable we need two new objects
+               var str = new Object();
+               var len = new Object();
+
+               var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
+
+               var copytext=meintext;
+
+               str.data=copytext;
+
+               trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);
+
+               var clipid=Components.interfaces.nsIClipboard;
+
+               if (!clip) return false;
+
+               clip.setData(trans,null,clipid.kGlobalClipboard);          
+       }
+} */