|
|
@ -14,12 +14,13 @@ |
|
|
|
* 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 */ |
|
|
|
/* globals PDFView, mozL10n, getPDFFileNameFromURL */ |
|
|
|
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var DocumentProperties = { |
|
|
|
var DocumentProperties = { |
|
|
|
overlayContainer: null, |
|
|
|
overlayContainer: null, |
|
|
|
|
|
|
|
fileName: '', |
|
|
|
fileSize: '', |
|
|
|
fileSize: '', |
|
|
|
visible: false, |
|
|
|
visible: false, |
|
|
|
|
|
|
|
|
|
|
@ -58,11 +59,22 @@ var DocumentProperties = { |
|
|
|
if (options.closeButton) { |
|
|
|
if (options.closeButton) { |
|
|
|
options.closeButton.addEventListener('click', this.hide.bind(this)); |
|
|
|
options.closeButton.addEventListener('click', this.hide.bind(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bind the event listener for the Esc key (to close the dialog).
|
|
|
|
|
|
|
|
window.addEventListener('keydown', |
|
|
|
|
|
|
|
function (e) { |
|
|
|
|
|
|
|
if (e.keyCode === 27) { // Esc key
|
|
|
|
|
|
|
|
this.hide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getProperties: function documentPropertiesGetProperties() { |
|
|
|
getProperties: function documentPropertiesGetProperties() { |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the file name.
|
|
|
|
|
|
|
|
this.fileName = getPDFFileNameFromURL(PDFView.url); |
|
|
|
|
|
|
|
|
|
|
|
// Get the file size.
|
|
|
|
// Get the file size.
|
|
|
|
PDFView.pdfDocument.dataLoaded().then(function(data) { |
|
|
|
PDFView.pdfDocument.dataLoaded().then(function(data) { |
|
|
|
self.setFileSize(data.length); |
|
|
|
self.setFileSize(data.length); |
|
|
@ -71,7 +83,7 @@ var DocumentProperties = { |
|
|
|
// 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: PDFView.url }, |
|
|
|
{ field: self.fileNameField, content: self.fileName }, |
|
|
|
{ field: self.fileSizeField, content: self.fileSize }, |
|
|
|
{ field: self.fileSizeField, content: self.fileSize }, |
|
|
|
{ field: self.titleField, content: data.info.Title }, |
|
|
|
{ field: self.titleField, content: data.info.Title }, |
|
|
|
{ field: self.authorField, content: data.info.Author }, |
|
|
|
{ field: self.authorField, content: data.info.Author }, |
|
|
@ -99,14 +111,17 @@ var DocumentProperties = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setFileSize: function documentPropertiesSetFileSize(fileSize) { |
|
|
|
setFileSize: function documentPropertiesSetFileSize(fileSize) { |
|
|
|
var kb = Math.round(fileSize / 1024); |
|
|
|
var kb = fileSize / 1024; |
|
|
|
if (kb < 1024) { |
|
|
|
if (kb < 1024) { |
|
|
|
this.fileSize = mozL10n.get('document_properties_kb', |
|
|
|
this.fileSize = mozL10n.get('document_properties_kb', { |
|
|
|
{size_kb: kb}, '{{size_kb}} KB'); |
|
|
|
size_kb: (+kb.toPrecision(3)).toLocaleString(), |
|
|
|
|
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
|
|
|
|
}, '{{size_kb}} KB ({{size_b}} bytes)'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var mb = Math.round((kb / 1024) * 100) / 100; |
|
|
|
this.fileSize = mozL10n.get('document_properties_mb', { |
|
|
|
this.fileSize = mozL10n.get('document_properties_mb', |
|
|
|
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(), |
|
|
|
{size_mb: mb}, '{{size_mb}} MB'); |
|
|
|
size_b: fileSize.toLocaleString() |
|
|
|
|
|
|
|
}, '{{size_mb}} MB ({{size_b}} bytes)'); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|