diff options
| author | Stephen Blott | 2016-04-17 16:22:28 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-17 16:22:28 +0100 |
| commit | 44ddab1e1eca01ae6c958756d149be2d4128b290 (patch) | |
| tree | be4e76270a1b0fdffc58c1a706cc4983e57b23d9 /content_scripts | |
| parent | 27385e81debd5fcd9000c718d73e296d6723e83a (diff) | |
| parent | 4b564e8517dd3415cb8e2209ce019fa024e88770 (diff) | |
| download | vimium-44ddab1e1eca01ae6c958756d149be2d4128b290.tar.bz2 | |
Merge pull request #2101 from smblott-github/rework-help-dialog
Move help dialog to top frame
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/hud.coffee | 8 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 3 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 33 | ||||
| -rw-r--r-- | content_scripts/vomnibar.coffee | 8 |
4 files changed, 22 insertions, 30 deletions
diff --git a/content_scripts/hud.coffee b/content_scripts/hud.coffee index 0bd1df3e..62bcf03f 100644 --- a/content_scripts/hud.coffee +++ b/content_scripts/hud.coffee @@ -23,13 +23,13 @@ HUD = @_showForDurationTimerId = setTimeout((=> @hide()), duration) show: (text) -> - return unless @isReady() + @init() clearTimeout(@_showForDurationTimerId) @hudUI.activate {name: "show", text} @tween.fade 1.0, 150 showFindMode: (@findMode = null) -> - return unless @isReady() + @init() @hudUI.activate name: "showFindMode" @tween.fade 1.0, 150 @@ -46,7 +46,7 @@ HUD = # If :updateIndicator is truthy, then we also refresh the mode indicator. The only time we don't update the # mode indicator, is when hide() is called for the mode indicator itself. hide: (immediate = false, updateIndicator = true) -> - return unless @tween? and @isReady() + return unless @hudUI?.uiComponentIsReady clearTimeout(@_showForDurationTimerId) @tween.stop() if immediate @@ -80,8 +80,6 @@ HUD = @findMode.exit() postExit?() - isReady: -> @hudUI?.uiComponentIsReady - class Tween opacity: 0 intervalId: -1 diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index 37321660..6508627e 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -69,8 +69,7 @@ class Mode # undefined, then the request propagates to the next mode. # The active indicator can also be changed with @setIndicator(). if @options.indicator? - if HUD?.isReady() - if @options.indicator then HUD.show @options.indicator else HUD.hide true, false + if @options.indicator then HUD.show @options.indicator else HUD.hide true, false @passEventToPage else @continueBubbling diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 92145303..a80093f9 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -121,9 +121,8 @@ class NormalMode extends KeyHandlerMode Are you sure you want to continue?""" if registryEntry.topFrame - # The Vomnibar (a top-frame command) cannot coexist with the help dialog (it causes focus issues). + # We never return to a UI-component frame (e.g. the help dialog), it might have lost the focus. sourceFrameId = if window.isVimiumUIComponent then 0 else frameId - HelpDialog.toggle() if HelpDialog.isShowing() chrome.runtime.sendMessage handler: "sendMessageToFrames", message: {name: "runInTopFrame", sourceFrameId, registryEntry} else if registryEntry.background @@ -142,10 +141,6 @@ installModes = -> initializeOnEnabledStateKnown = Utils.makeIdempotent -> installModes() -initializeUIComponents = Utils.makeIdempotent -> DomUtils.documentReady -> - HUD.init() - Vomnibar.init() if DomUtils.isTopFrame() - # # Complete initialization work that should be done prior to DOMReady. # @@ -155,7 +150,6 @@ initializePreDomReady = -> checkIfEnabledForUrl document.hasFocus() requestHandlers = - toggleHelpDialog: (request) -> if frameId == request.frameId then HelpDialog.toggle request.dialogHtml focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame request getScrollPosition: (ignoredA, ignoredB, sendResponse) -> sendResponse scrollX: window.scrollX, scrollY: window.scrollY if frameId == 0 @@ -458,13 +452,8 @@ checkIfEnabledForUrl = do -> {isEnabledForUrl, passKeys, frameIsFocused} = response initializeOnEnabledStateKnown() normalMode.setPassKeys passKeys - # Initialize UI components, if necessary. We only initialize these once we know that Vimium is enabled; - # see #1838. We need to check this every time so that we can change state from disabled to enabled. - if isEnabledForUrl - initializeUIComponents() if frameIsFocused - else - # Hide the HUD if we're not enabled. - HUD.hide() if HUD.isReady() + # Hide the HUD if we're not enabled. + HUD.hide true, false unless isEnabledForUrl (frameIsFocused = windowIsFocused()) -> Frame.postMessage "isEnabledForUrl", {frameIsFocused, url: window.location.toString()} @@ -626,19 +615,25 @@ enterFindMode = -> Marks.setPreviousPosition() new FindMode() -# If we are in the help dialog iframe, HelpDialog is already defined with the necessary functions. +window.showHelp = (sourceFrameId) -> + chrome.runtime.sendMessage handler: "getHelpDialogHtml", (response) -> + HelpDialog.toggle {sourceFrameId, html: response} + +# If we are in the help dialog iframe, then HelpDialog is already defined with the necessary functions. window.HelpDialog ?= helpUI: null isShowing: -> @helpUI?.showing + abort: -> @helpUI.hide false if @isShowing() - toggle: (html) -> + toggle: (request) -> @helpUI ?= new UIComponent "pages/help_dialog.html", "vimiumHelpDialogFrame", -> if @isShowing() @helpUI.hide() else - # On the options page, we allow the help dialog to lose the focus, elsewhere we do not. This allows - # users to view the help dialog while typing in the key-mappings input. - @helpUI.activate {name: "activate", html, focus: true, allowBlur: window.isVimiumOptionsPage ? false} + # On the options page, we allow the help dialog to blur, elsewhere we do not. This allows users to view + # the help dialog while typing in the key-mappings input. + @helpUI.activate extend request, + name: "activate", focus: true, allowBlur: window.isVimiumOptionsPage ? false initializePreDomReady() DomUtils.documentReady initializeOnDomReady diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 02ce97c5..cbd2892c 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -48,8 +48,7 @@ Vomnibar = } init: -> - unless @vomnibarUI? - @vomnibarUI = new UIComponent "pages/vomnibar.html", "vomnibarFrame", -> + @vomnibarUI ?= new UIComponent "pages/vomnibar.html", "vomnibarFrame", -> # This function opens the vomnibar. It accepts options, a map with the values: # completer - The completer to fetch results from. @@ -58,8 +57,9 @@ Vomnibar = # newTab - Optional, boolean. Whether to open the result in a new tab. open: (sourceFrameId, options) -> @init() - if @vomnibarUI?.uiComponentIsReady - @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } + # The Vomnibar cannot coexist with the help dialog (it causes focus issues). + HelpDialog.abort() + @vomnibarUI.activate extend options, { name: "activate", sourceFrameId, focus: true } root = exports ? window root.Vomnibar = Vomnibar |
