From d5f877da89554d75f9b14e568fc35e2bdc0e555b Mon Sep 17 00:00:00 2001 From: Sylvester Johansson Date: Thu, 28 May 2009 01:24:35 +0200 Subject: again, minor fixes --- examples/scripts/linkfollow.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'examples') 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: -- cgit v1.2.3