mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-07 01:04:12 +01:00
follow next/previous document relationships specified with link elements
(Raimon Grau Cusc�
This commit is contained in:
@@ -583,7 +583,7 @@ vimperator.Buffer = function () //{{{
|
|||||||
|
|
||||||
if (data.length - 1)
|
if (data.length - 1)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < data.length - 1 ; i++)
|
for (var i = 0; i < data.length - 1; i++)
|
||||||
ret += "<tr><td style='font-weight: bold; min-width: 150px'> " + data[i][0] + ": </td><td>" + data[i][1] + "</td></tr>";
|
ret += "<tr><td style='font-weight: bold; min-width: 150px'> " + data[i][0] + ": </td><td>" + data[i][1] + "</td></tr>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -773,37 +773,62 @@ vimperator.Buffer = function () //{{{
|
|||||||
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
|
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
|
||||||
},
|
},
|
||||||
|
|
||||||
followDocumentRelation: function (relation)
|
followDocumentRelationship: function (relationship)
|
||||||
{
|
{
|
||||||
var regexps;
|
var regexps;
|
||||||
var relText;
|
var relText;
|
||||||
var patternText;
|
var patternText;
|
||||||
switch (relation)
|
switch (relationship)
|
||||||
{
|
{
|
||||||
case "next":
|
case "next":
|
||||||
regexps = vimperator.options["nextpattern"].split(",");
|
regexps = vimperator.options["nextpattern"].split(",");
|
||||||
relText = "next";
|
break;
|
||||||
break;
|
|
||||||
case "previous":
|
case "previous":
|
||||||
//TODO: accept prev\%[ious]
|
//TODO: accept prev\%[ious]
|
||||||
regexps = vimperator.options["previouspattern"].split(",");
|
regexps = vimperator.options["previouspattern"].split(",");
|
||||||
relText = "previous";
|
break;
|
||||||
break;
|
default:
|
||||||
default: vimperator.echoerr("bad relation");
|
vimperator.echoerr("Bad document relationship: " + relationship);
|
||||||
}
|
}
|
||||||
|
|
||||||
relText = new RegExp(relText, "i");
|
relText = new RegExp(relationship, "i");
|
||||||
var elems = window.content.document.getElementsByTagName("a");
|
var elems = window.content.document.getElementsByTagName("link");
|
||||||
|
// links have higher priority than normal <a> hrefs
|
||||||
|
for (var i = 0; i < elems.length; i++)
|
||||||
|
{
|
||||||
|
if (relText.test(elems[i].rel))
|
||||||
|
{
|
||||||
|
vimperator.open(elems[i].href);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no links? ok, look for hrefs
|
||||||
|
elems = window.content.document.getElementsByTagName("a");
|
||||||
for (var pattern = 0; pattern < regexps.length; pattern++)
|
for (var pattern = 0; pattern < regexps.length; pattern++)
|
||||||
{
|
{
|
||||||
patternText = new RegExp(regexps[pattern], "i");
|
patternText = new RegExp(regexps[pattern], "i");
|
||||||
for (var i = 0; i < elems.length; i++)
|
for (var i = 0; i < elems.length; i++)
|
||||||
{
|
{
|
||||||
if (patternText.test(elems[i].text) || relText.test(elems[i].rel) )
|
if (patternText.test(elems[i].text) || relText.test(elems[i].rel))
|
||||||
{
|
{
|
||||||
vimperator.buffer.followLink(elems[i], vimperator.CURRENT_TAB);
|
vimperator.buffer.followLink(elems[i], vimperator.CURRENT_TAB);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// images with alt text being href
|
||||||
|
var children = elems[i].childNodes;
|
||||||
|
for (var j = 0; j < children.length; j++)
|
||||||
|
{
|
||||||
|
if (patternText.test(children[j].alt))
|
||||||
|
{
|
||||||
|
vimperator.buffer.followLink(elems[i], vimperator.CURRENT_TAB);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vimperator.beep();
|
vimperator.beep();
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ vimperator.Mappings = function () //{{{
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["]n"],
|
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["]n"],
|
||||||
function (count) { vimperator.buffer.followDocumentRelation("next"); },
|
function (count) { vimperator.buffer.followDocumentRelationship("next"); },
|
||||||
{
|
{
|
||||||
short_help: "go to 'next' or '>' if it exists. Beep otherwise.",
|
short_help: "go to 'next' or '>' if it exists. Beep otherwise.",
|
||||||
help: "Opens link labeled with next or >. Useful when browsing forums or documentation. Change nextpattern to modify its behaviour. It follows relations between files too.",
|
help: "Opens link labeled with next or >. Useful when browsing forums or documentation. Change nextpattern to modify its behaviour. It follows relations between files too.",
|
||||||
@@ -428,7 +428,7 @@ vimperator.Mappings = function () //{{{
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["]p"],
|
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["]p"],
|
||||||
function (count) { vimperator.buffer.followDocumentRelation("previous"); },
|
function (count) { vimperator.buffer.followDocumentRelationship("previous"); },
|
||||||
{
|
{
|
||||||
short_help: "go to 'prev', 'previous' or '<' if it exists. Beep otherwise.",
|
short_help: "go to 'prev', 'previous' or '<' if it exists. Beep otherwise.",
|
||||||
help: "Opens link labeled with prev, previous or <. Useful when browsing forums or documentation. Change nextpattern to modify its behaviour. It follows relations between files too.",
|
help: "Opens link labeled with prev, previous or <. Useful when browsing forums or documentation. Change nextpattern to modify its behaviour. It follows relations between files too.",
|
||||||
|
|||||||
Reference in New Issue
Block a user