From 09519db103b1cef197e183435e864287ab67e7e3 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 10 Mar 2016 09:32:15 +0000 Subject: 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. --- content_scripts/link_hints.coffee | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'content_scripts') 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 ] -- cgit v1.2.3