diff options
| author | ilya | 2009-10-28 23:38:24 -0700 |
|---|---|---|
| committer | ilya | 2009-10-28 23:38:24 -0700 |
| commit | f758035242958bdabb2eb525edc0d3a8919b3bdf (patch) | |
| tree | 18336dcd66883d0d40dcc308123ef65e72554166 | |
| parent | 4d7e3f41fbdde0c240b9efeb3c4219ed5fdbbd3c (diff) | |
| download | vimium-f758035242958bdabb2eb525edc0d3a8919b3bdf.tar.bz2 | |
Implement basic h,j,k,l navigation and remove the unnecessary registry in the content script.
| -rw-r--r-- | background_page.html | 4 | ||||
| -rw-r--r-- | vimiumFrontend.js | 25 |
2 files changed, 14 insertions, 15 deletions
diff --git a/background_page.html b/background_page.html index d175c9b2..b31a911d 100644 --- a/background_page.html +++ b/background_page.html @@ -17,6 +17,10 @@ } var keyToCommandRegistry = {}; + keyToCommandRegistry['j'] = 'scrollDown'; + keyToCommandRegistry['k'] = 'scrollUp'; + keyToCommandRegistry['h'] = 'scrollLeft'; + keyToCommandRegistry['l'] = 'scrollRight'; keyToCommandRegistry['gg'] = 'scrollToTop'; keyToCommandRegistry['G'] = 'scrollToBottom'; keyToCommandRegistry['t'] = createTab; diff --git a/vimiumFrontend.js b/vimiumFrontend.js index bb50b3f2..89611b2b 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -1,3 +1,5 @@ +var SCROLL_STEP_SIZE = 100; // Pixels + document.addEventListener("keydown", onKeydown); document.addEventListener("focus", onFocusCapturePhase, true); document.addEventListener("blur", onBlurCapturePhase, true); @@ -5,26 +7,19 @@ document.addEventListener("blur", onBlurCapturePhase, true); // Send the key to the key handler in the background page. var keyPort = chrome.extension.connect({name: "keyDown"}); -function scrollToBottom() { - console.log("scrollToBottom()"); - window.scrollTo(0, document.body.scrollHeight); -} - -function scrollToTop() { - console.log("scrollToTop()"); - window.scrollTo(0, 0); -} - -var commandRegistry = { - 'scrollToBottom': scrollToBottom, - 'scrollToTop': scrollToTop -}; +function scrollToBottom() { window.scrollTo(0, document.body.scrollHeight); } +function scrollToTop() { window.scrollTo(0, 0); } +function scrollUp() { window.scrollBy(0, -1 * SCROLL_STEP_SIZE); } +function scrollDown() { window.scrollBy(0, SCROLL_STEP_SIZE); } +function scrollLeft() { window.scrollBy(-1 * SCROLL_STEP_SIZE, 0); } +function scrollRight() { window.scrollBy(SCROLL_STEP_SIZE, 0); } chrome.extension.onConnect.addListener(function (port, name) { if (port.name == "executePageCommand") { port.onMessage.addListener(function (args) { - commandRegistry[args.command].call(); + if (this[args.command]) + this[args.command].call(); }); } }); |
