[Pkg-javascript-commits] [pdf.js] 87/116: Refactor PDFAttachmentView to be more class-like and to separate functionality into methods
David Prévot
taffit at moszumanska.debian.org
Fri Mar 6 16:20:04 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 733882ac25fa219c1d1aa4590b01820c3ff49f17
Author: Tim van der Meij <timvandermeij at gmail.com>
Date: Tue Jan 27 22:06:19 2015 +0100
Refactor PDFAttachmentView to be more class-like and to separate functionality into methods
---
web/pdf_attachment_view.js | 77 ++++++++++++++++++++++++++++------------------
web/viewer.js | 9 +++---
2 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/web/pdf_attachment_view.js b/web/pdf_attachment_view.js
index 2d92000..b69c4bf 100644
--- a/web/pdf_attachment_view.js
+++ b/web/pdf_attachment_view.js
@@ -18,37 +18,54 @@
'use strict';
-var PDFAttachmentView = function documentAttachmentsView(options) {
- var attachments = options.attachments;
- var attachmentsView = options.attachmentsView;
- while (attachmentsView.firstChild) {
- attachmentsView.removeChild(attachmentsView.firstChild);
+var PDFAttachmentView = (function PDFAttachmentViewClosure() {
+ function PDFAttachmentView(options) {
+ this.container = options.container;
+ this.attachments = options.attachments;
}
- if (!attachments) {
- return;
- }
+ PDFAttachmentView.prototype = {
+ reset: function PDFAttachmentView_reset() {
+ var container = this.container;
+ while (container.firstChild) {
+ container.removeChild(container.firstChild);
+ }
+ },
- function bindItemLink(domObj, item) {
- domObj.onclick = function documentAttachmentsViewOnclick(e) {
- var downloadManager = new DownloadManager();
- downloadManager.downloadData(item.content, getFileName(item.filename),
- '');
- return false;
- };
- }
+ _bindLink: function PDFAttachmentView_bindLink(button, item) {
+ button.onclick = function downloadFile(e) {
+ var downloadManager = new DownloadManager();
+ var content = item.content;
+ var filename = item.filename;
+ downloadManager.downloadData(content, getFileName(filename), '');
+ return false;
+ };
+ },
- var names = Object.keys(attachments).sort(function(a,b) {
- return a.toLowerCase().localeCompare(b.toLowerCase());
- });
- for (var i = 0, ii = names.length; i < ii; i++) {
- var item = attachments[names[i]];
- var div = document.createElement('div');
- div.className = 'attachmentsItem';
- var button = document.createElement('button');
- bindItemLink(button, item);
- button.textContent = getFileName(item.filename);
- div.appendChild(button);
- attachmentsView.appendChild(div);
- }
-};
+ render: function PDFAttachmentView_render() {
+ var attachments = this.attachments;
+
+ this.reset();
+
+ if (!attachments) {
+ return;
+ }
+
+ var names = Object.keys(attachments).sort(function(a, b) {
+ return a.toLowerCase().localeCompare(b.toLowerCase());
+ });
+ for (var i = 0, len = names.length; i < len; i++) {
+ var item = attachments[names[i]];
+ var div = document.createElement('div');
+ div.className = 'attachmentsItem';
+ var button = document.createElement('button');
+ this._bindLink(button, item);
+ button.textContent = getFileName(item.filename);
+ div.appendChild(button);
+ this.container.appendChild(div);
+ }
+ }
+ };
+
+ return PDFAttachmentView;
+})();
diff --git a/web/viewer.js b/web/viewer.js
index dfce686..92ad38b 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -985,14 +985,15 @@ var PDFViewerApplication = {
}
});
pdfDocument.getAttachments().then(function(attachments) {
- var attachmentsView = document.getElementById('attachmentsView');
+ var container = document.getElementById('attachmentsView');
self.attachments = new PDFAttachmentView({
- attachments: attachments,
- attachmentsView: attachmentsView
+ container: container,
+ attachments: attachments
});
+ self.attachments.render();
document.getElementById('viewAttachments').disabled = !attachments;
- if (!attachments && !attachmentsView.classList.contains('hidden')) {
+ if (!attachments && !container.classList.contains('hidden')) {
self.switchSidebarView('thumbs');
}
if (attachments &&
--
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