]> git.wh0rd.org - tt-rss.git/blobdiff - tt-rss.js
refactor combined mode, code cleanup
[tt-rss.git] / tt-rss.js
index 85f335b28ce8492cc8541929eba2dc6ded11b466..63518c154bb39d6a14af3466db040ce593e47506 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -6,13 +6,11 @@ var global_unread = -1;
 var active_title_text = "";
 var current_subtitle = "";
 var daemon_enabled = false;
-var daemon_refresh_only = false;
 //var _qfd_deleted_feed = 0;
 var firsttime_update = true;
 var _active_feed_id = 0;
 var _active_feed_is_cat = false;
 var number_of_feeds = 0;
-var sanity_check_done = false;
 var _hfd_scrolltop = 0;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
@@ -28,7 +26,7 @@ function activeFeedIsCat() {
 
 function getActiveFeedId() {
        try {
-               debug("gAFID: " + _active_feed_id);
+               //console.log("gAFID: " + _active_feed_id);
                return _active_feed_id;
        } catch (e) {
                exception_error("getActiveFeedId", e);
@@ -37,7 +35,7 @@ function getActiveFeedId() {
 
 function setActiveFeedId(id, is_cat) {
        try {
-               debug("sAFID(" + id + ", " + is_cat + ")");
+               //console.log("sAFID(" + id + ", " + is_cat + ")");
                _active_feed_id = id;
 
                if (is_cat != undefined) {
@@ -62,7 +60,7 @@ function toggleTags(show_all) {
 
        try {
 
-       debug("toggleTags: " + show_all + "; " + display_tags);
+       console.log("toggleTags: " + show_all + "; " + display_tags);
 
        var p = $("dispSwitchPrompt");
 
@@ -88,103 +86,18 @@ function toggleTags(show_all) {
 
 function dlg_frefresh_callback(transport, deleted_feed) {
        if (getActiveFeedId() == deleted_feed) {
-               var h = $("headlines-frame");
-               if (h) {
-                       h.innerHTML = "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
-               }
+               setTimeout("viewfeed(-5)", 100);
        }
 
        setTimeout('updateFeedList(false, false)', 50);
        closeInfoBox();
 }
 
-function backend_sanity_check_callback(transport) {
-
-       try {
-
-               if (sanity_check_done) {
-                       fatalError(11, "Sanity check request received twice. This can indicate "+
-                     "presence of Firebug or some other disrupting extension. "+
-                               "Please disable it and try again.");
-                       return;
-               }
-
-               if (!transport.responseXML) {
-                       if (!store) {
-                               fatalError(3, "Sanity check: Received reply is not XML", 
-                                       transport.responseText);
-                               return;
-                       } else {
-                               init_offline();
-                               return;
-                       }
-               }
-
-               if (getURLParam("offline")) {
-                       return init_offline();
-               }
-
-               var reply = transport.responseXML.firstChild.firstChild;
-
-               if (!reply) {
-                       fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
-                       return;
-               }
-
-               var error_code = reply.getAttribute("error-code");
-       
-               if (error_code && error_code != 0) {
-                       return fatalError(error_code, reply.getAttribute("error-msg"));
-               }
-
-               debug("sanity check ok");
-
-               var params = reply.nextSibling;
+function scheduleFeedUpdate() {
 
-               if (params) {
-                       debug('reading init-params...');
-                       var param = params.firstChild;
+       console.log("in scheduleFeedUpdate");
 
-                       while (param) {
-                               var k = param.getAttribute("key");
-                               var v = param.getAttribute("value");
-                               debug(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;
-                       }
-               }
-
-               sanity_check_done = true;
-
-               init_second_stage();
-
-       } catch (e) {
-               exception_error("backend_sanity_check_callback", e, transport); 
-       } 
-}
-
-function scheduleFeedUpdate(force) {
-
-       debug("in scheduleFeedUpdate");
-
-/*     if (!daemon_enabled && !daemon_refresh_only) {
-               notify_progress("Updating feeds...", true);
-       } */
-
-       var query_str = "backend.php?op=rpc&subop=";
-
-       if (force) {
-               query_str = query_str + "forceUpdateAllFeeds";
-       } else {
-               query_str = query_str + "updateAllFeeds";
-       }
+       var query_str = "backend.php?op=rpc&subop=updateAllFeeds";
 
        var omode;
 
@@ -202,7 +115,7 @@ function scheduleFeedUpdate(force) {
        query_str = query_str + "&omode=" + omode;
        query_str = query_str + "&uctr=" + global_unread;
 
-       debug("REFETCH query: " + query_str);
+       console.log("REFETCH query: " + query_str);
 
        new Ajax.Request("backend.php", {
                parameters: query_str,
@@ -211,39 +124,31 @@ function scheduleFeedUpdate(force) {
                        } });
 }
 
-function updateFeedList(silent, fetch) {
-
-//     if (silent != true) {
-//             notify("Loading feed list...");
-//     }
-
-       debug("<b>updateFeedList</b>");
-
-       if (offline_mode) return render_offline_feedlist();
-
-       var query_str = "backend.php?op=feeds";
-
-       if (display_tags) {
-               query_str = query_str + "&tags=1";
-       }
-
-       if (getActiveFeedId() && !activeFeedIsCat()) {
-               query_str = query_str + "&actid=" + getActiveFeedId();
-       }
+function updateFeedList() {
+       try {
+               console.log("updateFeedList");
        
-       if (fetch) query_str = query_str + "&fetch=yes";
-
-//     var feeds_frame = $("feeds-frame");
-//     feeds_frame.src = query_str;
-
-       debug("updateFeedList Q=" + query_str);
-
-       new Ajax.Request("backend.php", {
-               parameters: query_str,
-               onComplete: function(transport) { 
-                       feedlist_callback2(transport); 
-               } });
+               if (offline_mode) return render_offline_feedlist();
+       
+               var query_str = "backend.php?op=feeds";
+       
+               if (display_tags) {
+                       query_str = query_str + "&tags=1";
+               }
+       
+               if (getActiveFeedId() && !activeFeedIsCat()) {
+                       query_str = query_str + "&actid=" + getActiveFeedId();
+               }
+               
+               new Ajax.Request("backend.php", {
+                       parameters: query_str,
+                       onComplete: function(transport) { 
+                               render_feedlist(transport.responseText);
+                       } });
 
+       } catch (e) {
+               exception_error("updateFeedList", e);
+       }
 }
 
 function catchupAllFeeds() {
@@ -256,7 +161,7 @@ function catchupAllFeeds() {
 
                notify_progress("Marking all feeds as read...");
 
-               debug("catchupAllFeeds Q=" + query_str);
+               console.log("catchupAllFeeds Q=" + query_str);
 
                new Ajax.Request("backend.php", {
                        parameters: query_str,
@@ -332,6 +237,14 @@ function updateTitle(s) {
                tmp = tmp + " > " + active_title_text;
        }
 
+       if (window.fluid) {
+               if (global_unread > 0) {
+                       window.fluid.dockBadge = global_unread;
+               } else {
+                       window.fluid.dockBadge = "";
+               }
+       }
+
        document.title = tmp;
 }
 
@@ -359,11 +272,6 @@ function init() {
                if (!genericSanityCheck()) 
                        return;
 
-               if (getURLParam('debug')) {
-                       Element.show("debug_output");
-                       debug('debug mode activated');
-               }
-
                var params = "&ua=" + param_escape(navigator.userAgent);
 
                loading_set_progress(30);
@@ -383,7 +291,7 @@ function resize_headlines(delta_x, delta_y) {
 
        try {
 
-               debug("resize_headlines: " + delta_x + ":" + delta_y);
+               console.log("resize_headlines: " + delta_x + ":" + delta_y);
        
                var h_frame = $("headlines-frame");
                var c_frame = $("content-frame");
@@ -406,7 +314,7 @@ function resize_headlines(delta_x, delta_y) {
                                }
                        }
        
-                       debug("resize_headlines: HOR-mode: " + hor_offset);
+                       console.log("resize_headlines: HOR-mode: " + hor_offset);
        
                        c_frame.style.width = (400 + hor_offset) + "px";
                        h_frame.style.right = c_frame.offsetWidth - 1 + "px";
@@ -416,7 +324,7 @@ function resize_headlines(delta_x, delta_y) {
                                4) + "px";
                        resize_grab.style.display = "block";
 
-                       resize_handle.src = "themes/"+getInitParam('theme')+"/images/resize_handle_vert.png";
+                       //resize_handle.src = "themes/"+getInitParam('theme')+"/images/resize_handle_vert.png";
                        resize_handle.style.paddingTop = (resize_grab.offsetHeight / 2 - 7) + "px";
        
                } else {
@@ -427,13 +335,17 @@ function resize_headlines(delta_x, delta_y) {
                                }
                        }
        
-                       debug("resize_headlines: VER-mode: " + ver_offset);
+                       console.log("resize_headlines: VER-mode: " + ver_offset);
        
                        h_frame.style.height = (300 - ver_offset) + "px";
        
                        c_frame.style.top = (h_frame.offsetTop + h_frame.offsetHeight + 0) + "px";
                        h_frame.style.height = h_frame.offsetHeight + "px";
 
+                       // Workaround for Opera: force the content page to be re-rendered, 
+                       // so it is not truncated:
+                       var content_pane = $("content-insert");
+                       content_pane.innerHTML = content_pane.innerHTML;
                }
        
                if (getInitParam("cookie_lifetime") != 0) {
@@ -467,7 +379,6 @@ function init_second_stage() {
                dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
 
                daemon_enabled = getInitParam("daemon_enabled") == 1;
-               daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
                feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
 
 /*             var fl = cache_find_param("FEEDLIST", getInitParam("num_feeds"));
@@ -485,26 +396,29 @@ function init_second_stage() {
 
                setTimeout('updateFeedList(false, false)', 50);
 
-               debug("second stage ok");
+               console.log("second stage ok");
 
                loading_set_progress(60);
 
                ver_offset = parseInt(getCookie("ttrss_offset_ver"));
                hor_offset = parseInt(getCookie("ttrss_offset_hor"));
 
-               debug("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset);
+               console.log("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset);
 
                /* fuck IE */
 
                if (isNaN(hor_offset)) hor_offset = 0;
                if (isNaN(ver_offset)) ver_offset = 0;
 
-               debug("offsets from cookies [x:y]: " + hor_offset + ":" + ver_offset);
+               console.log("offsets from cookies [x:y]: " + hor_offset + ":" + ver_offset);
 
                resize_headlines();
 
                enable_offline_reading();
 
+               if (has_local_storage())
+                       localStorage.clear();
+
        } catch (e) {
                exception_error("init_second_stage", e);
        }
@@ -605,6 +519,18 @@ function quickMenuGo(opid) {
                        resize_headlines();
                }
 
+               if (opid == "qmcToggleReorder") {
+                       feedlist_sortable_enabled = !feedlist_sortable_enabled;
+
+                       if (feedlist_sortable_enabled) {
+                               notify_info("Category reordering enabled");
+                               toggle_sortable_feedlist(true);
+                       } else {
+                               notify_info("Category reordering disabled");
+                               toggle_sortable_feedlist(false);
+                       }
+               }
+
                if (opid == "qmcResetCats") {
 
                        if (confirm(__("Reset category order?"))) {
@@ -654,19 +580,19 @@ function toggleDispRead() {
 
 function parse_runtime_info(elem) {
        if (!elem) {
-               debug("parse_runtime_info: elem is null, aborting");
+               console.log("parse_runtime_info: elem is null, aborting");
                return;
        }
 
        var param = elem.firstChild;
 
-       debug("parse_runtime_info: " + param);
+       console.log("parse_runtime_info: " + param);
 
        while (param) {
                var k = param.getAttribute("key");
                var v = param.getAttribute("value");
 
-               debug("RI: " + k + " => " + v);
+               console.log("RI: " + k + " => " + v);
 
                if (k == "num_feeds") {
                        init_params[k] = v;                                     
@@ -813,7 +739,7 @@ function feedEditSave() {
 
 function collapse_feedlist() {
        try {
-               debug("collapse_feedlist");
+               console.log("collapse_feedlist");
                
                var theme = getInitParam("theme");
                if (theme != "" && 
@@ -829,7 +755,7 @@ function collapse_feedlist() {
 
                if (!Element.visible(fl)) {
                        Element.show(fl);
-                       fbtn.innerHTML = "<<";
+                       fbtn.innerHTML = "&lt;&lt;";
 
                        if (theme != "graycube") {
 
@@ -851,7 +777,7 @@ function collapse_feedlist() {
 
                } else {
                        Element.hide(fl);
-                       fbtn.innerHTML = ">>";
+                       fbtn.innerHTML = "&gt;&gt;";
 
                        if (theme != "graycube") {
 
@@ -972,7 +898,7 @@ function hotkey_handler(e) {
                } 
 
                if (!hotkeys_enabled) {
-                       debug("hotkeys disabled");
+                       console.log("hotkeys disabled");
                        return;
                }
 
@@ -990,7 +916,7 @@ function hotkey_handler(e) {
                        cmdline.innerHTML = keychar;
                        Element.show(cmdline);
 
-                       debug("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
+                       console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
                        return true;
                }
 
@@ -1004,17 +930,6 @@ function hotkey_handler(e) {
 
                if (!hotkey_prefix) {
 
-                       if (keycode == 68 && shift_key) { // d
-                               if (!Element.visible("debug_output")) {
-                                       Element.show("debug_output");
-                                       debug('debug mode activated');
-                               } else {
-                                       Element.hide("debug_output");
-                               }
-       
-                               return;
-                       }
-       
                        if ((keycode == 191 || keychar == '?') && shift_key) { // ?
                                if (!Element.visible("hotkey_help_overlay")) {
                                        //Element.show("hotkey_help_overlay");
@@ -1094,14 +1009,14 @@ function hotkey_handler(e) {
                        if (keycode == 78 || keycode == 40) { // n, down
                                if (typeof moveToPost != 'undefined') {
                                        moveToPost('next');
-                                       return;
+                                       return false;
                                }
                        }
        
                        if (keycode == 80 || keycode == 38) { // p, up
                                if (typeof moveToPost != 'undefined') {
                                        moveToPost('prev');
-                                       return;
+                                       return false;
                                }
                        }
 
@@ -1243,6 +1158,10 @@ function hotkey_handler(e) {
                                return;
                        }
 
+                       if (keycode == 88) { // x
+                               reverseHeadlineOrder();
+                               return;
+                       }
                }
 
                /* Prefix c */
@@ -1338,9 +1257,9 @@ function hotkey_handler(e) {
                }
 
                if (hotkey_prefix) {
-                       debug("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
                } else {
-                       debug("KP: CODE=" + keycode + " CHAR=" + keychar);
+                       console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
                }
 
 
@@ -1356,3 +1275,24 @@ function feedsSortByUnread() {
 function inPreferences() {
        return false;
 }
+
+function reverseHeadlineOrder() {
+       try {
+
+               var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
+
+               new Ajax.Request("backend.php", {
+                       parameters: query_str,
+                       onComplete: function(transport) { 
+                                       viewCurrentFeed();
+                               } });
+
+       } catch (e) {
+               exception_error("reverseHeadlineOrder", e);
+       }
+}
+
+function showFeedsWithErrors() {
+       displayDlg('feedUpdateErrors');
+}
+