Show animated loading icon if page renders slow
This commit is contained in:
parent
2047fba8cb
commit
47f24cd27b
BIN
web/images/loading-icon.gif
Normal file
BIN
web/images/loading-icon.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
@ -235,6 +235,20 @@ canvas {
|
|||||||
-webkit-box-shadow: 0px 2px 10px #ff0;
|
-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 {
|
.textLayer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
@ -790,6 +790,10 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight,
|
|||||||
div.appendChild(canvas);
|
div.appendChild(canvas);
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
|
||||||
|
var loadingIconDiv = document.createElement('div');
|
||||||
|
loadingIconDiv.className = 'loadingIcon';
|
||||||
|
div.appendChild(loadingIconDiv);
|
||||||
|
|
||||||
var textLayerDiv = null;
|
var textLayerDiv = null;
|
||||||
if (!PDFJS.disableTextLayer) {
|
if (!PDFJS.disableTextLayer) {
|
||||||
textLayerDiv = document.createElement('div');
|
textLayerDiv = document.createElement('div');
|
||||||
@ -809,19 +813,30 @@ 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;
|
||||||
|
|
||||||
|
// 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();
|
stats.begin = Date.now();
|
||||||
this.content.startRendering(ctx,
|
this.content.startRendering(ctx, function pageViewDrawCallback(error) {
|
||||||
(function pageViewDrawCallback(error) {
|
clearTimeout(loadingTimer);
|
||||||
|
loadingIconDiv.classList.remove('show');
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
PDFView.error('An error occurred while rendering the page.', error);
|
PDFView.error('An error occurred while rendering the page.', error);
|
||||||
this.updateStats();
|
|
||||||
if (this.onAfterDraw)
|
|
||||||
this.onAfterDraw();
|
|
||||||
|
|
||||||
cache.push(this);
|
self.updateStats();
|
||||||
|
if (self.onAfterDraw)
|
||||||
|
self.onAfterDraw();
|
||||||
|
|
||||||
|
cache.push(self);
|
||||||
callback();
|
callback();
|
||||||
}).bind(this), textLayer
|
}, textLayer);
|
||||||
);
|
|
||||||
|
|
||||||
setupAnnotations(this.content, this.scale);
|
setupAnnotations(this.content, this.scale);
|
||||||
div.setAttribute('data-loaded', true);
|
div.setAttribute('data-loaded', true);
|
||||||
|
Loading…
Reference in New Issue
Block a user