diff options
| author | Stephen Blott | 2016-03-10 09:32:15 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-03-28 05:40:09 +0100 |
| commit | 09519db103b1cef197e183435e864287ab67e7e3 (patch) | |
| tree | 7ce0f6313d5cf45d667e21f0e1b4e5c37b916c42 /content_scripts | |
| parent | 8b19dfcf3bc4fbc0c426f057a4481bd699c09f72 (diff) | |
| download | vimium-09519db103b1cef197e183435e864287ab67e7e3.tar.bz2 | |
Add HintCorrdinator stub.
This adds a shim between launching a link-hints mode and creating the
LinkHintsMode object. The shim is responsibly for for finding the
clickable elements. This is preparatory to implementing global hints.
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/link_hints.coffee | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index ec57f74a..57f7cc2b 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -46,17 +46,25 @@ DOWNLOAD_LINK_URL = indicator: "Download link URL." clickModifiers: altKey: true, ctrlKey: false, metaKey: false +HintCoordinator = + availableModes: [OPEN_IN_CURRENT_TAB, OPEN_IN_NEW_BG_TAB, OPEN_IN_NEW_FG_TAB, OPEN_WITH_QUEUE, + COPY_LINK_URL, OPEN_INCOGNITO, DOWNLOAD_LINK_URL] + + activateMode: (activateModeCallback) -> + activateModeCallback ClickableElements.getVisibleClickableElements() + LinkHints = activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) -> if 0 < count - new LinkHintsMode mode, (event = null) -> - # This is called which LinkHintsMode exits. Escape and Backspace are the two ways in which hints mode - # can exit following which we do not restart hints mode. - return if event?.type == "keydown" and KeyboardUtils.isEscape event - return if event?.type == "keydown" and event.keyCode in [ keyCodes.backspace, keyCodes.deleteKey ] - # Wait for the next tick to allow the previous mode to exit. It might yet generate a click event, - # which would cause our new mode to exit immediately. - Utils.nextTick -> LinkHints.activateMode count-1, mode + HintCoordinator.activateMode (elements) -> + new LinkHintsMode mode, elements, (event = null) -> + # This is called which LinkHintsMode exits. Escape and Backspace are the two ways in which hints mode + # can exit following which we do not restart hints mode. + return if event?.type == "keydown" and KeyboardUtils.isEscape event + return if event?.type == "keydown" and event.keyCode in [ keyCodes.backspace, keyCodes.deleteKey ] + # Wait for the next tick to allow the previous mode to exit. It might yet generate a click event, + # which would cause our new mode to exit immediately. + Utils.nextTick -> LinkHints.activateMode count-1, mode activateModeToOpenInNewTab: (count) -> @activateMode count, OPEN_IN_NEW_BG_TAB activateModeToOpenInNewForegroundTab: (count) -> @activateMode count, OPEN_IN_NEW_FG_TAB @@ -76,11 +84,10 @@ class LinkHintsModeBase # A count of the number of Tab presses since the last non-Tab keyboard event. tabCount: 0 - constructor: (mode = OPEN_IN_CURRENT_TAB, onExit = (->)) -> + constructor: (mode = OPEN_IN_CURRENT_TAB, elements, onExit = (->)) -> # we need documentElement to be ready in order to append links return unless document.documentElement - elements = ClickableElements.getVisibleClickableElements() # For these modes, we filter out those elements which don't have an HREF (since there's nothing we can do # with them). elements = (el for el in elements when el.element.href?) if mode in [ COPY_LINK_URL, OPEN_INCOGNITO ] |
