Browse Source

Convert the document properties to ES6 syntax

Tim van der Meij 8 years ago
parent
commit
6d7a0ff8f2
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
  1. 56
      web/pdf_document_properties.js

56
web/pdf_document_properties.js

@ -21,20 +21,17 @@ import { OverlayManager } from './overlay_manager';
* @typedef {Object} PDFDocumentPropertiesOptions * @typedef {Object} PDFDocumentPropertiesOptions
* @property {string} overlayName - Name/identifier for the overlay. * @property {string} overlayName - Name/identifier for the overlay.
* @property {Object} fields - Names and elements of the overlay's fields. * @property {Object} fields - Names and elements of the overlay's fields.
* @property {HTMLDivElement} container - Div container for the overlay.
* @property {HTMLButtonElement} closeButton - Button for closing the overlay. * @property {HTMLButtonElement} closeButton - Button for closing the overlay.
*/ */
/** class PDFDocumentProperties {
* @class
*/
var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
/** /**
* @constructs PDFDocumentProperties
* @param {PDFDocumentPropertiesOptions} options * @param {PDFDocumentPropertiesOptions} options
*/ */
function PDFDocumentProperties(options) { constructor(options) {
this.fields = options.fields;
this.overlayName = options.overlayName; this.overlayName = options.overlayName;
this.fields = options.fields;
this.container = options.container; this.container = options.container;
this.rawFileSize = 0; this.rawFileSize = 0;
@ -51,23 +48,22 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
this.close.bind(this)); this.close.bind(this));
} }
PDFDocumentProperties.prototype = {
/** /**
* Open the document properties overlay. * Open the document properties overlay.
*/ */
open: function PDFDocumentProperties_open() { open() {
Promise.all([OverlayManager.open(this.overlayName), Promise.all([OverlayManager.open(this.overlayName),
this._dataAvailableCapability.promise]).then(() => { this._dataAvailableCapability.promise]).then(() => {
this._getProperties(); this._getProperties();
}); });
}, }
/** /**
* Close the document properties overlay. * Close the document properties overlay.
*/ */
close: function PDFDocumentProperties_close() { close() {
OverlayManager.close(this.overlayName); OverlayManager.close(this.overlayName);
}, }
/** /**
* Set the file size of the PDF document. This method is used to * Set the file size of the PDF document. This method is used to
@ -76,11 +72,11 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
* *
* @param {number} fileSize - The file size of the PDF document. * @param {number} fileSize - The file size of the PDF document.
*/ */
setFileSize: function PDFDocumentProperties_setFileSize(fileSize) { setFileSize(fileSize) {
if (fileSize > 0) { if (fileSize > 0) {
this.rawFileSize = fileSize; this.rawFileSize = fileSize;
} }
}, }
/** /**
* Set a reference to the PDF document and the URL in order * Set a reference to the PDF document and the URL in order
@ -91,20 +87,19 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
* @param {Object} pdfDocument - A reference to the PDF document. * @param {Object} pdfDocument - A reference to the PDF document.
* @param {string} url - The URL of the document. * @param {string} url - The URL of the document.
*/ */
setDocumentAndUrl: setDocumentAndUrl(pdfDocument, url) {
function PDFDocumentProperties_setDocumentAndUrl(pdfDocument, url) {
this.pdfDocument = pdfDocument; this.pdfDocument = pdfDocument;
this.url = url; this.url = url;
this._dataAvailableCapability.resolve(); this._dataAvailableCapability.resolve();
}, }
/** /**
* @private * @private
*/ */
_getProperties: function PDFDocumentProperties_getProperties() { _getProperties() {
if (!OverlayManager.active) { if (!OverlayManager.active) {
// If the dialog was closed before dataAvailablePromise was resolved, // If the dialog was closed before `_dataAvailableCapability` was
// don't bother updating the properties. // resolved, don't bother updating the properties.
return; return;
} }
// Get the file size (if it hasn't already been set). // Get the file size (if it hasn't already been set).
@ -138,21 +133,21 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
this._updateUI(this.fields[identifier], content[identifier]); this._updateUI(this.fields[identifier], content[identifier]);
} }
}); });
}, }
/** /**
* @private * @private
*/ */
_updateUI: function PDFDocumentProperties_updateUI(field, content) { _updateUI(field, content) {
if (field && content !== undefined && content !== '') { if (field && content !== undefined && content !== '') {
field.textContent = content; field.textContent = content;
} }
}, }
/** /**
* @private * @private
*/ */
_parseFileSize: function PDFDocumentProperties_parseFileSize() { _parseFileSize() {
var fileSize = this.rawFileSize, kb = fileSize / 1024; var fileSize = this.rawFileSize, kb = fileSize / 1024;
if (!kb) { if (!kb) {
return; return;
@ -166,12 +161,12 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
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)');
}, }
/** /**
* @private * @private
*/ */
_parseDate: function PDFDocumentProperties_parseDate(inputDate) { _parseDate(inputDate) {
// This is implemented according to the PDF specification, but note that // This is implemented according to the PDF specification, but note that
// Adobe Reader doesn't handle changing the date to universal time // Adobe Reader doesn't handle changing the date to universal time
// and doesn't use the user's time zone (they're effectively ignoring // and doesn't use the user's time zone (they're effectively ignoring
@ -187,7 +182,7 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
} }
// Get all elements from the PDF date string. // Get all elements from the PDF date string.
// JavaScript's Date object expects the month to be between // JavaScript's `Date` object expects the month to be between
// 0 and 11 instead of 1 and 12, so we're correcting for this. // 0 and 11 instead of 1 and 12, so we're correcting for this.
var year = parseInt(dateToParse.substring(0, 4), 10); var year = parseInt(dateToParse.substring(0, 4), 10);
var month = parseInt(dateToParse.substring(4, 6), 10) - 1; var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
@ -214,13 +209,10 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
var dateString = date.toLocaleDateString(); var dateString = date.toLocaleDateString();
var timeString = date.toLocaleTimeString(); var timeString = date.toLocaleTimeString();
return mozL10n.get('document_properties_date_string', return mozL10n.get('document_properties_date_string',
{date: dateString, time: timeString}, { date: dateString, time: timeString },
'{{date}}, {{time}}'); '{{date}}, {{time}}');
} }
}; }
return PDFDocumentProperties;
})();
export { export {
PDFDocumentProperties, PDFDocumentProperties,

Loading…
Cancel
Save