Merge pull request #4546 from Snuffleupagus/document-properties-wait-for-data
Prevent the Document Properties from being empty when the dialog is opened before the file has started loading
This commit is contained in:
commit
9b0038f5e2
@ -14,7 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals PDFView, mozL10n, getPDFFileNameFromURL */
|
/* globals PDFView, Promise, mozL10n, getPDFFileNameFromURL */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -60,6 +60,10 @@ var DocumentProperties = {
|
|||||||
options.closeButton.addEventListener('click', this.hide.bind(this));
|
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).
|
// Bind the event listener for the Esc key (to close the dialog).
|
||||||
window.addEventListener('keydown',
|
window.addEventListener('keydown',
|
||||||
function (e) {
|
function (e) {
|
||||||
@ -70,44 +74,51 @@ var DocumentProperties = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getProperties: function documentPropertiesGetProperties() {
|
getProperties: function documentPropertiesGetProperties() {
|
||||||
var self = this;
|
if (!this.visible) {
|
||||||
|
// If the dialog was closed before dataAvailablePromise was resolved,
|
||||||
|
// don't bother updating the properties.
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Get the file name.
|
// Get the file name.
|
||||||
this.fileName = getPDFFileNameFromURL(PDFView.url);
|
this.fileName = getPDFFileNameFromURL(PDFView.url);
|
||||||
|
|
||||||
// Get the file size.
|
// Get the file size.
|
||||||
PDFView.pdfDocument.getDownloadInfo().then(function(data) {
|
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.
|
// Get the other document properties.
|
||||||
PDFView.pdfDocument.getMetadata().then(function(data) {
|
PDFView.pdfDocument.getMetadata().then(function(data) {
|
||||||
var fields = [
|
var fields = [
|
||||||
{ field: self.fileNameField, content: self.fileName },
|
{ field: this.fileNameField, content: this.fileName },
|
||||||
{ field: self.fileSizeField, content: self.fileSize },
|
// The fileSize field is updated once getDownloadInfo is resolved.
|
||||||
{ field: self.titleField, content: data.info.Title },
|
{ field: this.titleField, content: data.info.Title },
|
||||||
{ field: self.authorField, content: data.info.Author },
|
{ field: this.authorField, content: data.info.Author },
|
||||||
{ field: self.subjectField, content: data.info.Subject },
|
{ field: this.subjectField, content: data.info.Subject },
|
||||||
{ field: self.keywordsField, content: data.info.Keywords },
|
{ field: this.keywordsField, content: data.info.Keywords },
|
||||||
{ field: self.creationDateField,
|
{ field: this.creationDateField,
|
||||||
content: self.parseDate(data.info.CreationDate) },
|
content: this.parseDate(data.info.CreationDate) },
|
||||||
{ field: self.modificationDateField,
|
{ field: this.modificationDateField,
|
||||||
content: self.parseDate(data.info.ModDate) },
|
content: this.parseDate(data.info.ModDate) },
|
||||||
{ field: self.creatorField, content: data.info.Creator },
|
{ field: this.creatorField, content: data.info.Creator },
|
||||||
{ field: self.producerField, content: data.info.Producer },
|
{ field: this.producerField, content: data.info.Producer },
|
||||||
{ field: self.versionField, content: data.info.PDFFormatVersion },
|
{ field: this.versionField, content: data.info.PDFFormatVersion },
|
||||||
{ field: self.pageCountField, content: PDFView.pdfDocument.numPages }
|
{ field: this.pageCountField, content: PDFView.pdfDocument.numPages }
|
||||||
];
|
];
|
||||||
|
|
||||||
// Show the properties in the dialog.
|
// Show the properties in the dialog.
|
||||||
for (var item in fields) {
|
for (var item in fields) {
|
||||||
var element = fields[item];
|
var element = fields[item];
|
||||||
if (element.field && element.content !== undefined &&
|
this.updateUI(element.field, element.content);
|
||||||
element.content !== '') {
|
|
||||||
element.field.textContent = element.content;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
updateUI: function documentPropertiesUpdateUI(field, content) {
|
||||||
|
if (field && content !== undefined && content !== '') {
|
||||||
|
field.textContent = content;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setFileSize: function documentPropertiesSetFileSize(fileSize) {
|
setFileSize: function documentPropertiesSetFileSize(fileSize) {
|
||||||
@ -132,7 +143,10 @@ var DocumentProperties = {
|
|||||||
this.visible = true;
|
this.visible = true;
|
||||||
this.overlayContainer.classList.remove('hidden');
|
this.overlayContainer.classList.remove('hidden');
|
||||||
this.overlayContainer.lastElementChild.classList.remove('hidden');
|
this.overlayContainer.lastElementChild.classList.remove('hidden');
|
||||||
this.getProperties();
|
|
||||||
|
this.dataAvailablePromise.then(function () {
|
||||||
|
this.getProperties();
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function documentPropertiesClose() {
|
hide: function documentPropertiesClose() {
|
||||||
|
@ -887,6 +887,8 @@ var PDFView = {
|
|||||||
|
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
|
|
||||||
|
DocumentProperties.resolveDataAvailable();
|
||||||
|
|
||||||
pdfDocument.getDownloadInfo().then(function() {
|
pdfDocument.getDownloadInfo().then(function() {
|
||||||
PDFView.loadingBar.hide();
|
PDFView.loadingBar.hide();
|
||||||
var outerContainer = document.getElementById('outerContainer');
|
var outerContainer = document.getElementById('outerContainer');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user