]> git.wh0rd.org - tt-rss.git/blobdiff - js/tt-rss.js
Merge remote-tracking branch 'upstream/master'
[tt-rss.git] / js / tt-rss.js
index 530cb293139d4c02ffaed5fdac7df24db5e9a693..1d6540dbb47e90c8b6a94551cda23d9e49bbf7e2 100644 (file)
@@ -1,10 +1,10 @@
 var global_unread = -1;
-var _active_feed_id = undefined;
-var _active_feed_is_cat = false;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = 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;
@@ -21,7 +21,6 @@ function activeFeedIsCat() {
 
 function getActiveFeedId() {
        try {
-               //console.log("gAFID: " + _active_feed_id);
                return _active_feed_id;
        } catch (e) {
                exception_error("getActiveFeedId", e);
@@ -30,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) {
@@ -179,10 +178,14 @@ 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 + ")";
+               tmp = "(" + global_unread + ") " + tmp;
        }
 
        if (window.fluid) {
@@ -245,9 +248,11 @@ function init() {
                loading_set_progress(20);
 
                var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
+               var hasSandbox = "sandbox" in document.createElement("iframe");
 
                new Ajax.Request("backend.php", {
-                       parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio},
+                       parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
+                               hasSandbox: hasSandbox},
                        onComplete: function(transport) {
                                        backend_sanity_check_callback(transport);
                                } });
@@ -284,6 +289,13 @@ 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
@@ -438,6 +450,12 @@ function parse_runtime_info(data) {
                        return;
                }
 
+               if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
+                       if (parseInt(getInitParam("dep_ts")) < parseInt(v)) {
+                               window.location.reload();
+                       }
+               }
+
                if (k == "daemon_is_running" && v != 1) {
                        notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
                        return;
@@ -550,7 +568,7 @@ function hotkey_handler(e) {
                if (keycode == 16) return; // ignore lone shift
                if (keycode == 17) return; // ignore lone ctrl
 
-               if (!shift_key) keychar = keychar.toLowerCase();
+               keychar = keychar.toLowerCase();
 
                var hotkeys = getInitParam("hotkeys");
 
@@ -571,7 +589,11 @@ function hotkey_handler(e) {
                Element.hide(cmdline);
 
                var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
+
+               // ensure ^*char notation
+               if (shift_key) hotkey = "*" + hotkey;
                if (ctrl_key) hotkey = "^" + hotkey;
+
                hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
                hotkey_prefix = false;
 
@@ -604,6 +626,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 ;
@@ -641,17 +669,31 @@ function hotkey_handler(e) {
                        catchupRelativeToArticle(0);
                        return false;
                case "article_scroll_down":
-                       scrollArticle(50);
+                       var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
+
+                       scrollArticle(ctr.offsetHeight/3);
                        return false;
                case "article_scroll_up":
-                       scrollArticle(-50);
+                       var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
+
+                       scrollArticle(-ctr.offsetHeight/3);
                        return false;
                case "close_article":
-                       closeArticlePanel();
+                       if (isCdmMode()) {
+                               if (!getInitParam("cdm_expanded")) {
+                                       cdmCollapseArticle(false, getActiveArticleId());
+                               } else {
+                                       dismissArticle(getActiveArticleId());
+                               }
+                       } else {
+                               closeArticlePanel();
+                       }
                        return false;
                case "email_article":
                        if (typeof emailArticle != "undefined") {
                                emailArticle();
+                       } else if (typeof mailtoArticle != "undefined") {
+                               mailtoArticle();
                        } else {
                                alert(__("Please enable mail plugin first."));
                        }
@@ -754,6 +796,14 @@ function hotkey_handler(e) {
                case "collapse_sidebar":
                        collapse_feedlist();
                        return false;
+               case "toggle_embed_original":
+                       if (typeof embedOriginalArticle != "undefined") {
+                               if (getActiveArticleId())
+                                       embedOriginalArticle(getActiveArticleId());
+                       } else {
+                               alert(__("Please enable embed_original plugin first."));
+                       }
+                       return false;
                case "toggle_widescreen":
                        if (!isCdmMode()) {
                                _widescreen_mode = !_widescreen_mode;
@@ -763,6 +813,19 @@ function hotkey_handler(e) {
                        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);
@@ -864,8 +927,6 @@ function handle_rpc_json(transport, scheduled_call) {
                        if (runtime_info)
                                parse_runtime_info(runtime_info);
 
-                       hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
-
                        Element.hide(dijit.byId("net-alert").domNode);
 
                } else {
@@ -885,6 +946,8 @@ function handle_rpc_json(transport, scheduled_call) {
 
 function switchPanelMode(wide) {
        try {
+               if (isCdmMode()) return;
+
                article_id = getActiveArticleId();
 
                if (wide) {
@@ -942,3 +1005,21 @@ function update_random_feed() {
                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);
+       }
+}