Convert the document properties to ES6 syntax
This commit is contained in:
parent
228df572d2
commit
6d7a0ff8f2
@ -21,20 +21,17 @@ import { OverlayManager } from './overlay_manager';
|
||||
* @typedef {Object} PDFDocumentPropertiesOptions
|
||||
* @property {string} overlayName - Name/identifier for the overlay.
|
||||
* @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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
|
||||
class PDFDocumentProperties {
|
||||
/**
|
||||
* @constructs PDFDocumentProperties
|
||||
* @param {PDFDocumentPropertiesOptions} options
|
||||
*/
|
||||
function PDFDocumentProperties(options) {
|
||||
this.fields = options.fields;
|
||||
constructor(options) {
|
||||
this.overlayName = options.overlayName;
|
||||
this.fields = options.fields;
|
||||
this.container = options.container;
|
||||
|
||||
this.rawFileSize = 0;
|
||||
@ -51,23 +48,22 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
|
||||
this.close.bind(this));
|
||||
}
|
||||
|
||||
PDFDocumentProperties.prototype = {
|
||||
/**
|
||||
* Open the document properties overlay.
|
||||
*/
|
||||
open: function PDFDocumentProperties_open() {
|
||||
open() {
|
||||
Promise.all([OverlayManager.open(this.overlayName),
|
||||
this._dataAvailableCapability.promise]).then(() => {
|
||||
this._getProperties();
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the document properties overlay.
|
||||
*/
|
||||
close: function PDFDocumentProperties_close() {
|
||||
close() {
|
||||
OverlayManager.close(this.overlayName);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
setFileSize: function PDFDocumentProperties_setFileSize(fileSize) {
|
||||
setFileSize(fileSize) {
|
||||
if (fileSize > 0) {
|
||||
this.rawFileSize = fileSize;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {string} url - The URL of the document.
|
||||
*/
|
||||
setDocumentAndUrl:
|
||||
function PDFDocumentProperties_setDocumentAndUrl(pdfDocument, url) {
|
||||
setDocumentAndUrl(pdfDocument, url) {
|
||||
this.pdfDocument = pdfDocument;
|
||||
this.url = url;
|
||||
this._dataAvailableCapability.resolve();
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_getProperties: function PDFDocumentProperties_getProperties() {
|
||||
_getProperties() {
|
||||
if (!OverlayManager.active) {
|
||||
// If the dialog was closed before dataAvailablePromise was resolved,
|
||||
// don't bother updating the properties.
|
||||
// If the dialog was closed before `_dataAvailableCapability` was
|
||||
// resolved, don't bother updating the properties.
|
||||
return;
|
||||
}
|
||||
// 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]);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_updateUI: function PDFDocumentProperties_updateUI(field, content) {
|
||||
_updateUI(field, content) {
|
||||
if (field && content !== undefined && content !== '') {
|
||||
field.textContent = content;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_parseFileSize: function PDFDocumentProperties_parseFileSize() {
|
||||
_parseFileSize() {
|
||||
var fileSize = this.rawFileSize, kb = fileSize / 1024;
|
||||
if (!kb) {
|
||||
return;
|
||||
@ -166,12 +161,12 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
|
||||
size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
|
||||
size_b: fileSize.toLocaleString()
|
||||
}, '{{size_mb}} MB ({{size_b}} bytes)');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_parseDate: function PDFDocumentProperties_parseDate(inputDate) {
|
||||
_parseDate(inputDate) {
|
||||
// This is implemented according to the PDF specification, but note that
|
||||
// Adobe Reader doesn't handle changing the date to universal time
|
||||
// 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.
|
||||
// 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.
|
||||
var year = parseInt(dateToParse.substring(0, 4), 10);
|
||||
var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
|
||||
@ -214,13 +209,10 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
|
||||
var dateString = date.toLocaleDateString();
|
||||
var timeString = date.toLocaleTimeString();
|
||||
return mozL10n.get('document_properties_date_string',
|
||||
{date: dateString, time: timeString},
|
||||
{ date: dateString, time: timeString },
|
||||
'{{date}}, {{time}}');
|
||||
}
|
||||
};
|
||||
|
||||
return PDFDocumentProperties;
|
||||
})();
|
||||
}
|
||||
|
||||
export {
|
||||
PDFDocumentProperties,
|
||||
|
Loading…
x
Reference in New Issue
Block a user