mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 23:37:58 +01:00
made followLink() a function in vimperator.buffer. so also other modules can use it
This commit is contained in:
@@ -192,6 +192,38 @@ vimperator.Buffer = function () //{{{
|
||||
return result;
|
||||
},
|
||||
|
||||
// artificially "clicks" a link in order to open it
|
||||
followLink: function (elem, where, offsetX, offsetY)
|
||||
{
|
||||
var doc = window.content.document;
|
||||
var view = window.document.defaultView;
|
||||
//var view = doc.defaultView;
|
||||
offsetX = offsetX || 1;
|
||||
offsetY = offsetY || 1;
|
||||
|
||||
var new_tab = false, new_window = false;
|
||||
switch (where)
|
||||
{
|
||||
case vimperator.NEW_TAB:
|
||||
case vimperator.NEW_BACKGROUND_TAB:
|
||||
new_tab = true;
|
||||
break;
|
||||
case vimperator.NEW_WINDOW:
|
||||
new_window = true;
|
||||
break;
|
||||
default:
|
||||
vimperator.log("Invalid where argument for followLink()");
|
||||
}
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("mousedown", true, true, view, 1, offsetX, offsetY, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
//var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("click", true, true, view, 1, offsetX, offsetY, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
},
|
||||
|
||||
// in contrast to vim, returns the selection if one is made,
|
||||
// otherwise tries to guess the current word unter the text cursor
|
||||
// NOTE: might change the selection
|
||||
|
||||
@@ -72,12 +72,12 @@ vimperator.Hints = function () //{{{
|
||||
|
||||
// this function 'click' an element, which also works
|
||||
// for javascript links
|
||||
function openHint(new_tab, new_window)
|
||||
function openHint(where)
|
||||
{
|
||||
if (valid_hints.length < 1)
|
||||
return false;
|
||||
|
||||
var x = 0, y = 0;
|
||||
var x = 1, y = 1;
|
||||
var elem = valid_hints[hintNumber - 1] || valid_hints[0];
|
||||
var elemTagName = elem.localName.toLowerCase();
|
||||
elem.focus();
|
||||
@@ -88,20 +88,11 @@ vimperator.Hints = function () //{{{
|
||||
if (elemTagName == "area")
|
||||
{
|
||||
var coords = elem.getAttribute("coords").split(",");
|
||||
x = Number(coords[0]);
|
||||
y = Number(coords[1]);
|
||||
x = Number(coords[0]) + 1;
|
||||
y = Number(coords[1]) + 1;
|
||||
}
|
||||
var doc = window.content.document;
|
||||
var view = window.document.defaultView;
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("mousedown", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
var evt = doc.createEvent("MouseEvents");
|
||||
evt.initMouseEvent("click", true, true, view, 1, x + 1, y + 1, 0, 0, /*ctrl*/ new_tab, /*event.altKey*/0, /*event.shiftKey*/ new_window, /*event.metaKey*/ new_tab, 0, null);
|
||||
elem.dispatchEvent(evt);
|
||||
|
||||
vimperator.buffer.followLink(elem, where, x, y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -441,11 +432,11 @@ vimperator.Hints = function () //{{{
|
||||
case ";": focusHint(); break;
|
||||
case "a": saveHint(false); break;
|
||||
case "s": saveHint(true); break;
|
||||
case "o": openHint(false, false); break;
|
||||
case "o": openHint(vimperator.CURRENT_TAB); break;
|
||||
case "O": vimperator.commandline.open(":", "open " + loc, vimperator.modes.EX); break;
|
||||
case "t": openHint(true, false); break;
|
||||
case "t": openHint(vimperator.NEW_TAB); break;
|
||||
case "T": vimperator.commandline.open(":", "tabopen " + loc, vimperator.modes.EX); break;
|
||||
case "w": openHint(false, true); break;
|
||||
case "w": openHint(vimperator.NEW_WINDOW); break;
|
||||
case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break;
|
||||
case "y": yankHint(false); break;
|
||||
case "Y": yankHint(true); break;
|
||||
|
||||
@@ -50,7 +50,7 @@ const vimperator = (function () //{{{
|
||||
get mode() { return vimperator.modes.main; },
|
||||
set mode(value) { vimperator.modes.main = value; },
|
||||
|
||||
// Global contants
|
||||
// Global constants
|
||||
CURRENT_TAB: 1,
|
||||
NEW_TAB: 2,
|
||||
NEW_BACKGROUND_TAB: 3,
|
||||
|
||||
Reference in New Issue
Block a user