]> git.parisson.com Git - pdf.js.git/commitdiff
Add a progressbar to the loading indicator, below the text.
authorgigaherz <gigaherz@gmail.com>
Wed, 21 Mar 2012 22:36:10 +0000 (23:36 +0100)
committergigaherz <gigaherz@gmail.com>
Wed, 21 Mar 2012 22:36:10 +0000 (23:36 +0100)
web/viewer.css
web/viewer.html
web/viewer.js

index fdce0288aa4563d3d2bec95ce8d60dfc580b38b7..536073c34f26cfae74f6fb754d91dc43606e0ea4 100644 (file)
@@ -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;
index 34b2e77cbb48dc9dfc14778b34edf1691e49577c..b30b52db9faf800ae470ce000bba4cd01b94dd9e 100644 (file)
       </div>
     </div>
 
-    <div id="loading">Loading... 0%</div>
+    <div id="loadingBox">
+        <div id="loading">Loading... 0%</div>
+        <div id="loadingBar"><div id="progress"></div><div id="remaining"></div></div>
+    </div>
     <div id="viewer"></div>
   </body>
 </html>
index 67ef67e97ef9cf99c14033df8699f071cf72e126..b8d7b44f0e9c2702097cc23df8be52fcf9b70203 100644 (file)
@@ -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;