]> git.parisson.com Git - pdf.js.git/commitdiff
loading the max 15 thumbnails first time
authornotmasteryet <async.processingjs@yahoo.com>
Thu, 30 Jun 2011 04:18:27 +0000 (23:18 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Thu, 30 Jun 2011 04:18:27 +0000 (23:18 -0500)
multi_page_viewer.js

index 87e2c8f14c2be18a7229fb6b3a08303457f351b6..f92f450dcf4df67c5359fda1d945da38170b98fb 100644 (file)
@@ -274,6 +274,12 @@ var PDFViewer = {
   openURL: function(url) {
     PDFViewer.url = url;
     document.title = url;
+
+    if (this.thumbsLoadingInterval) {
+      // cancel thumbs loading operations
+      clearInterval(this.thumbsLoadingInterval);
+      this.thumbsLoadingInterval = null;
+    }
     
     var req = new XMLHttpRequest();
     req.open('GET', url);
@@ -290,7 +296,9 @@ var PDFViewer = {
     
     req.send(null);
   },
-  
+
+  thumbsLoadingInterval: null,
+
   readPDF: function(data) {
     while (PDFViewer.element.hasChildNodes()) {
       PDFViewer.element.removeChild(PDFViewer.element.firstChild);
@@ -312,12 +320,22 @@ var PDFViewer = {
       PDFViewer.drawPage(1);
       document.location.hash = 1;
       
-      setTimeout(function() {
-        for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
-          PDFViewer.createThumbnail(i);
-          PDFViewer.drawThumbnail(i);
+      // slowly loading the thumbs (few per second)
+      // first time we are loading more images than subsequent
+      var currentPageIndex = 1, imagesToLoad = 15;
+      this.thumbsLoadingInterval = setInterval((function() {
+        while (imagesToLoad-- > 0) {
+          if (currentPageIndex > PDFViewer.numberOfPages) {
+            clearInterval(this.thumbsLoadingInterval);
+            this.thumbsLoadingInterval = null;
+            return;
+          }
+          PDFViewer.createThumbnail(currentPageIndex);
+          PDFViewer.drawThumbnail(currentPageIndex);
+          ++currentPageIndex;
         }
-      }, 500);
+        imagesToLoad = 3; // next time loading less images
+      }).bind(this), 500);
     }
     
     PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : '';