From d2f463bf7c1a912c9616a3c90c135d622c5da626 Mon Sep 17 00:00:00 2001 From: gigaherz Date: Wed, 21 Mar 2012 23:36:10 +0100 Subject: [PATCH] Add a progressbar to the loading indicator, below the text. --- web/viewer.css | 20 +++++++++++++++++- web/viewer.html | 5 ++++- web/viewer.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/web/viewer.css b/web/viewer.css index fdce0288a..536073c34 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -391,11 +391,29 @@ canvas { } } -#loading { +#loadingBox { margin: 100px 0; text-align: center; } +#loadingBar { + display: inline-block; + border: 1px solid black; + clear: both; + padding: 1px; + margin:0px; +} + +#loadingBar #progress { + background-color: green; + display: inline-block; +} + +#loadingBar #remaining { + background-color: #333; + display: inline-block; +} + #PDFBug { font-size: 10px; position: fixed; diff --git a/web/viewer.html b/web/viewer.html index 34b2e77cb..b30b52db9 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -142,7 +142,10 @@ -
Loading... 0%
+
+
Loading... 0%
+
+
diff --git a/web/viewer.js b/web/viewer.js index 67ef67e97..b8d7b44f0 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -27,6 +27,49 @@ var Cache = function cacheCache(size) { }; }; +var ProgressBar = (function ProgressBarClosure() { + + function clamp(v, min, max) { + return Math.min(Math.max(v, min), max); + } + + function sizeBar(bar, num, width, height, units) { + var progress = bar.querySelector('#progress'); + var remaining = bar.querySelector('#remaining'); + progress.style.height=height + units; + remaining.style.height=height + units; + progress.style.width=num + units; + remaining.style.width=(width - num) + units; + } + + function ProgressBar(element, min, max, width, height, units) { + this.element = element; + this.min = min; + this.max = max; + this.width = width; + this.height = height; + this.units = units; + this.value = min; + sizeBar(element, 0, this.width, this.height, this.units); + } + + ProgressBar.prototype = { + constructor: ProgressBar, + + get value() { + return this._value; + }, + + set value(val) { + this._value = clamp(val, this.min, this.max); + var num = this.width * (val - this.min) / (this.max - this.min); + sizeBar(this.element, num, this.width, this.height, this.units); + } + }; + + return ProgressBar; +})(); + var RenderingQueue = (function RenderingQueueClosure() { function RenderingQueue() { this.items = []; @@ -260,6 +303,11 @@ var PDFView = { open: function pdfViewOpen(url, scale) { document.title = this.url = url; + // FIXME: Probably needs a better place to get initialized + if(!PDFView.loadingProgress) { + PDFView.loadingProgress = new ProgressBar(document.getElementById('loadingBar'), 0, 100, 15, 1.5, 'em'); + } + var self = this; PDFJS.getPdf( { @@ -400,6 +448,8 @@ var PDFView = { var percent = Math.round(level * 100); var loadingIndicator = document.getElementById('loading'); loadingIndicator.textContent = 'Loading... ' + percent + '%'; + + PDFView.loadingProgress.value = percent; }, load: function pdfViewLoad(data, scale) { @@ -414,8 +464,8 @@ var PDFView = { var errorWrapper = document.getElementById('errorWrapper'); errorWrapper.setAttribute('hidden', 'true'); - var loadingIndicator = document.getElementById('loading'); - loadingIndicator.setAttribute('hidden', 'true'); + var loadingBox = document.getElementById('loadingBox'); + loadingBox.setAttribute('hidden', 'true'); var sidebar = document.getElementById('sidebarView'); sidebar.parentNode.scrollTop = 0;