From bebb767410db71e6cd493a7fe09a0aba4c4613a2 Mon Sep 17 00:00:00 2001 From: Matt Garriott Date: Sat, 25 Aug 2012 13:01:17 -0600 Subject: The help dialog now initializes the javascript from the within vimium_frontend.coffee. All that is left now is to get the user's settings for the showAdvancedCommands option. --- content_scripts/vimium_frontend.coffee | 45 +++++++++++++++++++++++++++++++--- help_dialog.html | 36 --------------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index f4fb17fe..548e9c6c 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -841,13 +841,52 @@ window.showHelpDialog = (html, fid) -> container.innerHTML = html container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false) + + # Chrome's new security policy with manifest version 2 prevents the use + # of eval in this case. So instead of keeping the javascript in the help_dialog.html + # file we can just put it here as coffee script. + # See https://developer.chrome.com/trunk/extensions/sandboxingEval.html for more + # information on chrome's new security policies. + # @mgarriott - 8-25-2012 + # + # OldMethod: + # scripts = Array.prototype.slice.call(container.getElementsByTagName("script")) + # scripts.forEach((script) -> eval(script.text)) + VimiumHelpDialog = + # This setting is pulled out of local storage. It's false by default. + advancedCommandsVisible: false + #chrome.extension.getBackgroundPage().Settings.get('helpDialog_showAdvancedCommands') + + init: () -> + this.dialogElement = document.getElementById("vimiumHelpDialog") + this.dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].addEventListener("click", + VimiumHelpDialog.toggleAdvancedCommands, false) + this.dialogElement.style.maxHeight = window.innerHeight - 80 + this.showAdvancedCommands(this.advancedCommandsVisible) + + # + # Advanced commands are hidden by default so they don't overwhelm new and casual users. + # + toggleAdvancedCommands: (event) -> + event.preventDefault() + VimiumHelpDialog.advancedCommandsVisible = !VimiumHelpDialog.advancedCommandsVisible + chrome.extension.sendRequest( + { handler: "saveHelpDialogSettings", showAdvancedCommands: VimiumHelpDialog.advancedCommandsVisible }) + VimiumHelpDialog.showAdvancedCommands(VimiumHelpDialog.advancedCommandsVisible) + + 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 -- cgit v1.2.3