From 025f340228dc7ebeeb69cfccaca8e47cc7fbc490 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 Mar 2014 23:12:48 +0200 Subject: [PATCH 1/3] Prevent the Document Properties from being empty when the dialog is opened before the file has started loading --- web/document_properties.js | 31 +++++++++++++++++++++---------- web/viewer.js | 2 ++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/web/document_properties.js b/web/document_properties.js index 050865734..e5da09d8f 100644 --- a/web/document_properties.js +++ b/web/document_properties.js @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* globals PDFView, mozL10n, getPDFFileNameFromURL */ +/* globals PDFView, Promise, mozL10n, getPDFFileNameFromURL */ 'use strict'; @@ -60,6 +60,10 @@ var DocumentProperties = { options.closeButton.addEventListener('click', this.hide.bind(this)); } + this.dataAvailablePromise = new Promise(function (resolve) { + this.resolveDataAvailable = resolve; + }.bind(this)); + // Bind the event listener for the Esc key (to close the dialog). window.addEventListener('keydown', function (e) { @@ -77,14 +81,15 @@ var DocumentProperties = { // Get the file size. PDFView.pdfDocument.getDownloadInfo().then(function(data) { - self.setFileSize(data.length); - }); + this.setFileSize(data.length); + this.updateUI(this.fileSizeField, this.fileSize); + }.bind(this)); // Get the other document properties. PDFView.pdfDocument.getMetadata().then(function(data) { var fields = [ { field: self.fileNameField, content: self.fileName }, - { field: self.fileSizeField, content: self.fileSize }, + // The fileSize field is updated once getDownloadInfo is resolved. { field: self.titleField, content: data.info.Title }, { field: self.authorField, content: data.info.Author }, { field: self.subjectField, content: data.info.Subject }, @@ -102,12 +107,15 @@ var DocumentProperties = { // Show the properties in the dialog. for (var item in fields) { var element = fields[item]; - if (element.field && element.content !== undefined && - element.content !== '') { - element.field.textContent = element.content; - } + this.updateUI(element.field, element.content); } - }); + }.bind(this)); + }, + + updateUI: function documentPropertiesUpdateUI(field, content) { + if (field && content !== undefined && content !== '') { + field.textContent = content; + } }, setFileSize: function documentPropertiesSetFileSize(fileSize) { @@ -132,7 +140,10 @@ var DocumentProperties = { this.visible = true; this.overlayContainer.classList.remove('hidden'); this.overlayContainer.lastElementChild.classList.remove('hidden'); - this.getProperties(); + + this.dataAvailablePromise.then(function () { + this.getProperties(); + }.bind(this)); }, hide: function documentPropertiesClose() { diff --git a/web/viewer.js b/web/viewer.js index 0746b3bf9..b100f47f4 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -887,6 +887,8 @@ var PDFView = { this.pdfDocument = pdfDocument; + DocumentProperties.resolveDataAvailable(); + pdfDocument.getDownloadInfo().then(function() { PDFView.loadingBar.hide(); var outerContainer = document.getElementById('outerContainer'); From c7a0b68d9addfecba498008b350ad771d0442822 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 31 Mar 2014 23:16:44 +0200 Subject: [PATCH 2/3] Remove superfluous 'self' variable from web/document_properties.js --- web/document_properties.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/web/document_properties.js b/web/document_properties.js index e5da09d8f..0010f10c9 100644 --- a/web/document_properties.js +++ b/web/document_properties.js @@ -74,8 +74,6 @@ var DocumentProperties = { }, getProperties: function documentPropertiesGetProperties() { - var self = this; - // Get the file name. this.fileName = getPDFFileNameFromURL(PDFView.url); @@ -88,20 +86,20 @@ var DocumentProperties = { // Get the other document properties. PDFView.pdfDocument.getMetadata().then(function(data) { var fields = [ - { field: self.fileNameField, content: self.fileName }, + { field: this.fileNameField, content: this.fileName }, // The fileSize field is updated once getDownloadInfo is resolved. - { field: self.titleField, content: data.info.Title }, - { field: self.authorField, content: data.info.Author }, - { field: self.subjectField, content: data.info.Subject }, - { field: self.keywordsField, content: data.info.Keywords }, - { field: self.creationDateField, - content: self.parseDate(data.info.CreationDate) }, - { field: self.modificationDateField, - content: self.parseDate(data.info.ModDate) }, - { field: self.creatorField, content: data.info.Creator }, - { field: self.producerField, content: data.info.Producer }, - { field: self.versionField, content: data.info.PDFFormatVersion }, - { field: self.pageCountField, content: PDFView.pdfDocument.numPages } + { field: this.titleField, content: data.info.Title }, + { field: this.authorField, content: data.info.Author }, + { field: this.subjectField, content: data.info.Subject }, + { field: this.keywordsField, content: data.info.Keywords }, + { field: this.creationDateField, + content: this.parseDate(data.info.CreationDate) }, + { field: this.modificationDateField, + content: this.parseDate(data.info.ModDate) }, + { field: this.creatorField, content: data.info.Creator }, + { field: this.producerField, content: data.info.Producer }, + { field: this.versionField, content: data.info.PDFFormatVersion }, + { field: this.pageCountField, content: PDFView.pdfDocument.numPages } ]; // Show the properties in the dialog. From edfc78dfe7594ae5fbee90509f1bb74b4a3dcdee Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 2 Apr 2014 11:55:35 +0200 Subject: [PATCH 3/3] Only update the Document Properties if the dialog is still visible when the dataAvailablePromise is resolved --- web/document_properties.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/document_properties.js b/web/document_properties.js index 0010f10c9..25fbc8e61 100644 --- a/web/document_properties.js +++ b/web/document_properties.js @@ -74,6 +74,11 @@ var DocumentProperties = { }, getProperties: function documentPropertiesGetProperties() { + if (!this.visible) { + // If the dialog was closed before dataAvailablePromise was resolved, + // don't bother updating the properties. + return; + } // Get the file name. this.fileName = getPDFFileNameFromURL(PDFView.url);