From 47f24cd27bf524b9738129abc83bd68f4bc2aef4 Mon Sep 17 00:00:00 2001 From: Artur Adib Date: Tue, 31 Jan 2012 16:20:09 -0500 Subject: [PATCH] Show animated loading icon if page renders slow --- web/images/loading-icon.gif | Bin 0 -> 2545 bytes web/viewer.css | 14 +++++++++++++ web/viewer.js | 39 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 web/images/loading-icon.gif diff --git a/web/images/loading-icon.gif b/web/images/loading-icon.gif new file mode 100644 index 0000000000000000000000000000000000000000..1c72ebb554be018511ae972c3f2361dff02dce02 GIT binary patch literal 2545 zcma*pX;2es8VB%~zPr=ibVMCx-JQ^BhLDAsK)^**h(ZDp9YGuzZ%~j!}+w%FI;|aC7){7CdVvG)P{bng1y9Te*f}~*`1kQl$jwb z$tlW~rRS!X?#xfm_&6tTdp_`cjgYwbRFLNdoJCN$S-yhg`ZnC-yvedRSmOh%;Y`Gl6bY$Z-}#C=#F4%9!I1b zWQ~f+9P?;vhCxWwlwl=lrWG|7IYo;{jjmzJ5R9?f>n%-d@>kLINUc z4wM5dAO;kq<$}Dk{2-u0$I6@2N}&cUx9nmV1dYc8jfC}%=F9WCg^OQK9C6poh#2!A z3^EU*UFZvS^)?bu3T?J;@Ahb~%I?+@4!l5!*TjC}GIslNan-RCrrd~PdHYnNLJk+m&`$Y+NV(e>CCu%R#_8GqY4cv#j`#uRWdsg9DxWy(?oOvgCU}&@jy%c!H&-Q zqXJxajAtmQRoRa9V-RFXXh-bK*;Fum{BjpkYQGX~i@OZ^Dx0n&H}kvGKqQ?w(6iGXu_g08T|_hp#ZvFzIwKF*a=oMJ~3UGAjZ?g}GOxm44td zXoyYrU*I=y*vHv89hkYH(v5R#wc)BC3dZJKb3K)f>zaM3%JP(mpecViP0eKKYf3zy z->jx_mc?mCtPEvCQ?uppk?eLJt}_IR7giW%Jr)RyI!+E-voIs*lXI*z`GQc_&D#X( z{6G};HPYj6O|$lXxBJeDaweqa{4L=tOZ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H-#R6}0$WVA|*(K@3 z=5?@RlcLh(meW%A4)hGzcvEpm(_w?>zhL*i&s9$2>r zAtk{8Cia|+Y+V!uX9BtpXoF%lswuRKsM!pSs!?yhlCy!269K0|b M?FSZn2B>%I-}ej|s{jB1 literal 0 HcmV?d00001 diff --git a/web/viewer.css b/web/viewer.css index e355f7fc2..65f2928fa 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -235,6 +235,20 @@ canvas { -webkit-box-shadow: 0px 2px 10px #ff0; } +.loadingIcon { + position: absolute; + display: none; + left: 0; + top: 0; + right: 0; + bottom: 0; + background: url('images/loading-icon.gif') center no-repeat; */ +} + +.loadingIcon.show { + display: block; +} + .textLayer { position: absolute; left: 0; diff --git a/web/viewer.js b/web/viewer.js index dd16b0282..f319fcdc1 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -790,6 +790,10 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, div.appendChild(canvas); this.canvas = canvas; + var loadingIconDiv = document.createElement('div'); + loadingIconDiv.className = 'loadingIcon'; + div.appendChild(loadingIconDiv); + var textLayerDiv = null; if (!PDFJS.disableTextLayer) { textLayerDiv = document.createElement('div'); @@ -809,19 +813,30 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, ctx.restore(); ctx.translate(-this.x * scale, -this.y * scale); - stats.begin = Date.now(); - this.content.startRendering(ctx, - (function pageViewDrawCallback(error) { - if (error) - PDFView.error('An error occurred while rendering the page.', error); - this.updateStats(); - if (this.onAfterDraw) - this.onAfterDraw(); + // Rendering area - cache.push(this); - callback(); - }).bind(this), textLayer - ); + var self = this; + + // Display loading icon if page hasn't finished rendering after XXXX ms + var loadingTimer = setTimeout(function loadingTimerCallback() { + loadingIconDiv.classList.add('show'); + }, 1000); + + stats.begin = Date.now(); + this.content.startRendering(ctx, function pageViewDrawCallback(error) { + clearTimeout(loadingTimer); + loadingIconDiv.classList.remove('show'); + + if (error) + PDFView.error('An error occurred while rendering the page.', error); + + self.updateStats(); + if (self.onAfterDraw) + self.onAfterDraw(); + + cache.push(self); + callback(); + }, textLayer); setupAnnotations(this.content, this.scale); div.setAttribute('data-loaded', true);