diff options
| author | Phil Crosby | 2014-12-12 10:02:25 -0800 |
|---|---|---|
| committer | Phil Crosby | 2014-12-12 10:02:25 -0800 |
| commit | ff3586a0cbd0ed4e7ad1bc818f5906292bf07d6d (patch) | |
| tree | ca9bff07e9e3178c506f4eb6d8a0bb835d2291eb /pages/options.coffee | |
| parent | b6125a2b13d6927c10f381f51b207445fd3f049b (diff) | |
| parent | c6f78f1a9191eeb781c3718ac10a8b06408c3441 (diff) | |
| download | vimium-ff3586a0cbd0ed4e7ad1bc818f5906292bf07d6d.tar.bz2 | |
Merge remote-tracking branch 'smblott-github/option-for-options-page'
Conflicts:
pages/options.html
Diffstat (limited to 'pages/options.coffee')
| -rw-r--r-- | pages/options.coffee | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/pages/options.coffee b/pages/options.coffee index 3474bcba..cd19fa37 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -42,13 +42,7 @@ class Option @saveOptions: -> Option.all.map (option) -> option.save() $("saveOptions").disabled = true - - # Used by text options. <ctrl-Enter> saves all options. - activateCtrlEnterListener: (element) -> - element.addEventListener "keyup", (event) -> - if event.ctrlKey and event.keyCode == 13 - element.blur() - Option.saveOptions() + $("saveOptions").innerHTML = "No Changes" # Abstract method; only implemented in sub-classes. # Populate the option's DOM element (@element) with the setting's current value. @@ -66,7 +60,6 @@ class TextOption extends Option constructor: (field,enableSaveButton) -> super(field,enableSaveButton) @element.addEventListener "input", enableSaveButton - @activateCtrlEnterListener @element populateElement: (value) -> @element.value = value readValueFromElement: -> @element.value.trim() @@ -74,7 +67,6 @@ class NonEmptyTextOption extends Option constructor: (field,enableSaveButton) -> super(field,enableSaveButton) @element.addEventListener "input", enableSaveButton - @activateCtrlEnterListener @element populateElement: (value) -> @element.value = value # If the new value is not empty, then return it. Otherwise, restore the default value. @@ -89,7 +81,6 @@ class ExclusionRulesOption extends Option super(args...) $("exclusionAddButton").addEventListener "click", (event) => @appendRule { pattern: "", passKeys: "" } - @maintainExclusionMargin() # Focus the pattern element in the new rule. @element.children[@element.children.length-1].children[0].children[0].focus() # Scroll the new rule into view. @@ -97,11 +88,8 @@ class ExclusionRulesOption extends Option exclusionScrollBox.scrollTop = exclusionScrollBox.scrollHeight populateElement: (rules) -> - while @element.firstChild - @element.removeChild @element.firstChild for rule in rules @appendRule rule - @maintainExclusionMargin() # Append a row for a new rule. appendRule: (rule) -> @@ -111,7 +99,6 @@ class ExclusionRulesOption extends Option for field in ["pattern", "passKeys"] element = row.querySelector ".#{field}" element.value = rule[field] - @activateCtrlEnterListener element for event in [ "input", "change" ] element.addEventListener event, enableSaveButton @@ -120,13 +107,12 @@ class ExclusionRulesOption extends Option row = event.target.parentNode.parentNode row.parentNode.removeChild row enableSaveButton() - @maintainExclusionMargin() @element.appendChild row readValueFromElement: -> rules = - for element in @element.children + for element in @element.getElementsByClassName "exclusionRuleTemplateInstance" pattern = element.children[0].firstChild.value.trim() passKeys = element.children[1].firstChild.value.trim() { pattern: pattern, passKeys: passKeys } @@ -138,20 +124,11 @@ class ExclusionRulesOption extends Option flatten = (rule) -> if rule and rule.pattern then rule.pattern + "\n" + rule.passKeys else "" a.map(flatten).join("\n") == b.map(flatten).join("\n") - # Hack. There has to be a better way than... - # The y-axis scrollbar for "exclusionRules" is only displayed if it is needed. When visible, it appears on - # top of the enclosed content (partially obscuring it). Here, we adjust the margin of the "Remove" button to - # compensate. - maintainExclusionMargin: -> - scrollBox = $("exclusionScrollBox") - margin = if scrollBox.clientHeight < scrollBox.scrollHeight then "16px" else "0px" - for element in scrollBox.getElementsByClassName "exclusionRemoveButton" - element.style["margin-right"] = margin - # # Operations for page elements. enableSaveButton = -> $("saveOptions").removeAttribute "disabled" + $("saveOptions").innerHTML = "Save Changes" # Display either "linkHintNumbers" or "linkHintCharacters", depending upon "filterLinkHints". maintainLinkHintsView = -> @@ -175,9 +152,13 @@ toggleAdvancedOptions = $("advancedOptionsLink").innerHTML = "Hide advanced options" advancedMode = !advancedMode event.preventDefault() + # Prevent the "advanced options" link from retaining the focus. + document.activeElement.blur() activateHelpDialog = -> showHelpDialog chrome.extension.getBackgroundPage().helpDialogHtml(true, true, "Command Listing"), frameId + # Prevent the "show help" link from retaining the focus. + document.activeElement.blur() # # Initialization. @@ -214,3 +195,8 @@ document.addEventListener "DOMContentLoaded", -> maintainLinkHintsView() window.onbeforeunload = -> "You have unsaved changes to options." unless $("saveOptions").disabled + document.addEventListener "keyup", (event) -> + if event.ctrlKey and event.keyCode == 13 + document.activeElement.blur() if document?.activeElement?.blur + Option.saveOptions() + |
