aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormrmr19932014-10-12 18:28:20 +0100
committermrmr19932014-11-05 22:37:16 +0000
commit6d3d88831e06e9822d67991b9dcd85382a41fe69 (patch)
treee6afa6dcc1daf0a1b720e1766aacca2565d77ab4 /lib
parentd1cf578ea33202c5b94c8a596c254b2ab6eee5da (diff)
downloadvimium-6d3d88831e06e9822d67991b9dcd85382a41fe69.tar.bz2
Add support for selecting HTML5 inputs, change criterion to a blacklist
This is designed to address several issues: * `<input type="range" />` elements don't respond well to the simulated click; they always reset their value to the minimum. * The lack of `mouseup` event from the simulated click makes `<input type="range />` elements slide when the mouse is moved. * HTML5 adds a large number of text-based `<input>`s that should be focused like the `type="text"` case, for consistency. (Using a blacklist halves the number of types we have to list.) * An `<input>` with a `type` the browser doesn't support is rendered as a `type="text"`, so a blacklist ensures that the focusing action is consistent on all elements behaving as `type="text"`.
Diffstat (limited to 'lib')
-rw-r--r--lib/dom_utils.coffee7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 62e655e7..7735f62b 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -94,14 +94,15 @@ DomUtils =
# Selectable means the element has a text caret; this is not the same as "focusable".
#
isSelectable: (element) ->
- selectableTypes = ["search", "text", "password"]
- (element.nodeName.toLowerCase() == "input" && selectableTypes.indexOf(element.type) >= 0) ||
+ unselectableTypes = ["button", "checkbox", "color", "file", "hidden", "image", "radio", "reset"]
+ (element.nodeName.toLowerCase() == "input" && unselectableTypes.indexOf(element.type) == -1) ||
element.nodeName.toLowerCase() == "textarea"
simulateSelect: (element) ->
element.focus()
# When focusing a textbox, put the selection caret at the end of the textbox's contents.
- element.setSelectionRange(element.value.length, element.value.length)
+ # For some HTML5 input types (eg. date) we can't position the caret, so we wrap this with a try.
+ try element.setSelectionRange(element.value.length, element.value.length)
simulateClick: (element, modifiers) ->
modifiers ||= {}