diff options
| author | Alex Kovar | 2010-09-27 11:13:37 -0500 |
|---|---|---|
| committer | Alex Kovar | 2010-09-27 11:13:37 -0500 |
| commit | 60ffade9df3f46fca1bf31dc77e46ad9873a9cdf (patch) | |
| tree | 835c479c6fe501972e305070e902cb8bd9278f2c /linkHints.js | |
| parent | b2f3db6fe2a3ff8887c5961b868bebf530c4cfaf (diff) | |
| parent | 9d9bd40ae050ae4b5b9665fcdde4c60e3486cc87 (diff) | |
| download | vimium-60ffade9df3f46fca1bf31dc77e46ad9873a9cdf.tar.bz2 | |
Merge branch 'master' of http://github.com/philc/vimium
* 'master' of http://github.com/philc/vimium:
Revert a rename - not sure why I committed that.
Oops, fixed a regression.
Code cleanup & README changes for the multiple link hints patch.
Fix some frame logic and disable focusing the largest one for now because it's buggy with iframes.
A bunch of changes having to do with the frame support patch:
Updated README
Added ab3 to Credits ;)
Clean up code
added resetLinkHintsMode
Added activeteLinkHintsModeWithQueue and resetLinkHintsMode to linkHints.js and added 'q cmd' and 'q help cmd' to commands.js
Update README with new/changed key mappings.
Command to go to next frame.
Only show the Help Dialog on the focused frame.
Fix view source toggle when inside a frame.
Basic Support for Frames
Conflicts:
commands.js
manifest.json
Diffstat (limited to 'linkHints.js')
| -rw-r--r-- | linkHints.js | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/linkHints.js b/linkHints.js index fcaa832b..7593a630 100644 --- a/linkHints.js +++ b/linkHints.js @@ -13,6 +13,7 @@ var hintMarkerContainingDiv = null; var hintKeystrokeQueue = []; var linkHintsModeActivated = false; var shouldOpenLinkHintInNewTab = false; +var shouldOpenLinkHintWithQueue = false; // Whether link hint's "open in current/new tab" setting is currently toggled var openLinkModeToggle = false; // Whether we have added to the page the CSS needed to display link hints. @@ -32,25 +33,32 @@ var clickableElementsXPath = (function() { })(); // We need this as a top-level function because our command system doesn't yet support arguments. -function activateLinkHintsModeToOpenInNewTab() { activateLinkHintsMode(true); } +function activateLinkHintsModeToOpenInNewTab() { activateLinkHintsMode(true, false); } -function activateLinkHintsMode(openInNewTab) { +function activateLinkHintsModeWithQueue() { activateLinkHintsMode(true, true); } + +function activateLinkHintsMode(openInNewTab, withQueue) { if (!linkHintsCssAdded) addCssToPage(linkHintCss); // linkHintCss is declared by vimiumFrontend.js linkHintCssAdded = true; linkHintsModeActivated = true; - setOpenLinkMode(openInNewTab); + setOpenLinkMode(openInNewTab, withQueue); buildLinkHints(); document.addEventListener("keydown", onKeyDownInLinkHintsMode, true); document.addEventListener("keyup", onKeyUpInLinkHintsMode, true); } -function setOpenLinkMode(openInNewTab) { +function setOpenLinkMode(openInNewTab, withQueue) { shouldOpenLinkHintInNewTab = openInNewTab; - if (shouldOpenLinkHintInNewTab) - HUD.show("Open link in new tab"); - else - HUD.show("Open link in current tab"); + shouldOpenLinkHintWithQueue = withQueue; + if (shouldOpenLinkHintWithQueue) { + HUD.show("Open multiple links in a new tab"); + } else { + if (shouldOpenLinkHintInNewTab) + HUD.show("Open link in new tab"); + else + HUD.show("Open link in current tab"); + } } /* @@ -143,10 +151,11 @@ function isVisible(element, clientRect) { } function onKeyDownInLinkHintsMode(event) { + console.log("Key Down"); if (event.keyCode == keyCodes.shiftKey && !openLinkModeToggle) { // Toggle whether to open link in a new or current tab. - setOpenLinkMode(!shouldOpenLinkHintInNewTab); - openLinkModeToggle = true; + setOpenLinkMode(!shouldOpenLinkHintInNewTab, shouldOpenLinkHintWithQueue); + openLinkModeToggle = true; } var keyChar = getKeyChar(event); @@ -177,8 +186,8 @@ function onKeyDownInLinkHintsMode(event) { function onKeyUpInLinkHintsMode(event) { if (event.keyCode == keyCodes.shiftKey && openLinkModeToggle) { // Revert toggle on whether to open link in new or current tab. - setOpenLinkMode(!shouldOpenLinkHintInNewTab); - openLinkModeToggle = false; + setOpenLinkMode(!shouldOpenLinkHintInNewTab, shouldOpenLinkHintWithQueue); + openLinkModeToggle = false; } event.stopPropagation(); event.preventDefault(); @@ -202,13 +211,19 @@ function updateLinkHints() { } else { // When we're opening the link in the current tab, don't navigate to the selected link immediately; // we want to give the user some feedback depicting which link they've selected by focusing it. - if (!shouldOpenLinkHintInNewTab) - setTimeout(function() { simulateClick(matchedLink); }, 400); - else + if (shouldOpenLinkHintWithQueue) { simulateClick(matchedLink); - matchedLink.focus(); + resetLinkHintsMode(); + } else if (shouldOpenLinkHintInNewTab) { + simulateClick(matchedLink); + matchedLink.focus(); + deactivateLinkHintsMode(); + } else { + setTimeout(function() { simulateClick(matchedLink); }, 400); + matchedLink.focus(); + deactivateLinkHintsMode(); + } } - deactivateLinkHintsMode(); } } @@ -289,6 +304,11 @@ function deactivateLinkHintsMode() { HUD.hide(); } +function resetLinkHintsMode() { + deactivateLinkHintsMode(); + activateLinkHintsModeWithQueue(); +} + /* * Creates a link marker for the given link. */ |
