diff --git a/content/buffers.js b/content/buffers.js
index 54b59fc7..0b7eba0e 100644
--- a/content/buffers.js
+++ b/content/buffers.js
@@ -583,7 +583,7 @@ vimperator.Buffer = function () //{{{
if (data.length - 1)
{
- for (var i = 0; i < data.length - 1 ; i++)
+ for (var i = 0; i < data.length - 1; i++)
ret += "
| " + data[i][0] + ": | " + data[i][1] + " |
";
}
else
@@ -773,37 +773,62 @@ vimperator.Buffer = function () //{{{
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
},
- followDocumentRelation: function (relation)
+ followDocumentRelationship: function (relationship)
{
var regexps;
var relText;
var patternText;
- switch (relation)
+ switch (relationship)
{
case "next":
regexps = vimperator.options["nextpattern"].split(",");
- relText = "next";
- break;
+ break;
case "previous":
//TODO: accept prev\%[ious]
regexps = vimperator.options["previouspattern"].split(",");
- relText = "previous";
- break;
- default: vimperator.echoerr("bad relation");
+ break;
+ default:
+ vimperator.echoerr("Bad document relationship: " + relationship);
}
- relText = new RegExp(relText, "i");
- var elems = window.content.document.getElementsByTagName("a");
+ relText = new RegExp(relationship, "i");
+ var elems = window.content.document.getElementsByTagName("link");
+ // links have higher priority than normal 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++)
{
patternText = new RegExp(regexps[pattern], "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);
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();
diff --git a/content/mappings.js b/content/mappings.js
index 9fa59b9d..dd645143 100644
--- a/content/mappings.js
+++ b/content/mappings.js
@@ -420,7 +420,7 @@ vimperator.Mappings = function () //{{{
}
));
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.",
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"],
- function (count) { vimperator.buffer.followDocumentRelation("previous"); },
+ function (count) { vimperator.buffer.followDocumentRelationship("previous"); },
{
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.",