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