]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
part of #276: if the html page has only one single feed, we subscribe to that one...
[tt-rss.git] / functions.js
index c0ba5b349294222005d266608af2326cbef5dca0..af18f8383629e52ab694af6fffc5e12f7b567255 100644 (file)
@@ -15,9 +15,9 @@ Array.prototype.remove = function(s) {
 /* create console.log if it doesn't exist */
 
 if (!window.console) console = {};
-console.log = console.log || function(msg) { debug(msg); };
-console.warn = console.warn || function(msg) { debug(msg); };
-console.error = console.error || function(msg) { debug(msg); };
+console.log = console.log || function(msg) { };
+console.warn = console.warn || function(msg) { };
+console.error = console.error || function(msg) { };
 
 function exception_error(location, e, ext_info) {
        var msg = format_exception_error(location, e);
@@ -388,7 +388,7 @@ function parse_counters(reply, scheduled_call) {
                for (var l = 0; l < elems.length; l++) {
 
                        var id = elems[l].id
-                       var is_cat = elems[l].cat;
+                       var kind = elems[l].kind;
                        var ctr = parseInt(elems[l].counter)
                        var error = elems[l].error;
                        var has_img = elems[l].has_img;
@@ -412,7 +412,7 @@ function parse_counters(reply, scheduled_call) {
                                continue;
                        }
        
-                       if (is_cat) {
+                       if (kind && kind == "cat") {
                                var catctr = $("FCATCTR-" + id);
                                if (catctr) {
                                        catctr.innerHTML = "(" + ctr + ")";
@@ -460,7 +460,7 @@ function parse_counters(reply, scheduled_call) {
 
                        if (has_img && feed_img) {
                                if (!feed_img.src.match(id + ".ico")) {
-                                       feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
+                                       feed_img.src = getInitParam("icons_url") + "/" + id + ".ico";
                                }
                        }
 
@@ -581,12 +581,9 @@ function parse_counters_reply(transport, scheduled_call) {
 function all_counters_callback2(transport, async_call) {
        try {
                if (async_call) async_counters_work = true;
-               
                if (offline_mode) return;
 
-               console.log("<b>all_counters_callback2 IN: " + transport + "</b>");
                parse_counters_reply(transport);
-               console.log("<b>all_counters_callback2 OUT: " + transport + "</b>");
 
        } catch (e) {
                exception_error("all_counters_callback2", e, transport);
@@ -1322,6 +1319,7 @@ function subscribeToFeed() {
                                }
                                break;
                        case 2:
+                       case 3:
                                alert(__("Can't subscribe to the specified URL."));
                                break;
                        case 0:
@@ -1359,28 +1357,6 @@ function filterCR(e, f)
        }
 }
 
-var debug_last_class = "even";
-
-function debug(msg) {
-
-       if (debug_last_class == "even") {
-               debug_last_class = "odd";
-       } else {
-               debug_last_class = "even";
-       }
-
-       var c = $('debug_output');
-       if (c && Element.visible(c)) {
-               while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
-                       c.removeChild(c.lastChild);
-               }
-       
-               var ts = make_timestamp();
-               c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + 
-                       msg + "</li>" + c.innerHTML;
-       }
-}
-
 function getInitParam(key) {
        return init_params[key];
 }
@@ -1658,36 +1634,6 @@ function openArticleInNewWindow(id) {
        }
 }
 
-/* http://textsnippets.com/posts/show/835 */
-
-Position.GetWindowSize = function(w) {
-        w = w ? w : window;
-        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
-        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
-        return [width, height]
-}
-
-/* http://textsnippets.com/posts/show/836 */
-
-Position.Center = function(element, parent) {
-        var w, h, pw, ph;
-        var d = Element.getDimensions(element);
-        w = d.width;
-        h = d.height;
-        Position.prepare();
-        if (!parent) {
-                var ws = Position.GetWindowSize();
-                pw = ws[0];
-                ph = ws[1];
-        } else {
-                pw = parent.offsetWidth;
-                ph = parent.offsetHeight;
-        }
-        element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
-        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
-}
-
-
 function isCdmMode() {
        return !$("headlinesList");
 }
@@ -1723,21 +1669,11 @@ function displayHelpInfobox(topic_id) {
 
 }
 
-function focus_element(id) {
-       try {
-               var e = $(id);
-               if (e) e.focus();
-       } catch (e) {
-               exception_error("focus_element", e);
-       }
-       return false;
-}
-
 function loading_set_progress(p) {
        try {
                if (p < last_progress_point || !Element.visible("overlay")) return;
 
-               console.log("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
+               console.log("loading_set_progress : " + p + " (" + last_progress_point + ")");
 
                var o = $("l_progress_i");
 
@@ -1892,7 +1828,7 @@ function displayNewContentPrompt(id) {
 
                $('auxDlg').innerHTML = msg;
 
-               Element.show('auxDlg');
+               new Effect.Appear('auxDlg', {duration : 0.5});
 
        } catch (e) {
                exception_error("displayNewContentPrompt", e);
@@ -2167,21 +2103,24 @@ function backend_sanity_check_callback(transport) {
 
                if (params) {
                        console.log('reading init-params...');
-                       var param = params.firstChild;
-
-                       while (param) {
-                               var k = param.getAttribute("key");
-                               var v = param.getAttribute("value");
-                               console.log(k + " => " + v);
-                               init_params[k] = v;                                     
-
-                               if (db) {
-                                       db.execute("DELETE FROM init_params WHERE key = ?", [k]);
-                                       db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
-                                               [k, v]);
-                               }
 
-                               param = param.nextSibling;
+                       params = JSON.parse(params.firstChild.nodeValue);
+
+                       if (params) {
+                               for (var i = 0; i < params.length; i++) {
+       
+                                       var k = params[i].param;
+                                       var v = params[i].value;
+       
+                                       if (getURLParam('debug')) console.log(k + " => " + v);
+                                       init_params[k] = v;                                     
+       
+                                       if (db) {
+                                               db.execute("DELETE FROM init_params WHERE key = ?", [k]);
+                                               db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
+                                                       [k, v]);
+                                       }
+                               }
                        }
                }
 
@@ -2194,4 +2133,102 @@ function backend_sanity_check_callback(transport) {
        } 
 }
 
+function has_local_storage() {
+       try {
+               return 'localStorage' in window && window['localStorage'] != null;
+       } catch (e) {
+               return false;
+       }
+}
+
+function catSelectOnChange(elem) {
+       try {
+               var value = elem[elem.selectedIndex].value;
+               var def = elem.getAttribute('default');
+
+               if (value == "ADD_CAT") {
+
+                       if (def)
+                               dropboxSelect(elem, def);
+                       else
+                               elem.selectedIndex = 0;
+
+                       quickAddCat(elem);
+               }
+
+       } catch (e) {
+               exception_error("catSelectOnChange", e);
+       }
+}
+
+function quickAddCat(select) {
+       try {
+               var cat = prompt(__("Please enter category title:"));
+
+               if (cat) {
+
+                       var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function (transport) {
+                                       var response = transport.responseXML;
+
+                                       var payload = response.getElementsByTagName("payload")[0];
+
+                                       if (payload)
+                                               select.innerHTML = payload.firstChild.nodeValue;
+
+                       } });
+
+               }
+
+       } catch (e) {
+               exception_error("quickAddCat", e);
+       }
+}
+
+function genUrlChangeKey(feed, is_cat) {
+
+       try {
+               var ok = confirm(__("Generate new syndication address for this feed?"));
+       
+               if (ok) {
+       
+                       notify_progress("Trying to change address...", true);
+       
+                       var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + 
+                               "&is_cat=" + param_escape(is_cat);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                               var new_link = transport.responseXML.getElementsByTagName("link")[0];
+       
+                                               var e = $('gen_feed_url');
+       
+                                               if (new_link) {
+                                                       
+                                                       new_link = new_link.firstChild.nodeValue;
+
+                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/, 
+                                                               "&amp;key=" + new_link);
+
+                                                       e.href = e.href.replace(/\&amp;key=.*$/,
+                                                               "&amp;key=" + new_link);
+
+                                                       new Effect.Highlight(e);
+
+                                                       notify('');
+       
+                                               } else {
+                                                       notify_error("Could not change feed URL.");
+                                               }
+                               } });
+               }
+       } catch (e) {
+               exception_error("genUrlChangeKey", e);
+       }
+       return false;
+}