aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
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
parent1e20430333aee952f55f6caec4d55238a0160bf9 (diff)
parente035f6f991fdbe9862a72fba6e8d348dcc25532f (diff)
Merge branch 'experimental' of git://github.com/Dieterbe/uzbl into mouse-events
Diffstat (limited to 'examples')
-rw-r--r--examples/config/config20
-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
6 files changed, 101 insertions, 46 deletions
diff --git a/examples/config/config b/examples/config/config
index 8c706df..385a60b 100644
--- a/examples/config/config
+++ b/examples/config/config
@@ -83,7 +83,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh
@on_event LOAD_FINISH spawn @scripts_dir/history.sh
# Switch to insert mode if a (editable) html form is clicked
-@on_event FORM_ACTIVE @set_mode insert
+@on_event FOCUS_ELEMENT sh 'if [ "$1" = INPUT -o "$1" = TEXTAREA -o "$1" = SELECT ]; then echo "@set_mode insert" > $UZBL_FIFO; fi' %s
# Switch to command mode if anything else is clicked
@on_event ROOT_ACTIVE @set_mode command
@@ -91,7 +91,7 @@ set download_handler = sync_spawn @scripts_dir/download.sh
#@on_event CONFIG_CHANGED print Config changed: %1 = %2
# Scroll percentage calculation
-@on_event SCROLL_VERT set scroll_message = \@<(function(){var p='--';if(%3<=%4){p=(%1/(%3-%4));p=Math.round(10000*p)/100;};return p+'%';})()>\@
+@on_event SCROLL_VERT set scroll_message = \@<(function(curr, min, max, size){if(max == size) return '--'; var p=(curr/(max - size)); return Math.round(10000*p)/100;})(%1,%2,%3,%4)>\@%
# === Behaviour and appearance ===============================================
@@ -265,8 +265,8 @@ set ebind = @mode_bind global,-insert
@cbind n = search
@cbind N = search_reverse
-# Print pages to a printer
-@cbind  <Ctrl>p = hardcopy
+# Print pages to a printer
+@cbind <Ctrl>p = hardcopy
# Web searching binds
@cbind gg<Google:>_ = uri http://www.google.com/search?q=\@<encodeURIComponent(%r)>\@
@@ -310,7 +310,7 @@ set ebind = @mode_bind global,-insert
# Yanking & pasting binds
@cbind yu = sh 'echo -n "$UZBL_URI" | xclip'
-@cbind yU = sh 'echo -n "$1" | xclip' \@SELECTED_URI
+@cbind yU = sh 'echo -n "$1" | xclip' '\@SELECTED_URI'
@cbind yy = sh 'echo -n "$UZBL_TITLE" | xclip'
# Clone current window
@@ -325,9 +325,9 @@ set ebind = @mode_bind global,-insert
@bind <Shift><Insert> = sh 'echo "event INJECT_KEYCMD $(xclip -o | sed s/\\\@/%40/g)" > "$UZBL_FIFO"'
# Bookmark inserting binds
-@cbind <Ctrl>b<tags:>_ = sh 'echo `printf "$UZBL_URI %s"` >> "$XDG_DATA_HOME"/uzbl/bookmarks'
+@cbind <Ctrl>m<tags:>_ = sh 'echo "$UZBL_URI $1" >> "$XDG_DATA_HOME"/uzbl/bookmarks' '%s'
# Or use a script to insert a bookmark.
-@cbind B = spawn @scripts_dir/insert_bookmark.sh
+@cbind M = spawn @scripts_dir/insert_bookmark.sh
# Bookmark/history loading
@cbind U = spawn @scripts_dir/load_url_from_history.sh
@@ -343,8 +343,10 @@ set follow_hint_keys = 0123456789
#set follow_hint_keys = qwerty
#set follow_hint_keys = asdfghjkl;
#set follow_hint_keys = thsnd-rcgmvwb/;789aefijkopquxyz234
-@cbind fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 0) >\@
-@cbind Fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 1) >\@
+@cbind fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 'click') >\@
+@cbind Fl* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 'newwindow') >\@
+@cbind fL* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 'returnuri') >\@ set
+@cbind FL* = spawn @scripts_dir/follow.sh \@< uzbl.follow("\@follow_hint_keys", "%s", 'returnuri') >\@ clipboard
@cbind fi = spawn @scripts_dir/go_input.sh
# Form filler binds
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}"