aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dom_utils.coffee
diff options
context:
space:
mode:
authorStephen Blott2014-12-14 07:42:07 +0000
committerStephen Blott2014-12-14 07:42:07 +0000
commit1f54f9b6892fd92af419bfa29f986a4c8614013e (patch)
tree7668bdeda8ab6456d27bf1fdf25dae8df66105d9 /lib/dom_utils.coffee
parentd69f17ce906e93c15775ce31273556613276b2e5 (diff)
parente826484584f1c599e2f733765fef34e080bbcb89 (diff)
downloadvimium-1f54f9b6892fd92af419bfa29f986a4c8614013e.tar.bz2
Merge branch 'add-html5-input-types' of https://github.com/mrmr1993/vimium into mrmr1993-add-html5-input-types
Diffstat (limited to 'lib/dom_utils.coffee')
-rw-r--r--lib/dom_utils.coffee14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index 21018049..dfaa5d5f 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -91,17 +91,23 @@ DomUtils =
null
#
- # Selectable means the element has a text caret; this is not the same as "focusable".
+ # Selectable means that we should use the simulateSelect method to activate the element instead of a click.
+ #
+ # The html5 input types that should use simulateSelect are:
+ # ["date", "datetime", "datetime-local", "email", "month", "number", "password", "range", "search",
+ # "submit", "tel", "text", "time", "url", "week"]
+ # An unknown type will be treated the same as "text", in the same way that the browser does.
#
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 ||= {}