diff options
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 42 | 
1 files changed, 36 insertions, 6 deletions
| diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 3f73919b..577aa0c5 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -694,7 +694,8 @@ selectFoundInputElement = ->    # instead. however, since the last focused element might not be the one currently pointed to by find (e.g.    # the current one might be disabled and therefore unable to receive focus), we use the approximate    # heuristic of checking that the last anchor node is an ancestor of our element. -  if (findModeQueryHasResults && DomUtils.isSelectable(document.activeElement) && +  if (findModeQueryHasResults && document.activeElement && +      DomUtils.isSelectable(document.activeElement) &&        isDOMDescendant(findModeAnchorNode, document.activeElement))      DomUtils.simulateSelect(document.activeElement)      # the element has already received focus via find(), so invoke insert mode manually @@ -732,7 +733,8 @@ findAndFocus = (backwards) ->    # if we have found an input element via 'n', pressing <esc> immediately afterwards sends us into insert    # mode -  elementCanTakeInput = DomUtils.isSelectable(document.activeElement) && +  elementCanTakeInput = document.activeElement && +    DomUtils.isSelectable(document.activeElement) &&      isDOMDescendant(findModeAnchorNode, document.activeElement)    if (elementCanTakeInput)      handlerStack.push({ @@ -864,7 +866,7 @@ exitFindMode = ->    findMode = false    HUD.hide() -showHelpDialog = (html, fid) -> +window.showHelpDialog = (html, fid) ->    return if (isShowingHelpDialog || !document.body || fid != frameId)    isShowingHelpDialog = true    container = document.createElement("div") @@ -875,13 +877,41 @@ showHelpDialog = (html, fid) ->    container.innerHTML = html    container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false) +   +  VimiumHelpDialog = +    # This setting is pulled out of local storage. It's false by default. +    getShowAdvancedCommands: (callback) -> +      chrome.extension.sendRequest({ handler: "getShowAdvancedCommands"}, callback) + +    init: () -> +      this.dialogElement = document.getElementById("vimiumHelpDialog") +      this.dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].addEventListener("click", +        VimiumHelpDialog.toggleAdvancedCommands, false) +      this.dialogElement.style.maxHeight = window.innerHeight - 80 +      this.getShowAdvancedCommands(this.showAdvancedCommands) + +    #  +    # Advanced commands are hidden by default so they don't overwhelm new and casual users. +    #  +    toggleAdvancedCommands: (event) -> +      event.preventDefault() +      VimiumHelpDialog.getShowAdvancedCommands((value) -> +        VimiumHelpDialog.showAdvancedCommands(!value) +        chrome.extension.sendRequest({ handler: "saveHelpDialogSettings", showAdvancedCommands: !value })) + +    showAdvancedCommands: (visible) -> +      VimiumHelpDialog.dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].innerHTML = +        if visible then "Hide advanced commands" else "Show advanced commands" +      advancedEls = VimiumHelpDialog.dialogElement.getElementsByClassName("advanced") +      for el in advancedEls +        el.style.display = if visible then "table-row" else "none" + +  VimiumHelpDialog.init() +    container.getElementsByClassName("optionsPage")[0].addEventListener("click",      -> chrome.extension.sendRequest({ handler: "openOptionsPageInNewTab" })      false) -  # This is necessary because innerHTML does not evaluate javascript embedded in <script> tags. -  scripts = Array.prototype.slice.call(container.getElementsByTagName("script")) -  scripts.forEach((script) -> eval(script.text))  hideHelpDialog = (clickEvent) ->    isShowingHelpDialog = false | 
