From: Daniel Carl Date: Sat, 4 Jan 2014 16:40:15 +0000 (+0100) Subject: Fixed hints not opened in new window on duckduckgo (#59). X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=54456124f4997cdca50bf4bb6927185787c0a6cb;p=vimb.git Fixed hints not opened in new window on duckduckgo (#59). There are some pages that use mouse event observers that open link href programmatic and ignore the target attribute that vimb uses to open link into new window. So this patch fires the click related mouse events with the additional set CTRL key that is considered by those scripts and also other browsers to open the resource into new window. --- diff --git a/src/hints.js b/src/hints.js index 666c8e6..95315af 100644 --- a/src/hints.js +++ b/src/hints.js @@ -295,7 +295,10 @@ var VbHint = (function(){ } else if (e.target === "_blank") { e.removeAttribute("target"); } - click(e); + /* to open links in new window the mouse events are fired with ctrl */ + /* key - otherwise some ugly pages will ignore this attribute in their */ + /* mouse event observers like duckduckgo */ + click(e, newWin); e.target = oldTarget; } @@ -328,16 +331,20 @@ var VbHint = (function(){ return hints[i] || null; } - function click(e) { - mouseEvent(e, "mouseover"); - mouseEvent(e, "mousedown"); - mouseEvent(e, "mouseup"); - mouseEvent(e, "click"); + function click(e, ctrl) { + mouseEvent(e, "mouseover", ctrl); + mouseEvent(e, "mousedown", ctrl); + mouseEvent(e, "mouseup", ctrl); + mouseEvent(e, "click", ctrl); } - function mouseEvent(e, name) { + function mouseEvent(e, name, ctrl) { var evObj = e.ownerDocument.createEvent("MouseEvents"); - evObj.initMouseEvent(name, true, true, e.contentWindow, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + evObj.initMouseEvent( + name, true, true, e.contentWindow, + 0, 0, 0, 0, 0, + ctrl !== undefined ? ctrl : false, false, false, false, 0, null + ); e.dispatchEvent(evObj); }