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 {
-webkit-box-shadow: 0px 2px 10px #ff0; -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 { .textLayer {
position: absolute; position: absolute;
left: 0; left: 0;

34
web/viewer.js

@ -644,6 +644,10 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
div.removeAttribute('data-loaded'); div.removeAttribute('data-loaded');
delete this.canvas; delete this.canvas;
this.loadingIconDiv = document.createElement('div');
this.loadingIconDiv.className = 'loadingIcon';
div.appendChild(this.loadingIconDiv);
}; };
function setupAnnotations(content, scale) { function setupAnnotations(content, scale) {
@ -808,7 +812,7 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
}; };
this.drawingRequired = function() { this.drawingRequired = function() {
return !div.hasChildNodes(); return !div.querySelector('canvas');
}; };
this.draw = function pageviewDraw(callback) { this.draw = function pageviewDraw(callback) {
@ -843,19 +847,23 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
ctx.restore(); ctx.restore();
ctx.translate(-this.x * scale, -this.y * scale); ctx.translate(-this.x * scale, -this.y * scale);
// Rendering area
var self = this;
stats.begin = Date.now(); stats.begin = Date.now();
this.content.startRendering(ctx, this.content.startRendering(ctx, function pageViewDrawCallback(error) {
(function pageViewDrawCallback(error) { div.removeChild(self.loadingIconDiv);
if (error)
PDFView.error('An error occurred while rendering the page.', error); if (error)
this.updateStats(); PDFView.error('An error occurred while rendering the page.', error);
if (this.onAfterDraw)
this.onAfterDraw(); self.updateStats();
if (self.onAfterDraw)
cache.push(this); self.onAfterDraw();
callback();
}).bind(this), textLayer cache.push(self);
); callback();
}, textLayer);
setupAnnotations(this.content, this.scale); setupAnnotations(this.content, this.scale);
div.setAttribute('data-loaded', true); div.setAttribute('data-loaded', true);

Loading…
Cancel
Save