[Pkg-javascript-commits] [pdf.js] 95/119: Simplify document properties field logic
David Prévot
taffit at moszumanska.debian.org
Wed May 13 21:27:46 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 6abf3d6ba3c2783a4d9c10f82e3c419c094f4c49
Author: Tim van der Meij <timvandermeij at gmail.com>
Date: Fri Apr 24 21:19:58 2015 +0200
Simplify document properties field logic
This patch:
- Simplifies the way fields are passed to the document properties overlay
- Simplifies the way fields are filled internally in the document properties overlay
- Avoids passing a document properties reference to the secondary toolbar
---
web/pdf_document_properties.js | 60 ++++++++++++++++--------------------------
web/secondary_toolbar.js | 3 +--
web/viewer.js | 27 ++++++++++---------
3 files changed, 38 insertions(+), 52 deletions(-)
diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js
index 7767d9a..51e36ec 100644
--- a/web/pdf_document_properties.js
+++ b/web/pdf_document_properties.js
@@ -20,7 +20,9 @@
/**
* @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 {HTMLButtonElement} closeButton - Button for closing the overlay.
*/
/**
@@ -32,24 +34,12 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
* @param {PDFDocumentPropertiesOptions} options
*/
function PDFDocumentProperties(options) {
+ this.fields = options.fields;
+ this.overlayName = options.overlayName;
+
this.rawFileSize = 0;
this.url = null;
this.pdfDocument = null;
- this.overlayName = options.overlayName;
-
- // Set the document property fields.
- this.fileNameField = options.fileNameField || null;
- this.fileSizeField = options.fileSizeField || null;
- this.titleField = options.titleField || null;
- this.authorField = options.authorField || null;
- this.subjectField = options.subjectField || null;
- this.keywordsField = options.keywordsField || null;
- this.creationDateField = options.creationDateField || null;
- this.modificationDateField = options.modificationDateField || null;
- this.creatorField = options.creatorField || null;
- this.producerField = options.producerField || null;
- this.versionField = options.versionField || null;
- this.pageCountField = options.pageCountField || null;
// Bind the event listener for the Close button.
if (options.closeButton) {
@@ -125,33 +115,29 @@ var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {
return;
}
this.setFileSize(data.length);
- this._updateUI(this.fileSizeField, this._parseFileSize());
+ this._updateUI(this.fields['fileSize'], this._parseFileSize());
}.bind(this));
// Get the document properties.
this.pdfDocument.getMetadata().then(function(data) {
- var fields = [
- { field: this.fileNameField,
- content: getPDFFileNameFromURL(this.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 },
- { field: this.keywordsField, content: data.info.Keywords },
- { field: this.creationDateField,
- content: this._parseDate(data.info.CreationDate) },
- { field: this.modificationDateField,
- content: this._parseDate(data.info.ModDate) },
- { field: this.creatorField, content: data.info.Creator },
- { field: this.producerField, content: data.info.Producer },
- { field: this.versionField, content: data.info.PDFFormatVersion },
- { field: this.pageCountField, content: this.pdfDocument.numPages }
- ];
+ var content = {
+ 'fileName': getPDFFileNameFromURL(this.url),
+ 'fileSize': this._parseFileSize(),
+ 'title': data.info.Title,
+ 'author': data.info.Author,
+ 'subject': data.info.Subject,
+ 'keywords': data.info.Keywords,
+ 'creationDate': this._parseDate(data.info.CreationDate),
+ 'modificationDate': this._parseDate(data.info.ModDate),
+ 'creator': data.info.Creator,
+ 'producer': data.info.Producer,
+ 'version': data.info.PDFFormatVersion,
+ 'pageCount': this.pdfDocument.numPages
+ };
// Show the properties in the dialog.
- for (var item in fields) {
- var element = fields[item];
- this._updateUI(element.field, element.content);
+ for (var identifier in content) {
+ this._updateUI(this.fields[identifier], content[identifier]);
}
}.bind(this));
},
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 0b3f3d5..2714d79 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -25,7 +25,6 @@ var SecondaryToolbar = {
initialize: function secondaryToolbarInitialize(options) {
this.toolbar = options.toolbar;
- this.documentProperties = options.documentProperties;
this.buttonContainer = this.toolbar.firstElementChild;
// Define the toolbar buttons.
@@ -115,7 +114,7 @@ var SecondaryToolbar = {
},
documentPropertiesClick: function secondaryToolbarDocumentPropsClick(evt) {
- this.documentProperties.open();
+ PDFViewerApplication.pdfDocumentProperties.open();
this.close();
},
diff --git a/web/viewer.js b/web/viewer.js
index a842a5d..2cc02e5 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -177,18 +177,20 @@ var PDFViewerApplication = {
this.pdfDocumentProperties = new PDFDocumentProperties({
overlayName: 'documentPropertiesOverlay',
closeButton: document.getElementById('documentPropertiesClose'),
- fileNameField: document.getElementById('fileNameField'),
- fileSizeField: document.getElementById('fileSizeField'),
- titleField: document.getElementById('titleField'),
- authorField: document.getElementById('authorField'),
- subjectField: document.getElementById('subjectField'),
- keywordsField: document.getElementById('keywordsField'),
- creationDateField: document.getElementById('creationDateField'),
- modificationDateField: document.getElementById('modificationDateField'),
- creatorField: document.getElementById('creatorField'),
- producerField: document.getElementById('producerField'),
- versionField: document.getElementById('versionField'),
- pageCountField: document.getElementById('pageCountField')
+ fields: {
+ 'fileName': document.getElementById('fileNameField'),
+ 'fileSize': document.getElementById('fileSizeField'),
+ 'title': document.getElementById('titleField'),
+ 'author': document.getElementById('authorField'),
+ 'subject': document.getElementById('subjectField'),
+ 'keywords': document.getElementById('keywordsField'),
+ 'creationDate': document.getElementById('creationDateField'),
+ 'modificationDate': document.getElementById('modificationDateField'),
+ 'creator': document.getElementById('creatorField'),
+ 'producer': document.getElementById('producerField'),
+ 'version': document.getElementById('versionField'),
+ 'pageCount': document.getElementById('pageCountField')
+ }
});
SecondaryToolbar.initialize({
@@ -204,7 +206,6 @@ var PDFViewerApplication = {
lastPage: document.getElementById('lastPage'),
pageRotateCw: document.getElementById('pageRotateCw'),
pageRotateCcw: document.getElementById('pageRotateCcw'),
- documentProperties: this.pdfDocumentProperties,
documentPropertiesButton: document.getElementById('documentProperties')
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list