aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrmr19932016-02-03 03:04:56 +0000
committermrmr19932016-02-03 03:04:56 +0000
commitf9561276204ea8b3770600cfd2f7b268e28d8717 (patch)
tree63c586622ed876d13c0ac7510870743aecd0bd18
parent94979f8e6b7f5efc51b1bcc380bf0f4fbcb6dfb8 (diff)
downloadvimium-f9561276204ea8b3770600cfd2f7b268e28d8717.tar.bz2
Restructure VimiumHelpDialog so show and init have appropriate code
-rw-r--r--content_scripts/vimium_frontend.coffee33
1 files changed, 17 insertions, 16 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index c554fde3..e54c5c75 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -769,26 +769,29 @@ window.enterFindMode = ->
new FindMode()
VimiumHelpDialog =
+ container: null
+ dialogElement: null
+
# This setting is pulled out of local storage. It's false by default.
getShowAdvancedCommands: -> Settings.get("helpDialog_showAdvancedCommands")
- init: (html) ->
- container = DomUtils.createElement "div"
- container.id = "vimiumHelpDialogContainer"
- container.className = "vimiumReset"
+ init: ->
+ unless @container?
+ @container = DomUtils.createElement "div"
+ @container.id = "vimiumHelpDialogContainer"
+ @container.className = "vimiumReset"
- document.body.appendChild(container)
+ show: (html) ->
+ document.body.appendChild @container
- container.innerHTML = html
- container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false)
- container.getElementsByClassName("optionsPage")[0].addEventListener("click", (clickEvent) ->
+ @container.innerHTML = html
+ @container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false)
+ @container.getElementsByClassName("optionsPage")[0].addEventListener("click", (clickEvent) ->
clickEvent.preventDefault()
chrome.runtime.sendMessage({handler: "openOptionsPageInNewTab"})
false)
-
- show: ->
- @dialogElement = document.getElementById("vimiumHelpDialog")
+ @dialogElement = @container.querySelector "#VimiumHelpDialog"
@dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].addEventListener("click",
VimiumHelpDialog.toggleAdvancedCommands, false)
@showAdvancedCommands(@getShowAdvancedCommands())
@@ -797,9 +800,7 @@ VimiumHelpDialog =
DomUtils.simulateClick document.getElementById "vimiumHelpDialog"
hide: ->
- helpDialog = document.getElementById("vimiumHelpDialogContainer")
- if (helpDialog)
- helpDialog.parentNode.removeChild(helpDialog)
+ @container?.parentNode?.removeChild @container
#
# Advanced commands are hidden by default so they don't overwhelm new and casual users.
@@ -821,8 +822,8 @@ window.showHelpDialog = (html, fid) ->
return if (isShowingHelpDialog || !document.body || fid != frameId)
isShowingHelpDialog = true
- VimiumHelpDialog.init html
- VimiumHelpDialog.show()
+ VimiumHelpDialog.init()
+ VimiumHelpDialog.show html
hideHelpDialog = (clickEvent) ->
isShowingHelpDialog = false