]> git.wh0rd.org - tt-rss.git/blobdiff - js/tt-rss.js
Feature #446 - Allow customizing page title
[tt-rss.git] / js / tt-rss.js
index 18a7da9d3e695620b00c56c3f54437aeb981da40..5d6e1d81ec5399dccb4f289af4ad0dea035d36a9 100644 (file)
@@ -1,14 +1,10 @@
-var total_unread = 0;
 var global_unread = -1;
-var firsttime_update = true;
-var _active_feed_id = undefined;
-var _active_feed_is_cat = false;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
-var _force_scheduled_update = false;
-var last_scheduled_update = false;
-
+var _widescreen_mode = false;
 var _rpc_seq = 0;
+var _active_feed_id = 0;
+var _active_feed_is_cat = false;
 
 function next_seq() {
        _rpc_seq += 1;
@@ -25,7 +21,6 @@ function activeFeedIsCat() {
 
 function getActiveFeedId() {
        try {
-               //console.log("gAFID: " + _active_feed_id);
                return _active_feed_id;
        } catch (e) {
                exception_error("getActiveFeedId", e);
@@ -34,11 +29,11 @@ function getActiveFeedId() {
 
 function setActiveFeedId(id, is_cat) {
        try {
-               _active_feed_id = id;
+               hash_set('f', id);
+               hash_set('c', is_cat ? 1 : 0);
 
-               if (is_cat != undefined) {
-                       _active_feed_is_cat = is_cat;
-               }
+               _active_feed_id = id;
+               _active_feed_is_cat = is_cat;
 
                selectFeed(id, is_cat);
        } catch (e) {
@@ -73,25 +68,7 @@ function updateFeedList() {
                });
 
                var tree = new fox.FeedTree({
-               persist: false,
                model: treeModel,
-               onOpen: function (item, node) {
-                       var id = String(item.id);
-                       var cat_id = id.substr(id.indexOf(":")+1);
-
-                       new Ajax.Request("backend.php",
-                               { parameters: "backend.php?op=feeds&method=collapse&cid=" +
-                                       param_escape(cat_id) + "&mode=0" } );
-          },
-               onClose: function (item, node) {
-                       var id = String(item.id);
-                       var cat_id = id.substr(id.indexOf(":")+1);
-
-                       new Ajax.Request("backend.php",
-                               { parameters: "backend.php?op=feeds&method=collapse&cid=" +
-                                       param_escape(cat_id) + "&mode=1" } );
-
-          },
                onClick: function (item, node) {
                        var id = String(item.id);
                        var is_cat = id.match("^CAT:");
@@ -104,8 +81,6 @@ function updateFeedList() {
                id: "feedTree",
                }, "feedTree");
 
-               _force_scheduled_update = true;
-
 /*             var menu = new dijit.Menu({id: 'feedMenu'});
 
                menu.addChild(new dijit.MenuItem({
@@ -125,8 +100,6 @@ function updateFeedList() {
                dojo.disconnect(tmph);
                        Element.hide("feedlistLoading");
 
-                       tree.collapseHiddenCats();
-
                        feedlist_init();
 
 //                     var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
@@ -175,51 +148,10 @@ function viewCurrentFeed(method) {
 }
 
 function timeout() {
-       if (getInitParam("bw_limit") == "1") return;
-
-       try {
-          var date = new Date();
-      var ts = Math.round(date.getTime() / 1000);
-
-               if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
-
-                       //console.log("timeout()");
-
-                       window.clearTimeout(counter_timeout_id);
-
-                       var query_str = "?op=rpc&method=getAllCounters&seq=" + next_seq();
-
-                       var omode;
-
-                       if (firsttime_update && !navigator.userAgent.match("Opera")) {
-                               firsttime_update = false;
-                               omode = "T";
-                       } else {
-                               omode = "flc";
-                       }
-
-                       query_str = query_str + "&omode=" + omode;
-
-                       if (!_force_scheduled_update)
-                               query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
-
-                       //console.log("[timeout]" + query_str);
-
-                       new Ajax.Request("backend.php", {
-                               parameters: query_str,
-                               onComplete: function(transport) {
-                                               handle_rpc_json(transport, !_force_scheduled_update);
-                                               _force_scheduled_update = false;
-                                       } });
-
-                       last_scheduled_update = ts;
-               }
-
-       } catch (e) {
-               exception_error("timeout", e);
+       if (getInitParam("bw_limit") != "1") {
+               request_counters();
+               setTimeout("timeout()", 60*1000);
        }
-
-       setTimeout("timeout()", 3000);
 }
 
 function search() {
@@ -246,7 +178,11 @@ function search() {
 }
 
 function updateTitle() {
-       var tmp = "Tiny Tiny RSS";
+       var tmp = document.title; 
+    if (tmp.indexOf('(')>0)
+    {
+       tmp = tmp.substr(0,tmp.lastIndexOf('('));
+    }
 
        if (global_unread > 0) {
                tmp = tmp + " (" + global_unread + ")";
@@ -279,10 +215,6 @@ function init() {
 
                dojo.require("fox.FeedTree");
 
-               if (typeof themeBeforeLayout == 'function') {
-                       themeBeforeLayout();
-               }
-
                dojo.require("dijit.ColorPalette");
                dojo.require("dijit.Dialog");
                dojo.require("dijit.form.Button");
@@ -335,8 +267,10 @@ function init_second_stage() {
                        updateFeedList();
                        closeArticlePanel();
 
-                       if (typeof themeAfterLayout == 'function') {
-                               themeAfterLayout();
+                       _widescreen_mode = getInitParam("widescreen");
+
+                       if (_widescreen_mode) {
+                               switchPanelMode(_widescreen_mode);
                        }
 
                });
@@ -353,14 +287,37 @@ function init_second_stage() {
 
                feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
 
+               var hash_feed_id = hash_get('f');
+               var hash_feed_is_cat = hash_get('c') == "1";
+
+               if (hash_feed_id != undefined) {
+                       setActiveFeedId(hash_feed_id, hash_feed_is_cat);
+               }
+
                loading_set_progress(30);
 
                // can't use cache_clear() here because viewfeed might not have initialized yet
                if ('sessionStorage' in window && window['sessionStorage'] !== null)
                        sessionStorage.clear();
 
+               var hotkeys = getInitParam("hotkeys");
+               var tmp = [];
+
+               for (sequence in hotkeys[1]) {
+                       filtered = sequence.replace(/\|.*$/, "");
+                       tmp[filtered] = hotkeys[1][sequence];
+               }
+
+               hotkeys[1] = tmp;
+               setInitParam("hotkeys", hotkeys);
+
                console.log("second stage ok");
 
+               if (getInitParam("simple_update")) {
+                       console.log("scheduling simple feed updater...");
+                       window.setTimeout("update_random_feed()", 30*1000);
+               }
+
        } catch (e) {
                exception_error("init_second_stage", e);
        }
@@ -368,42 +325,35 @@ function init_second_stage() {
 
 function quickMenuGo(opid) {
        try {
-               if (opid == "qmcPrefs") {
+               switch (opid) {
+               case "qmcPrefs":
                        gotoPreferences();
-               }
-
-               if (opid == "qmcTagCloud") {
+                       break;
+               case "qmcLogout":
+                       gotoLogout();
+                       break;
+               case "qmcTagCloud":
                        displayDlg("printTagCloud");
-               }
-
-               if (opid == "qmcTagSelect") {
+                       break;
+               case "qmcTagSelect":
                        displayDlg("printTagSelect");
-               }
-
-               if (opid == "qmcSearch") {
+                       break;
+               case "qmcSearch":
                        search();
-                       return;
-               }
-
-               if (opid == "qmcAddFeed") {
+                       break;
+               case "qmcAddFeed":
                        quickAddFeed();
-                       return;
-               }
-
-               if (opid == "qmcDigest") {
+                       break;
+               case "qmcDigest":
                        window.location.href = "backend.php?op=digest";
-                       return;
-               }
-
-               if (opid == "qmcEditFeed") {
+                       break;
+               case "qmcEditFeed":
                        if (activeFeedIsCat())
                                alert(__("You can't edit this kind of feed."));
                        else
                                editFeed(getActiveFeedId());
-                       return;
-               }
-
-               if (opid == "qmcRemoveFeed") {
+                       break;
+               case "qmcRemoveFeed":
                        var actid = getActiveFeedId();
 
                        if (activeFeedIsCat()) {
@@ -423,37 +373,34 @@ function quickMenuGo(opid) {
                        if (confirm(pr)) {
                                unsubscribeFeed(actid);
                        }
-
-                       return;
-               }
-
-               if (opid == "qmcCatchupAll") {
+                       break;
+               case "qmcCatchupAll":
                        catchupAllFeeds();
-                       return;
-               }
-
-               if (opid == "qmcShowOnlyUnread") {
+                       break;
+               case "qmcShowOnlyUnread":
                        toggleDispRead();
-                       return;
-               }
-
-               if (opid == "qmcAddFilter") {
+                       break;
+               case "qmcAddFilter":
                        quickAddFilter();
-                       return;
-               }
-
-               if (opid == "qmcAddLabel") {
+                       break;
+               case "qmcAddLabel":
                        addLabel();
-                       return;
-               }
-
-               if (opid == "qmcRescoreFeed") {
+                       break;
+               case "qmcRescoreFeed":
                        rescoreCurrentFeed();
-                       return;
-               }
+                       break;
+               case "qmcToggleWidescreen":
+                       if (!isCdmMode()) {
+                               _widescreen_mode = !_widescreen_mode;
 
-               if (opid == "qmcHKhelp") {
+                               switchPanelMode(_widescreen_mode);
+                       }
+                       break;
+               case "qmcHKhelp":
                        helpDialog("main");
+                       break;
+               default:
+                       console.log("quickMenuGo: unknown action: " + opid);
                }
 
        } catch (e) {
@@ -493,13 +440,10 @@ function parse_runtime_info(data) {
 //             console.log("RI: " + k + " => " + v);
 
                if (k == "new_version_available") {
-                       var icon = $("newVersionIcon");
-                       if (icon) {
-                               if (v == "1") {
-                                       icon.style.display = "inline";
-                               } else {
-                                       icon.style.display = "none";
-                               }
+                       if (v == "1") {
+                               Element.show(dijit.byId("newVersionIcon").domNode);
+                       } else {
+                               Element.hide(dijit.byId("newVersionIcon").domNode);
                        }
                        return;
                }
@@ -558,26 +502,6 @@ function viewLimitChanged() {
        return viewCurrentFeed('');
 }
 
-/* function adjustArticleScore(id, score) {
-       try {
-
-               var pr = prompt(__("Assign score to article:"), score);
-
-               if (pr != undefined) {
-                       var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr;
-
-                       new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) {
-                                       viewCurrentFeed();
-                               } });
-
-               }
-       } catch (e) {
-               exception_error("adjustArticleScore", e);
-       }
-} */
-
 function rescoreCurrentFeed() {
 
        var actid = getActiveFeedId();
@@ -618,11 +542,8 @@ function hotkey_handler(e) {
 
                var cmdline = $('cmdline');
 
-               try {
-                       shift_key = e.shiftKey;
-               } catch (e) {
-
-               }
+               shift_key = e.shiftKey;
+               ctrl_key = e.ctrlKey;
 
                if (window.event) {
                        keycode = window.event.keyCode;
@@ -660,6 +581,7 @@ function hotkey_handler(e) {
                Element.hide(cmdline);
 
                var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
+               if (ctrl_key) hotkey = "^" + hotkey;
                hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
                hotkey_prefix = false;
 
@@ -692,6 +614,12 @@ function hotkey_handler(e) {
                case "prev_article":
                        moveToPost('prev');
                        return false;
+               case "next_article_noscroll":
+                       moveToPost('next', true);
+                       return false;
+               case "prev_article_noscroll":
+                       moveToPost('prev', true);
+                       return false;
                case "search_dialog":
                        search();
                        return ;
@@ -734,6 +662,9 @@ function hotkey_handler(e) {
                case "article_scroll_up":
                        scrollArticle(-50);
                        return false;
+               case "close_article":
+                       closeArticlePanel();
+                       return false;
                case "email_article":
                        if (typeof emailArticle != "undefined") {
                                emailArticle();
@@ -839,8 +770,28 @@ function hotkey_handler(e) {
                case "collapse_sidebar":
                        collapse_feedlist();
                        return false;
+               case "toggle_widescreen":
+                       if (!isCdmMode()) {
+                               _widescreen_mode = !_widescreen_mode;
+
+                               switchPanelMode(_widescreen_mode);
+                       }
+                       return false;
                case "help_dialog":
                        helpDialog("main");
+                       return false;
+               case "toggle_combined_mode":
+                       notify_progress("Loading, please wait...");
+
+                       var value = isCdmMode() ? "false" : "true";
+                       var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value;
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                       window.location.reload();
+                               } });
+
                        return false;
                default:
                        console.log("unhandled action: " + hotkey_action + "; hotkey: " + hotkey);
@@ -928,7 +879,7 @@ function handle_rpc_json(transport, scheduled_call) {
                                if (message == "UPDATE_COUNTERS") {
                                        console.log("need to refresh counters...");
                                        setInitParam("last_article_id", -1);
-                                       _force_scheduled_update = true;
+                                       request_counters(true);
                                }
                        }
 
@@ -944,12 +895,16 @@ function handle_rpc_json(transport, scheduled_call) {
 
                        hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
 
+                       Element.hide(dijit.byId("net-alert").domNode);
+
                } else {
-                       notify_error("Error communicating with server.");
+                       //notify_error("Error communicating with server.");
+                       Element.show(dijit.byId("net-alert").domNode);
                }
 
        } catch (e) {
-               notify_error("Error communicating with server.");
+               Element.show(dijit.byId("net-alert").domNode);
+               //notify_error("Error communicating with server.");
                console.log(e);
                //exception_error("handle_rpc_json", e, transport);
        }
@@ -957,3 +912,80 @@ function handle_rpc_json(transport, scheduled_call) {
        return true;
 }
 
+function switchPanelMode(wide) {
+       try {
+               article_id = getActiveArticleId();
+
+               if (wide) {
+                       dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
+                       dijit.byId("content-insert").attr("region", "trailing");
+
+                       dijit.byId("content-insert").domNode.setStyle({width: '50%',
+                               height: 'auto',
+                               borderLeftWidth: '1px',
+                               borderLeftColor: '#c0c0c0',
+                               borderTopWidth: '0px' });
+
+                       $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
+
+               } else {
+
+                       dijit.byId("content-insert").attr("region", "bottom");
+
+                       dijit.byId("content-insert").domNode.setStyle({width: 'auto',
+                               height: '50%',
+                               borderLeftWidth: '0px',
+                               borderTopWidth: '1px'});
+
+                       $("headlines-toolbar").setStyle({ borderBottomWidth: '1px' });
+               }
+
+               closeArticlePanel();
+
+               if (article_id) view(article_id);
+
+               new Ajax.Request("backend.php", {
+                       parameters: "op=rpc&method=setpanelmode&wide=" + (wide ? 1 : 0),
+                       onComplete: function(transport) {
+                               console.log(transport.responseText);
+                       } });
+
+
+       } catch (e) {
+               exception_error("switchPanelMode", e);
+       }
+}
+
+function update_random_feed() {
+       try {
+               console.log("in update_random_feed");
+
+               new Ajax.Request("backend.php", {
+                       parameters: "op=rpc&method=updateRandomFeed",
+                       onComplete: function(transport) {
+                               handle_rpc_json(transport, true);
+                               window.setTimeout("update_random_feed()", 30*1000);
+                       } });
+
+       } catch (e) {
+               exception_error("update_random_feed", e);
+       }
+}
+
+function hash_get(key) {
+       try {
+               kv = window.location.hash.substring(1).toQueryParams();
+               return kv[key];
+       } catch (e) {
+               exception_error("hash_set", e);
+       }
+}
+function hash_set(key, value) {
+       try {
+               kv = window.location.hash.substring(1).toQueryParams();
+               kv[key] = value;
+               window.location.hash = $H(kv).toQueryString();
+       } catch (e) {
+               exception_error("hash_set", e);
+       }
+}