]> git.wh0rd.org - tt-rss.git/blobdiff - js/tt-rss.js
Merge branch 'master' of github.com:gothfox/Tiny-Tiny-RSS
[tt-rss.git] / js / tt-rss.js
index 5cbfbfa6e91e0b25b4b58ff97fa1aa8aa14f738f..7462d933de3f1ee531a3b92a9a9dcf9d107314ec 100644 (file)
@@ -1,14 +1,9 @@
-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;
 
 function next_seq() {
@@ -74,25 +69,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:");
@@ -105,8 +82,6 @@ function updateFeedList() {
                id: "feedTree",
                }, "feedTree");
 
-               _force_scheduled_update = true;
-
 /*             var menu = new dijit.Menu({id: 'feedMenu'});
 
                menu.addChild(new dijit.MenuItem({
@@ -126,8 +101,6 @@ function updateFeedList() {
                dojo.disconnect(tmph);
                        Element.hide("feedlistLoading");
 
-                       tree.collapseHiddenCats();
-
                        feedlist_init();
 
 //                     var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
@@ -176,51 +149,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() {
@@ -280,10 +212,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");
@@ -336,8 +264,10 @@ function init_second_stage() {
                        updateFeedList();
                        closeArticlePanel();
 
-                       if (typeof themeAfterLayout == 'function') {
-                               themeAfterLayout();
+                       _widescreen_mode = getInitParam("widescreen");
+
+                       if (_widescreen_mode) {
+                               switchPanelMode(_widescreen_mode);
                        }
 
                });
@@ -360,8 +290,24 @@ function init_second_stage() {
                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);
        }
@@ -369,42 +315,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()) {
@@ -424,46 +363,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;
-               }
-
-               if (opid == "qmcToggleWidescreen") {
+                       break;
+               case "qmcToggleWidescreen":
                        if (!isCdmMode()) {
                                _widescreen_mode = !_widescreen_mode;
 
                                switchPanelMode(_widescreen_mode);
                        }
-                       return;
-               }
-
-               if (opid == "qmcHKhelp") {
+                       break;
+               case "qmcHKhelp":
                        helpDialog("main");
+                       break;
+               default:
+                       console.log("quickMenuGo: unknown action: " + opid);
                }
 
        } catch (e) {
@@ -503,13 +430,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;
                }
@@ -568,26 +492,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();
@@ -628,11 +532,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;
@@ -670,6 +571,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;
 
@@ -702,6 +604,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 ;
@@ -744,6 +652,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();
@@ -945,7 +856,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);
                                }
                        }
 
@@ -961,12 +872,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);
        }
@@ -984,9 +899,11 @@ function switchPanelMode(wide) {
 
                        dijit.byId("content-insert").domNode.setStyle({width: '50%',
                                height: 'auto',
-                               'border-top-width': '0px' });
+                               borderLeftWidth: '1px',
+                               borderLeftColor: '#c0c0c0',
+                               borderTopWidth: '0px' });
 
-                       $("headlines-toolbar").setStyle({ 'border-bottom-width': '0px' });
+                       $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
 
                } else {
 
@@ -994,16 +911,40 @@ function switchPanelMode(wide) {
 
                        dijit.byId("content-insert").domNode.setStyle({width: 'auto',
                                height: '50%',
-                               'border-top-width': '1px'});
+                               borderLeftWidth: '0px',
+                               borderTopWidth: '1px'});
 
-                       $("headlines-toolbar").setStyle({ 'border-bottom-width': '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);
+       }
+}