Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small re-factoring of DocumentProperties #5201

Merged
merged 1 commit into from
Aug 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions web/document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

var DocumentProperties = {
overlayName: null,
fileName: '',
fileSize: '',
rawFileSize: 0,

// Document property fields (in the viewer).
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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)');
Expand Down