]> git.wh0rd.org Git - tt-rss.git/commitdiff
unify frontend hotkey handlers
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 23 May 2006 06:55:26 +0000 (07:55 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 23 May 2006 06:55:26 +0000 (07:55 +0100)
feedlist.js
functions.js
tt-rss.js
viewfeed.js

index ae4c23225fd9d516ebd36ab7be4d8b65f0cbeb2a..d32ff1550c2b325290944d23ea6e91515b30bfe5 100644 (file)
@@ -130,40 +130,6 @@ function viewfeed(feed, skip, subop, doc, is_cat, subop_param) {
        }               
 }
 
-function localHotkeyHandler(keycode) {
-
-       if (keycode == 65) { // a
-               return parent.toggleDispRead();
-       }
-
-       if (keycode == 85) { // u
-               if (parent.getActiveFeedId()) {
-                       return viewfeed(parent.getActiveFeedId(), 0, "ForceUpdate");
-               }
-       }
-
-       if (keycode == 82) { // r
-               return parent.scheduleFeedUpdate(true);
-       }
-
-       var feedlist = document.getElementById('feedList');
-
-       if (keycode == 74) { // j
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-       if (keycode == 75) { // k
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'next');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-//     alert("KC: " + keycode);
-
-}
-
 function toggleCollapseCat(cat) {
        try {
                if (!xmlhttp_ready(xmlhttp)) {
index f642cda85e7bc42496f260524f3717b060b94551..c03176255df0d46130def4428edac934e0fe06b5 100644 (file)
@@ -14,10 +14,13 @@ function exception_error(location, e) {
                msg = "Exception: " + e.name + ", " + e.message + 
                        "\nFunction: " + location + "()" +
                        "\nLocation: " + base_fname + ":" + e.lineNumber;
+               
        } else {
                msg = "Exception: " + e + "\nFunction: " + location + "()";
        }
 
+       debug("<b>EXCEPTION: " + msg + "</b>");
+
        alert(msg);
 }
 
@@ -148,40 +151,85 @@ var seq = "";
 
 function hotkey_handler(e) {
 
-       var keycode;
-
-       if (!hotkeys_enabled) return;
-
-       if (window.event) {
-               keycode = window.event.keyCode;
-       } else if (e) {
-               keycode = e.which;
-       }
-
-       if (keycode == 13 || keycode == 27) {
-               seq = "";
-       } else {
-               seq = seq + "" + keycode;
-       }
-
-       if (document.getElementById("piggie")) {
+       try {
 
-               if (seq.match("807371717369")) {
+               var keycode;
+       
+               if (!hotkeys_enabled) return;
+       
+               if (window.event) {
+                       keycode = window.event.keyCode;
+               } else if (e) {
+                       keycode = e.which;
+               }
+       
+               if (keycode == 13 || keycode == 27) {
                        seq = "";
-                       localPiggieFunction(true);
                } else {
-                       localPiggieFunction(false);
+                       seq = seq + "" + keycode;
                }
-       }
        
-       if (typeof localHotkeyHandler != 'undefined') {
-               try {
-                       localHotkeyHandler(keycode);
-               } catch (e) {
-                       exception_error("hotkey_handler", e);
+               var m_ctx = getMainContext();
+               var f_ctx = getFeedsContext();
+               var h_ctx = getHeadlinesContext();
+       
+               if (keycode == 82) { // r
+                       return m_ctx.scheduleFeedUpdate(true);
+               }
+       
+               if (keycode == 85) { // u
+                       if (getActiveFeedId()) {
+                               return f_ctx.viewfeed(getActiveFeedId(), 0, "ForceUpdate");
+                       }
+               }
+       
+               if (keycode == 65) { // a
+                       return m_ctx.toggleDispRead();
+               }
+       
+               var f_doc = m_ctx.frames["feeds-frame"].document;
+               var feedlist = f_doc.getElementById('feedList');
+       
+               if (keycode == 74) { // j
+                       var feed = getActiveFeedId();
+                       var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
+                       if (new_feed) viewfeed(new_feed, 0, '');
+               }
+       
+               if (keycode == 75) { // k
+                       var feed = getActiveFeedId();
+                       var new_feed = getRelativeFeedId(feedlist, feed, 'next');
+                       if (new_feed) viewfeed(new_feed, 0, '');
                }
-       }
 
+               if (keycode == 78 || keycode == 40) { // n, down
+                       return h_ctx.moveToPost('next');
+               }
+       
+               if (keycode == 80 || keycode == 38) { // p, up
+                       return h_ctx.moveToPost('prev');
+               } 
+       
+               if (document.getElementById("piggie")) {
+       
+                       if (seq.match("807371717369")) {
+                               seq = "";
+                               localPiggieFunction(true);
+                       } else {
+                               localPiggieFunction(false);
+                       }
+               }
+               
+               if (typeof localHotkeyHandler != 'undefined') {
+                       try {
+                               localHotkeyHandler(keycode);
+                       } catch (e) {
+                               exception_error("hotkey_handler, local:", e);
+                       }
+               }
+       } catch (e) {
+               exception_error("hotkey_handler", e);
+       }
 }
 
 function cleanSelectedList(element) {
@@ -1070,6 +1118,15 @@ function getFeedsContext() {
        }
 }
 
+
+function getHeadlinesContext() {
+       try {
+               return getMainContext().frames["headlines-frame"];
+       } catch (e) {
+               exception_error("getHeadlinesContext", e);
+       }
+}
+
 function debug(msg) {
        var ctx = getMainContext();
 
index 3ffd04e8f01323c6f5dee1bb36f3109086b96f5a..0c3584c8eb704afe1c510b3759058b64833bce32 100644 (file)
--- a/tt-rss.js
+++ b/tt-rss.js
@@ -288,41 +288,6 @@ function localPiggieFunction(enable) {
        }
 }
 
-function localHotkeyHandler(keycode) {
-
-       if (keycode == 82) { // r
-               return scheduleFeedUpdate(true);
-       }
-
-       if (keycode == 85) { // u
-               if (getActiveFeedId()) {
-                       return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
-               }
-       }
-
-       if (keycode == 65) { // a
-               return toggleDispRead();
-       }
-
-       var f_doc = window.frames["feeds-frame"].document;
-       var feedlist = f_doc.getElementById('feedList');
-
-       if (keycode == 74) { // j
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-       if (keycode == 75) { // k
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'next');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-//     notify("KC: " + keycode);
-
-}
-
 // if argument is undefined, current subtitle is not updated
 // use blank string to clear subtitle
 function updateTitle(s) {
index 5a11c4e99d6b2c9ddcf658d0ba508adb0121f022..17ffa7fc8cc0f3d3c0b1957f01923daaf49bfe4c 100644 (file)
@@ -22,38 +22,42 @@ if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
 }
 
 function view(id, feed_id) {
+       
+       try {
 
-       parent.debug("loading article: " + id + "/" + feed_id);
-
-       var f_document = parent.frames["feeds-frame"].document;
-       var h_document = document;
-       var m_document = parent.document;
-
-       enableHotkeys();
-
-       var crow = h_document.getElementById("RROW-" + id);
-
-       crow.className = crow.className.replace("Unread", "");
-
-       cleanSelected("headlinesList");
-
-       var upd_img_pic = h_document.getElementById("FUPDPIC-" + id);
-
-       if (upd_img_pic) {
-               upd_img_pic.src = "images/blank_icon.gif";
-       } 
-
-       active_post_id = id; 
-       setActiveFeedId(feed_id);
-
-       var content = m_document.getElementById("content-frame");
-
-       content.src = "backend.php?op=view&id=" + param_escape(id) +
-               "&feed=" + param_escape(feed_id);
-
-       selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
-       markHeadline(active_post_id);
+               debug("loading article: " + id + "/" + feed_id);
+       
+               var f_document = getFeedsContext().document;
+               var m_document = parent.document;
+       
+               enableHotkeys();
+       
+               var crow = document.getElementById("RROW-" + id);
+       
+               crow.className = crow.className.replace("Unread", "");
+       
+               cleanSelected("headlinesList");
+       
+               var upd_img_pic = document.getElementById("FUPDPIC-" + id);
+       
+               if (upd_img_pic) {
+                       upd_img_pic.src = "images/blank_icon.gif";
+               } 
+       
+               active_post_id = id; 
+               setActiveFeedId(feed_id);
+       
+               var content = m_document.getElementById("content-frame");
+       
+               content.src = "backend.php?op=view&id=" + param_escape(id) +
+                       "&feed=" + param_escape(feed_id);
+       
+               selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
+               markHeadline(active_post_id);
 
+       } catch (e) {
+               exception_error("view", e);
+       }
 }
 
 function toggleMark(id) {
@@ -155,58 +159,6 @@ function viewfeed(id) {
        f.viewfeed(id, 0);
 }
 
-function localHotkeyHandler(keycode) {
-
-       if (keycode == 78 || keycode == 40) { // n, down
-               return moveToPost('next');
-       }
-
-       if (keycode == 80 || keycode == 38) { // p, up
-               return moveToPost('prev');
-       } 
-
-       if (keycode == 65) { // a
-               return parent.toggleDispRead();
-       }
-
-       if (keycode == 85) { // u
-               if (parent.getActiveFeedId()) {
-                       return parent.viewfeed(parent.getActiveFeedId(), 0, "ForceUpdate");
-               }
-       }
-
-       if (keycode == 82) { // r
-               return parent.scheduleFeedUpdate(true);
-       }
-       
-       var f_doc = parent.frames["feeds-frame"].document;
-       var feedlist = f_doc.getElementById('feedList');
-
-       if (keycode == 74) { // j
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-       if (keycode == 75) { // k
-               var feed = getActiveFeedId();
-               var new_feed = getRelativeFeedId(feedlist, feed, 'next');
-               if (new_feed) viewfeed(new_feed, 0, '');
-       }
-
-// FIXME
-//     if (keycode == 85) {
-//             return viewfeed(active_feed_id, active_offset, "ForceUpdate");
-//     }
-
-       if (keycode == 83) { // s
-               selectionToggleMarked();
-       }
-       
-//     alert("KC: " + keycode);
-
-}
-
 function toggleUnread(id, cmode) {
        try {
                if (!xmlhttp_ready(xmlhttp_rpc)) {