]> git.wh0rd.org - tt-rss.git/blobdiff - js/tt-rss.js
Merge pull request #172 from Menti/master
[tt-rss.git] / js / tt-rss.js
index 942e31e1c1fd94a122faf0013b95d634068c79e1..c6c0c13dd445177c7a6219992c3736e5f52e04a8 100644 (file)
@@ -1,6 +1,7 @@
 var global_unread = -1;
 var hotkey_prefix = false;
 var hotkey_prefix_pressed = false;
+var hotkey_actions = {};
 var _widescreen_mode = false;
 var _rpc_seq = 0;
 var _active_feed_id = 0;
@@ -35,7 +36,12 @@ function setActiveFeedId(id, is_cat) {
                _active_feed_id = id;
                _active_feed_is_cat = is_cat;
 
+               $("headlines-frame").setAttribute("feed-id", id);
+               $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
+
                selectFeed(id, is_cat);
+
+               PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id);
        } catch (e) {
                exception_error("setActiveFeedId", e);
        }
@@ -130,7 +136,8 @@ function catchupAllFeeds() {
                new Ajax.Request("backend.php", {
                        parameters: query_str,
                        onComplete: function(transport) {
-                               feedlist_callback2(transport);
+                               request_counters(true);
+                               viewCurrentFeed();
                        } });
 
                global_unread = 0;
@@ -155,7 +162,7 @@ function timeout() {
 }
 
 function search() {
-       var query = "backend.php?op=dlg&method=search&param=" +
+       var query = "backend.php?op=feeds&method=search&param=" +
                param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
 
        if (dijit.byId("searchDlg"))
@@ -205,7 +212,6 @@ function genericSanityCheck() {
        return true;
 }
 
-var hotkey_actions = {};
 
 function init() {
        try {
@@ -245,16 +251,22 @@ function init() {
 
                loading_set_progress(20);
 
-               var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
+               var a = document.createElement('audio');
+
+               var hasAudio = !!a.canPlayType;
                var hasSandbox = "sandbox" in document.createElement("iframe");
+               var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
+               var clientTzOffset = new Date().getTimezoneOffset() * 60;
 
                new Ajax.Request("backend.php", {
                        parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
+                               hasMp3: hasMp3,
+                               clientTzOffset: clientTzOffset,
                                hasSandbox: hasSandbox},
                        onComplete: function(transport) {
                                        backend_sanity_check_callback(transport);
                                } });
-               
+
                hotkey_actions["next_feed"] = function() {
                                var rv = dijit.byId("feedTree").getNextFeed(
                                                getActiveFeedId(), activeFeedIsCat());
@@ -279,6 +291,12 @@ function init() {
                hotkey_actions["prev_article_noscroll"] = function() {
                                moveToPost('prev', true);
                };
+               hotkey_actions["next_article_noexpand"] = function() {
+                               moveToPost('next', true, true);
+               };
+               hotkey_actions["prev_article_noexpand"] = function() {
+                               moveToPost('prev', true, true);
+               };
                hotkey_actions["collapse_article"] = function() {
                                var id = getActiveArticleId();
                                var elem = $("CICD-"+id);
@@ -289,6 +307,16 @@ function init() {
                                        cdmExpandArticle(id);
                                }
                };
+               hotkey_actions["toggle_expand"] = function() {
+                               var id = getActiveArticleId();
+                               var elem = $("CICD-"+id);
+                               if(elem.visible()) {
+                                       cdmCollapseArticle(null, id, false);
+                               }
+                               else {
+                                       cdmExpandArticle(id);
+                               }
+               };
                hotkey_actions["search_dialog"] = function() {
                                search();
                };
@@ -304,7 +332,7 @@ function init() {
                hotkey_actions["edit_tags"] = function() {
                                var id = getActiveArticleId();
                                if (id) {
-                                       editArticleTags(id, getActiveFeedId(), isCdmMode());
+                                       editArticleTags(id);
                                };
                        }
                hotkey_actions["dismiss_selected"] = function() {
@@ -325,12 +353,12 @@ function init() {
                hotkey_actions["article_scroll_down"] = function() {
                                var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
 
-                               scrollArticle(ctr.offsetHeight/3);
+                               scrollArticle(40);
                };
                hotkey_actions["article_scroll_up"] = function() {
                                var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
 
-                               scrollArticle(-ctr.offsetHeight/3);
+                               scrollArticle(-40);
                };
                hotkey_actions["close_article"] = function() {
                                if (isCdmMode()) {
@@ -425,7 +453,7 @@ function init() {
                                viewfeed(-2);
                };
                hotkey_actions["goto_tagcloud"] = function() {
-                               displayDlg("printTagCloud");
+                               displayDlg(__("Tag cloud"), "printTagCloud");
                };
                hotkey_actions["goto_prefs"] = function() {
                                gotoPreferences();
@@ -433,11 +461,17 @@ function init() {
                hotkey_actions["select_article_cursor"] = function() {
                                var id = getArticleUnderPointer();
                                if (id) {
-                                       var cb = dijit.byId("RCHK-" + id);
-                                       if (cb) {
-                                               cb.attr("checked", !cb.attr("checked"));
-                                               toggleSelectRowById(cb, "RROW-" + id);
-                                               return false;
+                                       var row = $("RROW-" + id);
+
+                                       if (row) {
+                                               var cb = dijit.getEnclosingWidget(
+                                                       row.getElementsByClassName("rchk")[0]);
+
+                                               if (cb) {
+                                                       cb.attr("checked", !cb.attr("checked"));
+                                                       toggleSelectRowById(cb, "RROW-" + id);
+                                                       return false;
+                                               }
                                        }
                                }
                };
@@ -477,7 +511,25 @@ function init() {
                                new Ajax.Request("backend.php", {
                                        parameters: query,
                                        onComplete: function(transport) {
-                                               window.location.reload();
+                                               setInitParam("combined_display_mode",
+                                                               !getInitParam("combined_display_mode"));
+
+                                               closeArticlePanel();
+                                               viewCurrentFeed();
+
+                                                               } });
+               };
+               hotkey_actions["toggle_cdm_expanded"] = function() {
+                               notify_progress("Loading, please wait...");
+
+                               var value = getInitParam("cdm_expanded") ? "false" : "true";
+                               var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value;
+
+                               new Ajax.Request("backend.php", {
+                                       parameters: query,
+                                       onComplete: function(transport) {
+                                               setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
+                                               viewCurrentFeed();
                                        } });
                };
 
@@ -560,10 +612,10 @@ function quickMenuGo(opid) {
                        gotoLogout();
                        break;
                case "qmcTagCloud":
-                       displayDlg("printTagCloud");
+                       displayDlg(__("Tag cloud"), "printTagCloud");
                        break;
                case "qmcTagSelect":
-                       displayDlg("printTagSelect");
+                       displayDlg(__("Select item(s) by tags"), "printTagSelect");
                        break;
                case "qmcSearch":
                        search();
@@ -701,6 +753,8 @@ function parse_runtime_info(data) {
                init_params[k] = v;
                notify('');
        }
+
+       PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
 }
 
 function collapse_feedlist() {
@@ -731,10 +785,6 @@ function viewModeChanged() {
        return viewCurrentFeed('');
 }
 
-function viewLimitChanged() {
-       return viewCurrentFeed('');
-}
-
 function rescoreCurrentFeed() {
 
        var actid = getActiveFeedId();
@@ -833,7 +883,11 @@ function hotkey_handler(e) {
                }
 
                var action = hotkey_actions[hotkey_action];
-               if(action != null) action();
+
+               if (action != null) {
+                       action();
+                       return false;
+               }
 
        } catch (e) {
                exception_error("hotkey_handler", e);
@@ -847,13 +901,27 @@ function inPreferences() {
 function reverseHeadlineOrder() {
        try {
 
-               var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
+               /* var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
 
                new Ajax.Request("backend.php", {
                        parameters: query_str,
                        onComplete: function(transport) {
                                        viewCurrentFeed();
-                               } });
+                               } }); */
+
+               var toolbar = document.forms["main_toolbar_form"];
+               var order_by = dijit.getEnclosingWidget(toolbar.order_by);
+
+               var value = order_by.attr('value');
+
+               if (value == "date_reverse")
+                       value = "default";
+               else
+                       value = "date_reverse";
+
+               order_by.attr('value', value);
+
+               viewCurrentFeed();
 
        } catch (e) {
                exception_error("reverseHeadlineOrder", e);
@@ -926,7 +994,7 @@ function handle_rpc_json(transport, scheduled_call) {
                        if (counters)
                                parse_counters(counters, scheduled_call);
 
-                       var runtime_info = reply['runtime-info'];;
+                       var runtime_info = reply['runtime-info'];
 
                        if (runtime_info)
                                parse_runtime_info(runtime_info);
@@ -1015,7 +1083,7 @@ function hash_get(key) {
                kv = window.location.hash.substring(1).toQueryParams();
                return kv[key];
        } catch (e) {
-               exception_error("hash_set", e);
+               exception_error("hash_get", e);
        }
 }
 function hash_set(key, value) {