Browse Source

Merge pull request #1150 from arturadib/loading-icon

Show animated loading icon until page loads
Brendan Dahl 13 years ago
parent
commit
6e0891d1f4
  1. BIN
      web/images/loading-icon.gif
  2. 10
      web/viewer.css
  3. 34
      web/viewer.js

BIN
web/images/loading-icon.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

10
web/viewer.css

@ -235,6 +235,16 @@ canvas { @@ -235,6 +235,16 @@ canvas {
-webkit-box-shadow: 0px 2px 10px #ff0;
}
.loadingIcon {
position: absolute;
display: block;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: url('images/loading-icon.gif') center no-repeat;
}
.textLayer {
position: absolute;
left: 0;

34
web/viewer.js

@ -644,6 +644,10 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, @@ -644,6 +644,10 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
div.removeAttribute('data-loaded');
delete this.canvas;
this.loadingIconDiv = document.createElement('div');
this.loadingIconDiv.className = 'loadingIcon';
div.appendChild(this.loadingIconDiv);
};
function setupAnnotations(content, scale) {
@ -808,7 +812,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, @@ -808,7 +812,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
};
this.drawingRequired = function() {
return !div.hasChildNodes();
return !div.querySelector('canvas');
};
this.draw = function pageviewDraw(callback) {
@ -843,19 +847,23 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, @@ -843,19 +847,23 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
ctx.restore();
ctx.translate(-this.x * scale, -this.y * scale);
// Rendering area
var self = this;
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();
cache.push(this);
callback();
}).bind(this), textLayer
);
this.content.startRendering(ctx, function pageViewDrawCallback(error) {
div.removeChild(self.loadingIconDiv);
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);

Loading…
Cancel
Save