diff options
| author | Stephen Blott | 2015-04-19 11:01:27 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-04-19 11:01:27 +0100 | 
| commit | b8457c39f9ac487c25c66fffebfc176e8593eaa7 (patch) | |
| tree | a2fc05ec1ee69c54c8c79e86b9e75d85596aa969 /content_scripts/link_hints.coffee | |
| parent | 756312e9f67d73bbaf1e48cc4f9fe0439ccb7f72 (diff) | |
| parent | 0e2d65684a338f6c7a31205f34a76c6d33f46aa8 (diff) | |
| download | vimium-b8457c39f9ac487c25c66fffebfc176e8593eaa7.tar.bz2 | |
Merge branch 'remove-badges'
Conflicts:
	content_scripts/vimium_frontend.coffee
Diffstat (limited to 'content_scripts/link_hints.coffee')
| -rw-r--r-- | content_scripts/link_hints.coffee | 77 | 
1 files changed, 35 insertions, 42 deletions
| diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 72fde9e1..73af6a06 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -8,16 +8,15 @@  # In 'filter' mode, our link hints are numbers, and the user can narrow down the range of possibilities by  # typing the text of the link itself.  # -# The "name" property below is a short-form name to appear in the link-hints mode name.  Debugging only.  The -# key appears in the mode's badge. +# The "name" property below is a short-form name to appear in the link-hints mode's name.  It's for debug only.  # -OPEN_IN_CURRENT_TAB = { name: "curr-tab", key: "" } -OPEN_IN_NEW_BG_TAB = { name: "bg-tab", key: "B" } -OPEN_IN_NEW_FG_TAB = { name: "fg-tab", key: "F" } -OPEN_WITH_QUEUE = { name: "queue", key: "Q" } -COPY_LINK_URL = { name: "link", key: "C" } -OPEN_INCOGNITO = { name: "incognito", key: "I" } -DOWNLOAD_LINK_URL = { name: "download", key: "D" } +OPEN_IN_CURRENT_TAB = name: "curr-tab" +OPEN_IN_NEW_BG_TAB = name: "bg-tab" +OPEN_IN_NEW_FG_TAB = name: "fg-tab" +OPEN_WITH_QUEUE = name: "queue" +COPY_LINK_URL = name: "link" +OPEN_INCOGNITO = name: "incognito" +DOWNLOAD_LINK_URL = name: "download"  LinkHints =    hintMarkerContainingDiv: null @@ -55,61 +54,56 @@ LinkHints =        return      @isActive = true -    @setOpenLinkMode(mode)      hintMarkers = (@createMarkerFor(el) for el in @getVisibleClickableElements())      @getMarkerMatcher().fillInMarkers(hintMarkers) -    # Note(philc): Append these markers as top level children instead of as child nodes to the link itself, -    # because some clickable elements cannot contain children, e.g. submit buttons. This has the caveat -    # that if you scroll the page and the link has position=fixed, the marker will not stay fixed. -    @hintMarkerContainingDiv = DomUtils.addElementList(hintMarkers, -      { id: "vimiumHintMarkerContainer", className: "vimiumReset" }) -      @hintMode = new Mode        name: "hint/#{mode.name}" -      badge: "#{mode.key}?" +      indicator: false        passInitialKeyupEvents: true -      keydown: @onKeyDownInMode.bind(this, hintMarkers), -      # trap all key events +      keydown: @onKeyDownInMode.bind this, hintMarkers +      # Trap all other key events.        keypress: -> false        keyup: -> false +    @setOpenLinkMode mode + +    # Note(philc): Append these markers as top level children instead of as child nodes to the link itself, +    # because some clickable elements cannot contain children, e.g. submit buttons. This has the caveat +    # that if you scroll the page and the link has position=fixed, the marker will not stay fixed. +    @hintMarkerContainingDiv = DomUtils.addElementList(hintMarkers, +      { id: "vimiumHintMarkerContainer", className: "vimiumReset" }) +    setOpenLinkMode: (@mode) ->      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 -        HUD.show("Open link in new tab") +        @hintMode.setIndicator "Open link in new tab"        else if @mode is OPEN_IN_NEW_FG_TAB -        HUD.show("Open link in new tab and switch to it") +        @hintMode.setIndicator "Open link in new tab and switch to it"        else -        HUD.show("Open multiple links in a new tab") +        @hintMode.setIndicator "Open multiple links in a new tab"        @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}) +        DomUtils.simulateClick link, +          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 -      HUD.show("Copy link URL to Clipboard") +      @hintMode.setIndicator "Copy link URL to Clipboard"        @linkActivator = (link) -> -        chrome.runtime.sendMessage({handler: "copyToClipboard", data: link.href}) +        chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href      else if @mode is OPEN_INCOGNITO -      HUD.show("Open link in incognito window") - +      @hintMode.setIndicator "Open link in incognito window"        @linkActivator = (link) -> -        chrome.runtime.sendMessage( -          handler: 'openUrlInIncognito' -          url: link.href) +        chrome.runtime.sendMessage handler: 'openUrlInIncognito', url: link.href      else if @mode is DOWNLOAD_LINK_URL -      HUD.show("Download link URL") +      @hintMode.setIndicator "Download link URL"        @linkActivator = (link) -> -        DomUtils.simulateClick(link, { -          altKey: true, -          ctrlKey: false, -          metaKey: false }) +        DomUtils.simulateClick link, altKey: true, ctrlKey: false, metaKey: false      else # OPEN_IN_CURRENT_TAB -      HUD.show("Open link in current tab") +      @hintMode.setIndicator "Open link in current tab"        @linkActivator = (link) -> DomUtils.simulateClick.bind(DomUtils, link)()    # @@ -276,8 +270,8 @@ LinkHints =        handlerStack.push          keyup: (event) =>            if event.keyCode == keyCode -            @setOpenLinkMode previousMode if @isActive              handlerStack.remove() +            @setOpenLinkMode previousMode if @isActive            true      # TODO(philc): Ignore keys that have modifiers. @@ -347,7 +341,6 @@ LinkHints =          DomUtils.removeElement LinkHints.hintMarkerContainingDiv        LinkHints.hintMarkerContainingDiv = null        @hintMode.exit() -      HUD.hide()        @isActive = false      # we invoke the deactivate() function directly instead of using setTimeout(callback, 0) so that | 
