Merge pull request #5201 from Snuffleupagus/DocumentProperties-refactor
Small re-factoring of DocumentProperties
This commit is contained in:
commit
b06dc8d363
@ -20,8 +20,6 @@
|
||||
|
||||
var DocumentProperties = {
|
||||
overlayName: null,
|
||||
fileName: '',
|
||||
fileSize: '',
|
||||
rawFileSize: 0,
|
||||
|
||||
// Document property fields (in the viewer).
|
||||
@ -73,23 +71,21 @@ var DocumentProperties = {
|
||||
// don't bother updating the properties.
|
||||
return;
|
||||
}
|
||||
// Get the file name.
|
||||
this.fileName = getPDFFileNameFromURL(PDFView.url);
|
||||
|
||||
// Get the file size.
|
||||
// Get the file size (if it hasn't already been set).
|
||||
PDFView.pdfDocument.getDownloadInfo().then(function(data) {
|
||||
if (data.length === this.rawFileSize) {
|
||||
return;
|
||||
}
|
||||
this.setFileSize(data.length);
|
||||
this.updateUI(this.fileSizeField, this.fileSize);
|
||||
this.updateUI(this.fileSizeField, this.parseFileSize());
|
||||
}.bind(this));
|
||||
|
||||
// Get the other document properties.
|
||||
// Get the document properties.
|
||||
PDFView.pdfDocument.getMetadata().then(function(data) {
|
||||
var fields = [
|
||||
{ field: this.fileNameField, content: this.fileName },
|
||||
{ field: this.fileSizeField, content: this.fileSize },
|
||||
{ field: this.fileNameField,
|
||||
content: getPDFFileNameFromURL(PDFView.url) },
|
||||
{ field: this.fileSizeField, content: this.parseFileSize() },
|
||||
{ field: this.titleField, content: data.info.Title },
|
||||
{ field: this.authorField, content: data.info.Author },
|
||||
{ field: this.subjectField, content: data.info.Subject },
|
||||
@ -119,14 +115,22 @@ var DocumentProperties = {
|
||||
},
|
||||
|
||||
setFileSize: function documentPropertiesSetFileSize(fileSize) {
|
||||
var kb = (this.rawFileSize = fileSize) / 1024;
|
||||
if (kb < 1024) {
|
||||
this.fileSize = mozL10n.get('document_properties_kb', {
|
||||
if (fileSize > 0) {
|
||||
this.rawFileSize = fileSize;
|
||||
}
|
||||
},
|
||||
|
||||
parseFileSize: function documentPropertiesParseFileSize() {
|
||||
var fileSize = this.rawFileSize, kb = fileSize / 1024;
|
||||
if (!kb) {
|
||||
return;
|
||||
} else if (kb < 1024) {
|
||||
return mozL10n.get('document_properties_kb', {
|
||||
size_kb: (+kb.toPrecision(3)).toLocaleString(),
|
||||
size_b: fileSize.toLocaleString()
|
||||
}, '{{size_kb}} KB ({{size_b}} bytes)');
|
||||
} else {
|
||||
this.fileSize = mozL10n.get('document_properties_mb', {
|
||||
return mozL10n.get('document_properties_mb', {
|
||||
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
|
||||
size_b: fileSize.toLocaleString()
|
||||
}, '{{size_mb}} MB ({{size_b}} bytes)');
|
||||
|
Loading…
Reference in New Issue
Block a user