@@ -277,6 +277,12 @@ var PDFViewer = {
277
277
openURL : function (url ) {
278
278
PDFViewer .url = url ;
279
279
document .title = url ;
280
+
281
+ if (this .thumbsLoadingInterval ) {
282
+ // cancel thumbs loading operations
283
+ clearInterval (this .thumbsLoadingInterval );
284
+ this .thumbsLoadingInterval = null ;
285
+ }
280
286
281
287
var req = new XMLHttpRequest ();
282
288
req .open ('GET' , url );
@@ -293,7 +299,9 @@ var PDFViewer = {
293
299
294
300
req .send (null );
295
301
},
296
-
302
+
303
+ thumbsLoadingInterval : null ,
304
+
297
305
readPDF : function (data ) {
298
306
while (PDFViewer .element .hasChildNodes ()) {
299
307
PDFViewer .element .removeChild (PDFViewer .element .firstChild );
@@ -315,12 +323,22 @@ var PDFViewer = {
315
323
PDFViewer .drawPage (1 );
316
324
document .location .hash = 1 ;
317
325
318
- setTimeout (function () {
319
- for (var i = 1 ; i <= PDFViewer .numberOfPages ; i ++) {
320
- PDFViewer .createThumbnail (i );
321
- PDFViewer .drawThumbnail (i );
326
+ // slowly loading the thumbs (few per second)
327
+ // first time we are loading more images than subsequent
328
+ var currentPageIndex = 1 , imagesToLoad = 15 ;
329
+ this .thumbsLoadingInterval = setInterval ((function () {
330
+ while (imagesToLoad -- > 0 ) {
331
+ if (currentPageIndex > PDFViewer .numberOfPages ) {
332
+ clearInterval (this .thumbsLoadingInterval );
333
+ this .thumbsLoadingInterval = null ;
334
+ return ;
335
+ }
336
+ PDFViewer .createThumbnail (currentPageIndex );
337
+ PDFViewer .drawThumbnail (currentPageIndex );
338
+ ++currentPageIndex ;
322
339
}
323
- }, 500 );
340
+ imagesToLoad = 3 ; // next time loading less images
341
+ }).bind (this ), 500 );
324
342
}
325
343
326
344
PDFViewer .previousPageButton .className = (PDFViewer .pageNumber === 1 ) ? 'disabled' : '';
0 commit comments