Skip to content

Commit 32f681c

Browse files
committed
loading the max 15 thumbnails first time
1 parent 29d0d8a commit 32f681c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

multi_page_viewer.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ var PDFViewer = {
274274
openURL: function(url) {
275275
PDFViewer.url = url;
276276
document.title = url;
277+
278+
if (this.thumbsLoadingInterval) {
279+
// cancel thumbs loading operations
280+
clearInterval(this.thumbsLoadingInterval);
281+
this.thumbsLoadingInterval = null;
282+
}
277283

278284
var req = new XMLHttpRequest();
279285
req.open('GET', url);
@@ -290,7 +296,9 @@ var PDFViewer = {
290296

291297
req.send(null);
292298
},
293-
299+
300+
thumbsLoadingInterval: null,
301+
294302
readPDF: function(data) {
295303
while (PDFViewer.element.hasChildNodes()) {
296304
PDFViewer.element.removeChild(PDFViewer.element.firstChild);
@@ -312,12 +320,22 @@ var PDFViewer = {
312320
PDFViewer.drawPage(1);
313321
document.location.hash = 1;
314322

315-
setTimeout(function() {
316-
for (var i = 1; i <= PDFViewer.numberOfPages; i++) {
317-
PDFViewer.createThumbnail(i);
318-
PDFViewer.drawThumbnail(i);
323+
// slowly loading the thumbs (few per second)
324+
// first time we are loading more images than subsequent
325+
var currentPageIndex = 1, imagesToLoad = 15;
326+
this.thumbsLoadingInterval = setInterval((function() {
327+
while (imagesToLoad-- > 0) {
328+
if (currentPageIndex > PDFViewer.numberOfPages) {
329+
clearInterval(this.thumbsLoadingInterval);
330+
this.thumbsLoadingInterval = null;
331+
return;
332+
}
333+
PDFViewer.createThumbnail(currentPageIndex);
334+
PDFViewer.drawThumbnail(currentPageIndex);
335+
++currentPageIndex;
319336
}
320-
}, 500);
337+
imagesToLoad = 3; // next time loading less images
338+
}).bind(this), 500);
321339
}
322340

323341
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : '';

0 commit comments

Comments
 (0)