[Pkg-javascript-commits] [pdf.js] 169/246: Attempt to display the File size quicker in the Document Properties dialog
David Prévot
taffit at moszumanska.debian.org
Sun Sep 7 15:36:37 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 3fd6c468b7d031565e9245fdfcdfc1904b9c6896
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Mon Aug 11 15:25:37 2014 +0200
Attempt to display the File size quicker in the Document Properties dialog
Currently the File size field in the Document Properties dialog isn't set until `PDFView.pdfDocument.getDownloadInfo()` is resolved. If the Document Properties dialog is opened while a PDF file is loading with range requests, this leads to the less desirable situation where all fields *except* File size are available.
In cases where `PDFView.open()` is called with the `args` parameter defined, and `args` contains the property `length`, we actually know the File size when the PDF file begins to load. (This is usually the case when ranged loading is used in the Firefox addon/built-in version.)
Hence we can use `args.length` to set the File size immediately when `PDFView.open()` is called, resulting in a better user experience.
---
web/document_properties.js | 8 ++++++--
web/viewer.js | 4 ++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/web/document_properties.js b/web/document_properties.js
index eefbc0e..e7cf0c2 100644
--- a/web/document_properties.js
+++ b/web/document_properties.js
@@ -22,6 +22,7 @@ var DocumentProperties = {
overlayName: null,
fileName: '',
fileSize: '',
+ rawFileSize: 0,
// Document property fields (in the viewer).
fileNameField: null,
@@ -77,6 +78,9 @@ var DocumentProperties = {
// Get the file size.
PDFView.pdfDocument.getDownloadInfo().then(function(data) {
+ if (data.length === this.rawFileSize) {
+ return;
+ }
this.setFileSize(data.length);
this.updateUI(this.fileSizeField, this.fileSize);
}.bind(this));
@@ -85,7 +89,7 @@ var DocumentProperties = {
PDFView.pdfDocument.getMetadata().then(function(data) {
var fields = [
{ field: this.fileNameField, content: this.fileName },
- // The fileSize field is updated once getDownloadInfo is resolved.
+ { field: this.fileSizeField, content: this.fileSize },
{ field: this.titleField, content: data.info.Title },
{ field: this.authorField, content: data.info.Author },
{ field: this.subjectField, content: data.info.Subject },
@@ -115,7 +119,7 @@ var DocumentProperties = {
},
setFileSize: function documentPropertiesSetFileSize(fileSize) {
- var kb = fileSize / 1024;
+ var kb = (this.rawFileSize = fileSize) / 1024;
if (kb < 1024) {
this.fileSize = mozL10n.get('document_properties_kb', {
size_kb: (+kb.toPrecision(3)).toLocaleString(),
diff --git a/web/viewer.js b/web/viewer.js
index 7ba2450..86f17b5 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -696,6 +696,10 @@ var PDFView = {
self.loading = false;
}
);
+
+ if (args && args.length) {
+ DocumentProperties.setFileSize(args.length);
+ }
},
download: function pdfViewDownload() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list