diff options
| author | mrmr1993 | 2016-03-05 13:54:22 +0000 |
|---|---|---|
| committer | mrmr1993 | 2016-03-05 13:54:22 +0000 |
| commit | e93b6b2cd689016022113006c53d0decfb98d5c5 (patch) | |
| tree | 22703bc5b55aa970cc97cbdc95aa3c4886298ffe /content_scripts | |
| parent | 4491ba5e988aa069839ca073f9de6bada596857f (diff) | |
| download | vimium-e93b6b2cd689016022113006c53d0decfb98d5c5.tar.bz2 | |
Factor out click activators in link hints
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/link_hints.coffee | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 45145d49..5c116bad 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -103,6 +103,8 @@ class LinkHintsMode id: "vimiumHintMarkerContainer", className: "vimiumReset" setOpenLinkMode: (@mode) -> + clickActivator = (modifiers) -> (link) -> DomUtils.simulateClick link, modifiers + if @mode is OPEN_IN_NEW_BG_TAB or @mode is OPEN_IN_NEW_FG_TAB or @mode is OPEN_WITH_QUEUE if @mode is OPEN_IN_NEW_BG_TAB @hintMode.setIndicator "Open link in new tab." @@ -110,14 +112,14 @@ class LinkHintsMode @hintMode.setIndicator "Open link in new tab and switch to it." else @hintMode.setIndicator "Open multiple links in new tabs." - @linkActivator = (link) -> - # When "clicking" on a link, dispatch the event with the appropriate meta key (CMD on Mac, CTRL on - # windows) to open it in a new tab if necessary. - DomUtils.simulateClick link, - shiftKey: @mode is OPEN_IN_NEW_FG_TAB - metaKey: KeyboardUtils.platform == "Mac" - ctrlKey: KeyboardUtils.platform != "Mac" - altKey: false + # When "clicking" on a link, dispatch the event with the appropriate meta key (CMD on Mac, CTRL on + # windows) to open it in a new tab if necessary. + @linkActivator = clickActivator { + shiftKey: @mode is OPEN_IN_NEW_FG_TAB + metaKey: KeyboardUtils.platform == "Mac" + ctrlKey: KeyboardUtils.platform != "Mac" + altKey: false + } else if @mode is COPY_LINK_URL @hintMode.setIndicator "Copy link URL to Clipboard." @linkActivator = (link) => @@ -134,11 +136,10 @@ class LinkHintsMode chrome.runtime.sendMessage handler: 'openUrlInIncognito', url: link.href else if @mode is DOWNLOAD_LINK_URL @hintMode.setIndicator "Download link URL." - @linkActivator = (link) -> - DomUtils.simulateClick link, altKey: true, ctrlKey: false, metaKey: false + @linkActivator = clickActivator altKey: true, ctrlKey: false, metaKey: false else # OPEN_IN_CURRENT_TAB @hintMode.setIndicator "Open link in current tab." - @linkActivator = DomUtils.simulateClick.bind DomUtils + @linkActivator = clickActivator # # Creates a link marker for the given link. |
