diff options
| author | Stephen Blott | 2014-09-01 12:07:24 +0100 |
|---|---|---|
| committer | Stephen Blott | 2014-09-02 08:43:36 +0100 |
| commit | 41bdac83d2fd450569013dd5cfdb78239143ba24 (patch) | |
| tree | 58c06e564cb5641102fbc6583071e84e094818f7 /lib | |
| parent | 1685640ccabe265c9f182a0175d8ce823db35b4b (diff) | |
| download | vimium-41bdac83d2fd450569013dd5cfdb78239143ba24.tar.bz2 | |
Structured passkeys, internally and on the options and popup pages.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/exclusion_rule.coffee | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/exclusion_rule.coffee b/lib/exclusion_rule.coffee new file mode 100644 index 00000000..0942e7cf --- /dev/null +++ b/lib/exclusion_rule.coffee @@ -0,0 +1,46 @@ +root = exports ? window + +# Operations to build the DOM on the options page for a single exclusion rule. + +root.ExclusionRule = + + # Build a DOM table row (a "tr") for this rule. + buildRuleElement: (rule,enableSaveButton) -> + pattern = @buildInput(enableSaveButton,rule.pattern,"URL pattern","pattern") + passKeys = @buildInput(enableSaveButton,rule.passKeys,"Excluded keys","passKeys") + row = document.createElement("tr") + row.className = "exclusionRow" + remove = document.createElement("input") + remove.type = "button" + remove.value = "\u2716" # A cross. + remove.className = "exclusionRemoveButton" + remove.addEventListener "click", -> + row.parentNode.removeChild(row) + enableSaveButton() + row.appendChild(pattern) + row.appendChild(passKeys) + row.appendChild(remove) + # NOTE: Since the order of exclusions matters, it would be nice to have "Move Up" and "Move Down" buttons, + # too. But this option is pretty cluttered already. + row + + # Build DOM (a "td" containing an "input") for a single input element. + buildInput: (enableSaveButton,value,placeholder,cls) -> + input = document.createElement("input") + input.setAttribute("placeholder",placeholder) + input.type = "text" + input.value = value + input.className = cls + input.addEventListener "keyup", enableSaveButton, false + input.addEventListener "change", enableSaveButton, false + container = document.createElement("td") + container.appendChild(input) + container + + # Build a new exclusion rule from the given element. This is the reverse of the two methods above. + extractRule: (element) -> + patternElement = element.firstChild + passKeysElement = patternElement.nextSibling + pattern = patternElement.firstChild.value.trim() + passKeys = passKeysElement.firstChild.value.trim() + if pattern then { pattern: pattern, passKeys: passKeys } else null |
