aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGravatar Sylvester Johansson <scj@archlinux.us>2009-05-28 01:24:35 +0200
committerGravatar Sylvester Johansson <scj@archlinux.us>2009-05-28 01:34:12 +0200
commitd5f877da89554d75f9b14e568fc35e2bdc0e555b (patch)
tree2153aca271e659ce6d52d760aee2ee251c3a07aa /examples
parent2760e44099d43f0c2efbebd10e1ef85b8e20d200 (diff)
again, minor fixes
Diffstat (limited to 'examples')
-rw-r--r--examples/scripts/linkfollow.js41
1 files changed, 34 insertions, 7 deletions
diff --git a/examples/scripts/linkfollow.js b/examples/scripts/linkfollow.js
index 20a756f..5dbbd5b 100644
--- a/examples/scripts/linkfollow.js
+++ b/examples/scripts/linkfollow.js
@@ -14,7 +14,8 @@
// At the moment, it may be useful to have way of forcing uzbl to load the script
// bind :lf = script /usr/share/examples/scripts/linkfollow.js
//
-// To enable hint highlighting, add:
+// The default style for the hints are pretty ugly, so it is recommended to add the following
+// to config file
// set stylesheet_uri = /usr/share/uzbl/examples/data/style.css
//
// based on follow_Numbers.js
@@ -70,7 +71,8 @@ function Hints(){
return isVisible(el.parentNode);
}
- var hintable = "//a[@href] | //img | //input";
+ // the vimperator defaults minus the xhtml elements, since it gave DOM errors
+ var hintable = " //*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link'] | //input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select";
function Matcher(str){
var numbers = str.replace(/[^\d]/g,"");
@@ -179,10 +181,33 @@ function Hints(){
doc.body.removeAttribute("onkeyup");
}
}
+ this.openInNewWindow = function(item){
+ // TODO: this doesn't work
+ simulateMouseOver(item);
+ window.open(item.href,"uzbl new","");
+ }
+ this.openInThisWindow = function(item){
+ window.location = item.href;
+ }
- function follow(str){
- var m = new Matcher(str);
+// found on stackoverflow
+// function simulateMouseOver(item){
+// var evt = doc.createEvent("MouseEvents");
+// evt.initMouseEvent("mouseover",true,true,
+// doc.defaultView,0,0,0,0,0,
+// false,false,false,false,0,null);
+// var canceled = !item.dispatchEvent(evt);
+// if(canceled){
+// alert('Event Cancelled');
+// }
+// }
+
+ function follow(str,opener){
+ var m = new Matcher(str);
+ if(!opener){
+ var opener = this.openInThisWindow;
+ }
var items = visible.filter(function (n) { return n.isHinted });
clear();
var num = parseInt(m.numbers,10);
@@ -192,13 +217,15 @@ function Hints(){
var item = items[0].node;
}
if (item) {
+ item.style.margin -= 3;
+ item.style.padding -= 3;
item.style.borderStyle = "dotted";
item.style.borderWidth = "thin";
var name = item.tagName;
if (name == 'A') {
if(item.click) {item.click()};
- window.location = item.href;
+ opener(item);
} else if (name == 'INPUT') {
var type = item.getAttribute('type').toUpperCase();
if (type == 'TEXT' || type == 'FILE' || type == 'PASSWORD') {
@@ -212,7 +239,7 @@ function Hints(){
item.select();
} else {
item.click();
- window.location = item.href;
+ opener(item);
}
}
}
@@ -221,6 +248,6 @@ function Hints(){
var hints = new Hints();
//document.attachEvent("onKeyUp",hints.keyPressHandler);
-// vim:set et tw=2:
+// vim:set et sw=2: