From 4bb5c202f366bb1818054ceaa89474545344d554 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Mon, 26 Sep 2011 18:28:43 +0000 Subject: fix following input[type=email], [type=search], etc. --- examples/data/scripts/follow.js | 32 +++++++++++++++++++------------- examples/data/scripts/follow.sh | 6 +++--- examples/data/scripts/formfiller.js | 16 +++++++++------- examples/data/scripts/go_input.js | 2 +- examples/data/scripts/go_input.sh | 4 ++-- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js index 2b4fcd0..45ecfc6 100644 --- a/examples/data/scripts/follow.js +++ b/examples/data/scripts/follow.js @@ -138,26 +138,32 @@ uzbl.follow.generateHint = function(doc, el, label, top, left) { return hint; } -// Here we choose what to do with an element if we -// want to "follow" it. On form elements we "select" -// or pass the focus, on links we try to perform a click, -// but at least set the href of the link. (needs some improvements) +// this is pointlessly duplicated in uzbl.formfiller +uzbl.follow.textInputTypes = [ + 'text', 'password', 'search', 'email', 'url', 'number', 'range', 'color', + 'date', 'month', 'week', 'time', 'datetime', 'datetime-local' +]; + +// this is pointlessly duplicated in uzbl.formfiller +uzbl.follow.inputTypeIsText = function(type) { + return uzbl.follow.textInputTypes.indexOf(type) >= 0; +} + +// Here we choose what to do with an element that's been selected. +// On text form elements we focus and select the content. On other +// elements we simulate a mouse click. uzbl.follow.clickElem = function(item) { if(!item) return; - if (item instanceof HTMLInputElement) { - var type = item.type; - if (type == 'text' || type == 'file' || type == 'password') { - item.focus(); - item.select(); - return "XXXEMIT_FORM_ACTIVEXXX"; - } - // otherwise fall through to a simulated mouseclick. + if (item instanceof HTMLInputElement && uzbl.follow.inputTypeIsText(item.type)) { + item.focus(); + item.select(); + return "XXXFORM_ACTIVEXXX"; } else if (item instanceof HTMLTextAreaElement || item instanceof HTMLSelectElement) { item.focus(); if(typeof item.select != 'undefined') item.select(); - return "XXXEMIT_FORM_ACTIVEXXX"; + return "XXXFORM_ACTIVEXXX"; } // simulate a mouseclick to activate the element diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh index 8ae095c..01e92db 100755 --- a/examples/data/scripts/follow.sh +++ b/examples/data/scripts/follow.sh @@ -1,13 +1,13 @@ #!/bin/sh -# This scripts acts on the return value of followLinks in follow.js +# This scripts acts on the return value of followLinks in follow.js result=$1 shift case "$result" in - XXXEMIT_FORM_ACTIVEXXX) + XXXFORM_ACTIVEXXX) # a form element was selected - printf 'event KEYCMD_CLEAR\n' > "$UZBL_FIFO" + echo 'event KEYCMD_CLEAR' > "$UZBL_FIFO" ;; XXXRESET_MODEXXX) # a link was selected, reset uzbl's input mode diff --git a/examples/data/scripts/formfiller.js b/examples/data/scripts/formfiller.js index 4470661..1b10db4 100644 --- a/examples/data/scripts/formfiller.js +++ b/examples/data/scripts/formfiller.js @@ -1,14 +1,16 @@ uzbl.formfiller = { - inputTypeIsText: function(type) { - var types = [ 'text', 'password', 'search', 'email', 'url', - 'number', 'range', 'color', 'date', 'month', - 'week', 'time', 'datetime', 'datetime-local' ]; + // this is pointlessly duplicated in uzbl.follow + textInputTypes: [ + 'text', 'password', 'search', 'email', 'url', 'number', 'range', 'color', + 'date', 'month', 'week', 'time', 'datetime', 'datetime-local' + ] - for(var i = 0; i < types.length; ++i) - if(types[i] == type) return true; + , - return false; + // this is pointlessly duplicated in uzbl.follow + inputTypeIsText: function(type) { + return uzbl.formfiller.textInputTypes.indexOf(type) >= 0; } , diff --git a/examples/data/scripts/go_input.js b/examples/data/scripts/go_input.js index 557671f..fedbd90 100644 --- a/examples/data/scripts/go_input.js +++ b/examples/data/scripts/go_input.js @@ -18,7 +18,7 @@ function gi() { else { el.focus(); } - return "XXXEMIT_FORM_ACTIVEXXX"; + return "XXXFORM_ACTIVEXXX"; } } } diff --git a/examples/data/scripts/go_input.sh b/examples/data/scripts/go_input.sh index 9797788..973ae4f 100755 --- a/examples/data/scripts/go_input.sh +++ b/examples/data/scripts/go_input.sh @@ -1,7 +1,7 @@ #!/bin/sh case "$( echo "script @scripts_dir/go_input.js" | socat - "unix-connect:$UZBL_SOCKET" )" in - *XXXEMIT_FORM_ACTIVEXXX*) - echo "event FORM_ACTIVE" > "$UZBL_FIFO" + *XXXFORM_ACTIVEXXX*) + echo 'event KEYCMD_CLEAR' > "$UZBL_FIFO" ;; esac -- cgit v1.2.3