Merge pull request #1377 from gigaherz/progressbar
Add a Progressbar to the loading indicator
This commit is contained in:
commit
0cf43886c5
@ -391,11 +391,43 @@ canvas {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#loading {
|
#loadingBox {
|
||||||
margin: 100px 0;
|
margin: 100px 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#loadingBar {
|
||||||
|
background-color: #333;
|
||||||
|
display: inline-block;
|
||||||
|
border: 1px solid black;
|
||||||
|
clear: both;
|
||||||
|
margin:0px;
|
||||||
|
line-height: 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
width: 15em;
|
||||||
|
height: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loadingBar .progress {
|
||||||
|
background-color: green;
|
||||||
|
display: inline-block;
|
||||||
|
float: left;
|
||||||
|
|
||||||
|
background: #b4e391;
|
||||||
|
background: -moz-linear-gradient(top, #b4e391 0%, #61c419 50%, #b4e391 100%);
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b4e391), color-stop(50%,#61c419), color-stop(100%,#b4e391));
|
||||||
|
background: -webkit-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: -o-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: -ms-linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
background: linear-gradient(top, #b4e391 0%,#61c419 50%,#b4e391 100%);
|
||||||
|
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
|
||||||
|
width: 0%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
#PDFBug {
|
#PDFBug {
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
@ -143,7 +143,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loading">Loading... 0%</div>
|
<div id="loadingBox">
|
||||||
|
<div id="loading">Loading... 0%</div>
|
||||||
|
<div id="loadingBar"><div class="progress"></div></div>
|
||||||
|
</div>
|
||||||
<div id="viewer"></div>
|
<div id="viewer"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -27,6 +27,48 @@ var Cache = function cacheCache(size) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var ProgressBar = (function ProgressBarClosure() {
|
||||||
|
|
||||||
|
function clamp(v, min, max) {
|
||||||
|
return Math.min(Math.max(v, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProgressBar(id, opts) {
|
||||||
|
|
||||||
|
// Fetch the sub-elements for later
|
||||||
|
this.div = document.querySelector(id + ' .progress');
|
||||||
|
|
||||||
|
// Get options, with sensible defaults
|
||||||
|
this.height = opts.height || 100;
|
||||||
|
this.width = opts.width || 100;
|
||||||
|
this.units = opts.units || '%';
|
||||||
|
this.percent = opts.percent || 0;
|
||||||
|
|
||||||
|
// Initialize heights
|
||||||
|
this.div.style.height = this.height + this.units;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressBar.prototype = {
|
||||||
|
|
||||||
|
updateBar: function ProgressBar_updateBar() {
|
||||||
|
var progressSize = this.width * this._percent / 100;
|
||||||
|
|
||||||
|
this.div.style.width = progressSize + this.units;
|
||||||
|
},
|
||||||
|
|
||||||
|
get percent() {
|
||||||
|
return this._percent;
|
||||||
|
},
|
||||||
|
|
||||||
|
set percent(val) {
|
||||||
|
this._percent = clamp(val, 0, 100);
|
||||||
|
this.updateBar();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return ProgressBar;
|
||||||
|
})();
|
||||||
|
|
||||||
var RenderingQueue = (function RenderingQueueClosure() {
|
var RenderingQueue = (function RenderingQueueClosure() {
|
||||||
function RenderingQueue() {
|
function RenderingQueue() {
|
||||||
this.items = [];
|
this.items = [];
|
||||||
@ -260,6 +302,10 @@ var PDFView = {
|
|||||||
open: function pdfViewOpen(url, scale) {
|
open: function pdfViewOpen(url, scale) {
|
||||||
document.title = this.url = url;
|
document.title = this.url = url;
|
||||||
|
|
||||||
|
if (!PDFView.loadingBar) {
|
||||||
|
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
PDFJS.getPdf(
|
PDFJS.getPdf(
|
||||||
{
|
{
|
||||||
@ -400,6 +446,8 @@ var PDFView = {
|
|||||||
var percent = Math.round(level * 100);
|
var percent = Math.round(level * 100);
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingIndicator = document.getElementById('loading');
|
||||||
loadingIndicator.textContent = 'Loading... ' + percent + '%';
|
loadingIndicator.textContent = 'Loading... ' + percent + '%';
|
||||||
|
|
||||||
|
PDFView.loadingBar.percent = percent;
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function pdfViewLoad(data, scale) {
|
load: function pdfViewLoad(data, scale) {
|
||||||
@ -414,8 +462,8 @@ var PDFView = {
|
|||||||
var errorWrapper = document.getElementById('errorWrapper');
|
var errorWrapper = document.getElementById('errorWrapper');
|
||||||
errorWrapper.setAttribute('hidden', 'true');
|
errorWrapper.setAttribute('hidden', 'true');
|
||||||
|
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingBox = document.getElementById('loadingBox');
|
||||||
loadingIndicator.setAttribute('hidden', 'true');
|
loadingBox.setAttribute('hidden', 'true');
|
||||||
|
|
||||||
var sidebar = document.getElementById('sidebarView');
|
var sidebar = document.getElementById('sidebarView');
|
||||||
sidebar.parentNode.scrollTop = 0;
|
sidebar.parentNode.scrollTop = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user