]> git.parisson.com Git - pdf.js.git/commitdiff
Using native HTML hyperlinks for bookmark/link navigation
authornotmasteryet <async.processingjs@yahoo.com>
Thu, 25 Aug 2011 23:28:50 +0000 (18:28 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Thu, 25 Aug 2011 23:28:50 +0000 (18:28 -0500)
web/viewer.css
web/viewer.js

index e18d9681e35b74972a12ff056addd6320f7d4a96..18da0b3d1edf0d1d1284ef6d9fb31f924633d733 100644 (file)
@@ -20,6 +20,7 @@ body {
   top: 0px;
   height: 40px;
   width: 100%;
+  z-index: 1;
 }
 
 .separator {
@@ -67,6 +68,7 @@ span#info {
   transition: left 0.25s ease-in-out 1s;
   -moz-transition: left 0.25s ease-in-out 1s;
   -webkit-transition: left 0.25s ease-in-out 1s;
+  z-index: 1;
 }
 
 #sidebar:hover {
@@ -180,6 +182,20 @@ canvas {
   width: 816px;
   height: 1056px;
   margin: 10px auto;
+  position:relative;
+}
+
+.page > a {
+  display: block;
+  position: absolute;
+}
+
+.page > a:hover {
+  opacity: 0.2;
+  background: #ff0;
+  box-shadow: 0px 2px 10px #ff0;
+  -moz-box-shadow: 0px 2px 10px #ff0;
+  -webkit-box-shadow: 0px 2px 10px #ff0;
 }
 
 #viewer {
index a16cd76b17ce0066b23684ec4117ba20e65dea47..8af6e01d1073532fa203e9d6912b68b1c71a8440 100644 (file)
@@ -212,39 +212,24 @@ var PageView = function(container, content, id, width, height,
   };
 
   function setupLinks(canvas, content, scale) {
+    function bindLink(link, dest) {
+      if (dest) {
+        link.onclick = function() {
+          PDFView.navigateTo(dest);
+          return false;
+        };
+      }
+    }
     var links = content.getLinks();
-    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;
-        }
-        x /= scale;
-        y /= scale;
-        var i, n = links.length;
-        for (i = 0; i < n; i++) {
-          var link = links[i];
-          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) {
-        if (!currentLink)
-          return;
-        if (currentLink.url)
-          window.location.href = currentLink.url;
-        if (currentLink.dest)
-          navigateTo(currentLink.dest);
-      }, false);
+    for (var i = 0; i < links.length; i++) {
+      var link = document.createElement('a');
+      link.style.left = Math.floor(links[i].x * scale) + 'px';
+      link.style.top = Math.floor(links[i].y * scale) + 'px';
+      link.style.width = Math.ceil(links[i].width * scale) + 'px';
+      link.style.height = Math.ceil(links[i].height * scale) + 'px';
+      link.href = links[i].url || '';
+      bindLink(link, links[i].dest);
+      div.appendChild(link);
     }
   }