diff options
| author | Stephen Blott | 2014-12-21 05:28:02 +0000 |
|---|---|---|
| committer | Stephen Blott | 2014-12-21 05:28:02 +0000 |
| commit | e2fe06c25ad0d478a602f77d3ea052ac0e886233 (patch) | |
| tree | 447044a99b78b5c8d6b6ec3d342188bee40d9ec0 | |
| parent | 015f5bad3f6e4058d6bfeb8f6bf213de37464da7 (diff) | |
| download | vimium-e2fe06c25ad0d478a602f77d3ea052ac0e886233.tar.bz2 | |
Exclusion; minor refactoring.
| -rw-r--r-- | background_scripts/exclusions.coffee | 2 | ||||
| -rw-r--r-- | pages/options.coffee | 126 | ||||
| -rw-r--r-- | pages/popup.html | 2 |
3 files changed, 64 insertions, 66 deletions
diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index ac0e5f20..fd74e7da 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -18,7 +18,7 @@ RegexpCache = # The exclusions are an array of such objects (because the order matters). root.Exclusions = Exclusions = - # Make RegexpCache, which is required on the page popup, accessible via Exclusions. + # Make RegexpCache, which is required on the page popup, accessible via the Exclusions object. RegexpCache: RegexpCache rules: Settings.get("exclusionRules") diff --git a/pages/options.coffee b/pages/options.coffee index 776432d2..956c3e4e 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -42,10 +42,6 @@ class Option # Static method. @saveOptions: -> Option.all.map (option) -> option.save() - # These are only relevant on the options page; catch the exception on the popup page. - try - $("saveOptions").disabled = true - $("saveOptions").innerHTML = "No Changes" # Abstract method; only implemented in sub-classes. # Populate the option's DOM element (@element) with the setting's current value. @@ -137,43 +133,63 @@ 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") -# -# Operations for page elements. -enableSaveButton = -> - $("saveOptions").removeAttribute "disabled" - $("saveOptions").innerHTML = "Save Changes" - -# Display either "linkHintNumbers" or "linkHintCharacters", depending upon "filterLinkHints". -maintainLinkHintsView = -> - hide = (el) -> el.parentNode.parentNode.style.display = "none" - show = (el) -> el.parentNode.parentNode.style.display = "table-row" - if $("filterLinkHints").checked - hide $("linkHintCharacters") - show $("linkHintNumbers") - else - show $("linkHintCharacters") - hide $("linkHintNumbers") - -toggleAdvancedOptions = - do (advancedMode=false) -> - (event) -> - if advancedMode - $("advancedOptions").style.display = "none" - $("advancedOptionsLink").innerHTML = "Show advanced options…" - else - $("advancedOptions").style.display = "table-row-group" - $("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() - -initOptions = -> +initOptionsPage = -> + enableSaveButton = -> + $("saveOptions").removeAttribute "disabled" + $("saveOptions").innerHTML = "Save Changes" + + # Display either "linkHintNumbers" or "linkHintCharacters", depending upon "filterLinkHints". + maintainLinkHintsView = -> + hide = (el) -> el.parentNode.parentNode.style.display = "none" + show = (el) -> el.parentNode.parentNode.style.display = "table-row" + if $("filterLinkHints").checked + hide $("linkHintCharacters") + show $("linkHintNumbers") + else + show $("linkHintCharacters") + hide $("linkHintNumbers") + + toggleAdvancedOptions = + do (advancedMode=false) -> + (event) -> + if advancedMode + $("advancedOptions").style.display = "none" + $("advancedOptionsLink").innerHTML = "Show advanced options…" + else + $("advancedOptions").style.display = "table-row-group" + $("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 when clicked. + document.activeElement.blur() + + saveOptions = -> + Option.saveOptions() + $("saveOptions").disabled = true + $("saveOptions").innerHTML = "No Changes" + + $("saveOptions").addEventListener "click", saveOptions + $("advancedOptionsLink").addEventListener "click", toggleAdvancedOptions + $("showCommands").addEventListener "click", activateHelpDialog + $("filterLinkHints").addEventListener "click", maintainLinkHintsView + + for element in document.getElementsByClassName "nonEmptyTextOption" + element.className = element.className + " example info" + element.innerHTML = "Leave empty to reset this option." + + 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 + saveOptions() + options = exclusionRules: ExclusionRulesOption filterLinkHints: CheckBoxOption @@ -195,31 +211,13 @@ initOptions = -> for name, type of options new type(name,enableSaveButton) - $("saveOptions").addEventListener "click", Option.saveOptions - $("advancedOptionsLink").addEventListener "click", toggleAdvancedOptions - $("showCommands").addEventListener "click", activateHelpDialog - $("filterLinkHints").addEventListener "click", maintainLinkHintsView - - for element in document.getElementsByClassName "nonEmptyTextOption" - element.className = element.className + " example info" - element.innerHTML = "Leave empty to reset this option." - - 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() - -initPopup = -> +initPopupPage = -> chrome.tabs.getSelected null, (tab) -> document.getElementById("optionsLink").setAttribute "href", chrome.runtime.getURL("pages/options.html") - updated = false onUpdated = -> - $("helpText").innerHTML = "Type <strong>Ctrl-Enter</strong> to save and close; <strong>Esc</strong> to cancel." - updated = true + $("helpText").innerHTML = + "Type <strong>Ctrl-Enter</strong> to save and close; <strong>Esc</strong> to cancel." document.addEventListener "keyup", (event) -> if event.ctrlKey and event.keyCode == 13 @@ -232,6 +230,6 @@ initPopup = -> # Initialization. document.addEventListener "DOMContentLoaded", -> switch location.pathname - when "/pages/options.html" then initOptions() - when "/pages/popup.html" then initPopup() + when "/pages/options.html" then initOptionsPage() + when "/pages/popup.html" then initPopupPage() diff --git a/pages/popup.html b/pages/popup.html index 726ecc3f..6c2dc2d0 100644 --- a/pages/popup.html +++ b/pages/popup.html @@ -69,7 +69,7 @@ <tr> <td id="footerTableData"> <span> - <span id="helpText">These are the matching exclusion rules for this page.</span> + <span id="helpText">These are the matching rules for this page.</span> <br/> <span> <a id="optionsLink" target="_blank">Vimium Options</a>.</span> </span> |
