From 486ba68a42e2ba7b96a7a14b0ae34aca7ac7e780 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sun, 19 Aug 2012 00:50:45 -0700 Subject: Convert options.js -> options/options.coffee. --- options/options.coffee | 90 ++++++++++++++++++++ options/options.html | 227 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 options/options.coffee create mode 100644 options/options.html (limited to 'options') diff --git a/options/options.coffee b/options/options.coffee new file mode 100644 index 00000000..6300dbcd --- /dev/null +++ b/options/options.coffee @@ -0,0 +1,90 @@ +$ = (id) -> document.getElementById id + +bgSettings = chrome.extension.getBackgroundPage().Settings + +editableFields = ["scrollStepSize", "excludedUrls", "linkHintCharacters", "userDefinedLinkHintCss", + "keyMappings", "filterLinkHints", "previousPatterns", "nextPatterns", "hideHud"] + +canBeEmptyFields = ["excludedUrls", "keyMappings", "userDefinedLinkHintCss"] + +postSaveHooks = keyMappings: (value) -> + commands = chrome.extension.getBackgroundPage().Commands + commands.clearKeyMappingsAndSetDefaults() + commands.parseCustomKeyMappings value + chrome.extension.getBackgroundPage().refreshCompletionKeysAfterMappingSave() + +document.addEventListener "DOMContentLoaded", -> + populateOptions() + + for field in editableFields + $(field).addEventListener "keyup", onOptionKeyup, false + $(field).addEventListener "change", enableSaveButton, false + $(field).addEventListener "change", onDataLoaded, false + + $("advancedOptions").addEventListener "click", openAdvancedOptions, false + $("showCommands").addEventListener "click", (-> + showHelpDialog chrome.extension.getBackgroundPage().helpDialogHtml(true, true, "Command Listing"), frameId + ), false + document.getElementById("restoreSettings").addEventListener "click", restoreToDefaults + document.getElementById("saveOptions").addEventListener "click", saveOptions + +onOptionKeyup = (event) -> + if (event.target.getAttribute("type") isnt "checkbox" and + event.target.getAttribute("savedValue") isnt event.target.value) + enableSaveButton() + +onDataLoaded = -> + $("linkHintCharacters").readOnly = $("filterLinkHints").checked + +enableSaveButton = -> + $("saveOptions").removeAttribute "disabled" + +# Saves options to localStorage. +saveOptions = -> + + # If the value is unchanged from the default, delete the preference from localStorage; this gives us + # the freedom to change the defaults in the future. + for fieldName in editableFields + field = $(fieldName) + if field.getAttribute("type") is "checkbox" + fieldValue = field.checked + else + fieldValue = field.value.trim() + field.value = fieldValue + + # If it's empty and not a field that we allow to be empty, restore to the default value + if not fieldValue and canBeEmptyFields.indexOf(fieldName) is -1 + bgSettings.clear fieldName + fieldValue = bgSettings.get(fieldName) + else + bgSettings.set fieldName, fieldValue + $(fieldName).value = fieldValue + $(fieldName).setAttribute "savedValue", fieldValue + postSaveHooks[fieldName] fieldValue if postSaveHooks[fieldName] + + $("saveOptions").disabled = true + +# Restores select box state to saved value from localStorage. +populateOptions = -> + for field in editableFields + val = bgSettings.get(field) or "" + setFieldValue $(field), val + onDataLoaded() + +restoreToDefaults = -> + for field in editableFields + val = bgSettings.defaults[field] or "" + setFieldValue $(field), val + onDataLoaded() + enableSaveButton() + +setFieldValue = (field, value) -> + unless field.getAttribute("type") is "checkbox" + field.value = value + field.setAttribute "savedValue", value + +openAdvancedOptions = (event) -> + elements = document.getElementsByClassName("advancedOption") + for element in elements + element.style.display = (if (element.style.display is "table-row") then "none" else "table-row") + event.preventDefault() diff --git a/options/options.html b/options/options.html new file mode 100644 index 00000000..93a402fb --- /dev/null +++ b/options/options.html @@ -0,0 +1,227 @@ + +
+| Scroll step size | ++ px + | +|
|
+ Excluded URLs +
+
+
+
+ e.g. http*://mail.google.com/*
+ + This will disable Vimium on Gmail. + Enter one URL per line. + |
+ ||
| + Advanced options » + | +||
| Custom key mappings |
+
+
+
+
+
+
+ Enter commands to remap your keys. Available commands:
+ +
+ map j scrollDown
+ Show available commands.
+ + unmap j + unmapAll + " this is a comment + # this is also a comment + |
+ |
| Characters used for link hints |
+
+
+
+
+
+ The characters placed next to each link after typing "F" to enter link hinting mode.
+
+ |
+ |
| CSS for link hints | +
+
+
+
+
+ The CSS used to style the characters next to each link hint.
+ + Note: these styles are used in addition to and take precedence over Vimium's + default styles. + |
+ |
| + |
+
+
+
+
+ After typing "F" to enter link hinting mode, this option lets you type the text of a link
+ to select it.
+
+ |
+ |
| + |
+
+
+
+
+ The Heads-Up Display appears when typing into text boxes.
+
+ |
+ |
| Previous Patterns | +
+
+
+
+
+ Vimium will match against these patterns when using the "navigate to the previous page"
+ command.
+
+ |
+ |
| Next Patterns | +
+
+
+
+
+ Vimium will match against these patterns when using the "navigate to the next page" command.
+
+ |
+ |