1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Basic annotation link support

This commit is contained in:
notmasteryet 2011-08-17 20:21:54 -05:00
parent 2d1b356e66
commit 5c7ecbfa28
2 changed files with 87 additions and 0 deletions

View file

@ -165,6 +165,38 @@ var PageView = function(container, content, id, width, height, stats) {
div.removeChild(div.lastChild);
};
function setupLinks(canvas, content, scale) {
var links = content.getLinks(scale);
var currentLink = null;
if (links.length > 0)
{
canvas.addEventListener('mousemove', function(e) {
var x = e.pageX;
var y = e.pageY;
for (var p = canvas; p; p = p.offsetParent) {
x -= p.offsetLeft;
y -= p.offsetTop;
}
for (var i = 0; i < links.length; i++) {
var link = links[i];
if (!link.url)
continue;
if (link.x <= x && link.y <= y &&
x < link.x + link.width && y < link.y + link.height) {
currentLink = link;
canvas.style.cursor = 'pointer';
return;
}
}
currentLink = null;
canvas.style.cursor = 'default';
}, false);
canvas.addEventListener('mousedown', function(e) {
window.location.href = currentLink.url;
}, false);
}
}
this.draw = function() {
if (div.hasChildNodes()) {
this.updateStats();
@ -188,6 +220,8 @@ var PageView = function(container, content, id, width, height, stats) {
stats.begin = Date.now();
this.content.startRendering(ctx, this.updateStats);
setupLinks(canvas, this.content, this.scale);
return true;
};