@@ -274,6 +274,12 @@ var PDFViewer = {
274
274
openURL : function (url ) {
275
275
PDFViewer .url = url ;
276
276
document .title = url ;
277
+
278
+ if (this .thumbsLoadingInterval ) {
279
+ // cancel thumbs loading operations
280
+ clearInterval (this .thumbsLoadingInterval );
281
+ this .thumbsLoadingInterval = null ;
282
+ }
277
283
278
284
var req = new XMLHttpRequest ();
279
285
req .open ('GET' , url );
@@ -290,7 +296,9 @@ var PDFViewer = {
290
296
291
297
req .send (null );
292
298
},
293
-
299
+
300
+ thumbsLoadingInterval : null ,
301
+
294
302
readPDF : function (data ) {
295
303
while (PDFViewer .element .hasChildNodes ()) {
296
304
PDFViewer .element .removeChild (PDFViewer .element .firstChild );
@@ -312,12 +320,22 @@ var PDFViewer = {
312
320
PDFViewer .drawPage (1 );
313
321
document .location .hash = 1 ;
314
322
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 ;
319
336
}
320
- }, 500 );
337
+ imagesToLoad = 3 ; // next time loading less images
338
+ }).bind (this ), 500 );
321
339
}
322
340
323
341
PDFViewer .previousPageButton .className = (PDFViewer .pageNumber === 1 ) ? 'disabled' : '';
0 commit comments