aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/data
diff options
context:
space:
mode:
authorGravatar keis <keijser@gmail.com>2011-07-28 22:31:30 +0200
committerGravatar keis <keijser@gmail.com>2011-07-28 22:31:30 +0200
commitdb61f092140205e71f40fb14dc98a1e650c7e527 (patch)
tree6a2459ae08c6baa4875b1db226dc7eb615a3cd3c /examples/data
parent1e20430333aee952f55f6caec4d55238a0160bf9 (diff)
parente035f6f991fdbe9862a72fba6e8d348dcc25532f (diff)
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into mouse-events
Diffstat (limited to 'examples/data')
-rw-r--r--examples/data/scripts/follow.js40
-rwxr-xr-xexamples/data/scripts/follow.sh22
-rw-r--r--examples/data/scripts/formfiller.js35
-rwxr-xr-xexamples/data/scripts/formfiller.sh16
-rw-r--r--examples/data/scripts/util/uzbl-dir.sh14
5 files changed, 90 insertions, 37 deletions
diff --git a/examples/data/scripts/follow.js b/examples/data/scripts/follow.js
index b7b0d82..5ecdcef 100644
--- a/examples/data/scripts/follow.js
+++ b/examples/data/scripts/follow.js
@@ -16,7 +16,16 @@ uzbldivid = 'uzbl_link_hints';
uzbl.follow = function() {
// Export
charset = arguments[0];
- newwindow = arguments[2];
+ if (arguments[2] == 0 || arguments[2] == 'click') {
+ newwindow = false;
+ returnuri = false;
+ } else if (arguments[2] == 1 || arguments[2] == 'newwindow') {
+ newwindow = true;
+ returnuri = false;
+ } else if (arguments[2] == 'returnuri') {
+ newwindow = false;
+ returnuri = true;
+ }
var keypress = arguments[1];
return arguments.callee.followLinks(keypress);
@@ -126,19 +135,19 @@ uzbl.follow.generateHint = function(doc, el, label, top, left) {
// but at least set the href of the link. (needs some improvements)
uzbl.follow.clickElem = function(item) {
if(!item) return;
- var name = item.tagName;
- if (name == 'INPUT') {
- var type = item.getAttribute('type').toUpperCase();
- if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') {
+ 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.
- } else if (name == 'TEXTAREA' || name == 'SELECT') {
+ } else if (item instanceof HTMLTextAreaElement || item instanceof HTMLSelectElement) {
item.focus();
- item.select();
+ if(typeof item.select != 'undefined')
+ item.select();
return "XXXEMIT_FORM_ACTIVEXXX";
}
@@ -169,9 +178,13 @@ uzbl.follow.reDrawHints = function(elems, chars) {
elements.forEach(function(el, i) {
var label = labels[i];
var pos = positions[i];
- var doc = uzbl.follow.getDocument(el);
- var h = uzbl.follow.generateHint(doc, el, label, pos[0], pos[1]);
- doc.hintdiv.appendChild(h);
+ try {
+ var doc = uzbl.follow.getDocument(el);
+ var h = uzbl.follow.generateHint(doc, el, label, pos[0], pos[1]);
+ doc.hintdiv.appendChild(h);
+ } catch (err) {
+ // Unable to attach label -> shrug it off and continue
+ }
});
}
@@ -222,7 +235,7 @@ uzbl.follow.followLinks = function(follow) {
//var desc = '*[title], img[alt], applet[alt], area[alt], input[alt]';
//var image = 'img, input[type=image]';
- if(newwindow)
+ if(newwindow || returnuri)
var res = this.query(uri);
else
var res = this.query(followable);
@@ -237,6 +250,11 @@ uzbl.follow.followLinks = function(follow) {
// clear all of our hints
this.clearHints();
+ if (returnuri) {
+ var uri = el.src || el.href;
+ return "XXXRETURNED_URIXXX" + uri
+ }
+
if (newwindow) {
// we're opening a new window using the URL attached to this element
var uri = el.src || el.href;
diff --git a/examples/data/scripts/follow.sh b/examples/data/scripts/follow.sh
index 014793e..30d3775 100755
--- a/examples/data/scripts/follow.sh
+++ b/examples/data/scripts/follow.sh
@@ -1,13 +1,31 @@
#!/bin/sh
# This scripts acts on the return value of followLinks in follow.js
-case "$1" in
+result=$1
+shift
+
+uriaction=$1
+shift
+
+case "$result" in
XXXEMIT_FORM_ACTIVEXXX)
# a form element was selected
- printf 'event FORM_ACTIVE\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
+ printf 'event KEYCMD_CLEAR\n' > "$UZBL_FIFO"
;;
XXXRESET_MODEXXX)
# a link was selected, reset uzbl's input mode
printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
;;
+ XXXRETURNED_URIXXX*)
+ uri=${result#XXXRETURNED_URIXXX}
+
+ case "$uriaction" in
+ set)
+ printf 'uri '"$uri"'\n' | sed -e 's/@/\\@/' > "$UZBL_FIFO"
+ ;;
+ clipboard)
+ printf "$uri" | xclip
+ ;;
+ esac
+ printf 'set mode=\nevent KEYCMD_CLEAR\n' > "$UZBL_FIFO"
esac
diff --git a/examples/data/scripts/formfiller.js b/examples/data/scripts/formfiller.js
index abf0162..a5fc9ee 100644
--- a/examples/data/scripts/formfiller.js
+++ b/examples/data/scripts/formfiller.js
@@ -1,24 +1,37 @@
uzbl.formfiller = {
+ inputTypeIsText: function(type) {
+ var types = [ '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;
+ }
+
+ ,
+
dump: function() {
var rv = '';
var allFrames = new Array(window);
- for ( f=0; f<window.frames.length; ++f ) {
+
+ for ( var f = 0; f < window.frames.length; ++f ) {
allFrames.push(window.frames[f]);
}
- for ( j=0; j<allFrames.length; ++j ) {
+
+ for ( var j = 0; j < allFrames.length; ++j ) {
try {
var xp_res = allFrames[j].document.evaluate(
'//input', allFrames[j].document.documentElement, null, XPathResult.ANY_TYPE,null
);
var input;
while ( input = xp_res.iterateNext() ) {
- var type = (input.type?input.type:text);
- if ( type == 'text' || type == 'password' || type == 'search' ) {
- rv += '%' + escape(input.name) + '(' + type + '):' + input.value + '\n';
- }
- else if ( type == 'checkbox' || type == 'radio' ) {
- rv += '%' + escape(input.name) + '(' + type + '){' + escape(input.value) + '}:' + (input.checked?'1':'0') + '\n';
+ if ( inputTypeIsText(input.type) ) {
+ rv += '%' + escape(input.name) + '(' + input.type + '):' + input.value + '\n';
+ } else if ( input.type == 'checkbox' || input.type == 'radio' ) {
+ rv += '%' + escape(input.name) + '(' + input.type + '){' + escape(input.value) + '}:' + (input.checked?'1':'0') + '\n';
}
}
xp_res = allFrames[j].document.evaluate(
@@ -39,12 +52,12 @@ uzbl.formfiller = {
insert: function(fname, ftype, fvalue, fchecked) {
fname = unescape(fname);
var allFrames = new Array(window);
- for ( f=0; f<window.frames.length; ++f ) {
+ for ( var f = 0; f < window.frames.length; ++f ) {
allFrames.push(window.frames[f]);
}
- for ( j=0; j<allFrames.length; ++j ) {
+ for ( var j = 0; j < allFrames.length; ++j ) {
try {
- if ( ftype == 'text' || ftype == 'password' || ftype == 'search' || ftype == 'textarea' ) {
+ if ( uzbl.formfiller.inputTypeIsText(ftype) || ftype == 'textarea' ) {
allFrames[j].document.getElementsByName(fname)[0].value = fvalue;
}
else if ( ftype == 'checkbox' ) {
diff --git a/examples/data/scripts/formfiller.sh b/examples/data/scripts/formfiller.sh
index c1171a0..394bfbd 100755
--- a/examples/data/scripts/formfiller.sh
+++ b/examples/data/scripts/formfiller.sh
@@ -39,7 +39,10 @@ GenForm ()
GetOption ()
{
DMENU_SCHEME=formfiller
- DMENU_PROMPT="choose profile"
+
+ # util/dmenu.sh doesn't handle spaces in DMENU_PROMPT. a proper fix will be
+ # tricky.
+ DMENU_PROMPT="choose_profile"
DMENU_LINES=4
. "$UZBL_UTIL_DIR/dmenu.sh"
@@ -66,11 +69,7 @@ ParseFields ()
field = $0
sub ( /[^:]*:/, "", field )
- if ( parts[2] ~ /^(text|password|search)$/ )
- printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
- parts[1], parts[2], field )
-
- else if ( parts[2] ~ /^(checkbox|radio)$/ )
+ if ( parts[2] ~ /^(checkbox|radio)$/ )
printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",%s);\n",
parts[1], parts[2], parts[3], field )
@@ -87,6 +86,11 @@ ParseFields ()
parts[1], parts[2], field )
}
+ else
+ printf( "js uzbl.formfiller.insert(\"%s\",\"%s\",\"%s\",0);\n",
+ parts[1], parts[2], field )
+
+
}'
}
diff --git a/examples/data/scripts/util/uzbl-dir.sh b/examples/data/scripts/util/uzbl-dir.sh
index 82510d8..76a7055 100644
--- a/examples/data/scripts/util/uzbl-dir.sh
+++ b/examples/data/scripts/util/uzbl-dir.sh
@@ -9,12 +9,12 @@ UZBL_SOCKET_DIR=/tmp
# Directories
UZBL_DOWNLOAD_DIR="${XDG_DOWNLOAD_DIR:-$HOME}"
-UZBL_FORMS_DIR="$UZBL_DATA_DIR/dforms"
+UZBL_FORMS_DIR="${UZBL_FORMS_DIR:-$UZBL_DATA_DIR/dforms}"
# Data files
-UZBL_CONFIG_FILE="$UZBL_CONFIG_DIR/config"
-UZBL_COOKIE_FILE="$UZBL_DATA_DIR/cookies.txt"
-UZBL_BOOKMARKS_FILE="$UZBL_DATA_DIR/bookmarks"
-UZBL_TEMPS_FILE="$UZBL_DATA_DIR/temps"
-UZBL_HISTORY_FILE="$UZBL_DATA_DIR/history"
-UZBL_SESSION_FILE="$UZBL_DATA_DIR/browser-session"
+UZBL_CONFIG_FILE="${UZBL_CONFIG_FILE:-$UZBL_CONFIG_DIR/config}"
+UZBL_COOKIE_FILE="${UZBL_COOKIE_FILE:-$UZBL_DATA_DIR/cookies.txt}"
+UZBL_BOOKMARKS_FILE="${UZBL_BOOKMARKS_FILE:-$UZBL_DATA_DIR/bookmarks}"
+UZBL_TEMPS_FILE="${UZBL_TEMPS_FILE:-$UZBL_DATA_DIR/temps}"
+UZBL_HISTORY_FILE="${UZBL_HISTORY_FILE:-$UZBL_DATA_DIR/history}"
+UZBL_SESSION_FILE="${UZBL_SESSION_FILE:-$UZBL_DATA_DIR/browser-session}"