From b0bf99098bcbae16df367d23aeede40c66a61501 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Wed, 19 Oct 2011 22:14:34 +0200 Subject: [PATCH] Make firstrun looks faster --- web/viewer.css | 1 + web/viewer.js | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/web/viewer.css b/web/viewer.css index 040b87bdf..27ad0638a 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -215,6 +215,7 @@ canvas { box-shadow: 0px 4px 10px #000; -moz-box-shadow: 0px 4px 10px #000; -webkit-box-shadow: 0px 4px 10px #000; + background-color: white; } .page > a { diff --git a/web/viewer.js b/web/viewer.js index 12d0a3f37..0b68f1137 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -38,10 +38,10 @@ var PDFView = { var pages = this.pages; for (var i = 0; i < pages.length; i++) pages[i].update(val * kCssUnits); - this.currentScale = val; - this.pages[this.page - 1].scrollIntoView(); - this.pages[this.page - 1].draw(); + if (this.currentScale != val) + this.pages[this.page - 1].scrollIntoView(); + this.currentScale = val; var event = document.createEvent('UIEvents'); event.initUIEvent('scalechange', false, false, window, 0); @@ -107,6 +107,10 @@ var PDFView = { if (updateViewarea.inProgress) return; + // Avoid scrolling the first page during loading + if (this.loading && val == 1) + return; + pages[val - 1].scrollIntoView(); }, @@ -117,17 +121,20 @@ var PDFView = { open: function pdfViewOpen(url, scale) { document.title = this.url = url; + var self = this; getPdf( { url: url, progress: function getPdfProgress(evt) { if (evt.lengthComputable) - PDFView.progress(evt.loaded / evt.total); + self.progress(evt.loaded / evt.total); }, - error: PDFView.error + error: self.error }, function getPdfLoad(data) { - PDFView.load(data, scale); + self.loading = true; + self.load(data, scale); + self.loading = false; }); }, @@ -267,7 +274,7 @@ var PDFView = { var currentPage = this.pages[pageNumber - 1]; currentPage.scrollIntoView(dest); } else - this.page = page; // simple page + this.page = params.page; // simple page return; } } else if (/^\d+$/.test(hash)) // page number @@ -466,11 +473,11 @@ var PageView = function pageView(container, content, id, pageWidth, pageHeight, var canvas = document.createElement('canvas'); canvas.id = 'page' + this.id; canvas.mozOpaque = true; + div.appendChild(canvas); var scale = this.scale; canvas.width = pageWidth * scale; canvas.height = pageHeight * scale; - div.appendChild(canvas); var ctx = canvas.getContext('2d'); ctx.save(); @@ -598,6 +605,10 @@ window.addEventListener('load', function webViewerLoad(evt) { document.getElementById('fileInput').value = null; }, true); +window.addEventListener('unload', function webViewerUnload(evt) { + window.scrollTo(0, 0); +}, true); + function updateViewarea() { var visiblePages = PDFView.getVisiblePages(); for (var i = 0; i < visiblePages.length; i++) {