Convert the attachments/outline view to ES6 syntax
This commit is contained in:
parent
0e8f020e2e
commit
93520172f6
@ -30,16 +30,13 @@ import {
|
||||
* @property {Array|null} attachments - An array of attachment objects.
|
||||
*/
|
||||
|
||||
class PDFAttachmentViewer {
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
/**
|
||||
* @constructs PDFAttachmentViewer
|
||||
* @param {PDFAttachmentViewerOptions} options
|
||||
*/
|
||||
function PDFAttachmentViewer(options) {
|
||||
constructor(options) {
|
||||
this.attachments = null;
|
||||
|
||||
this.container = options.container;
|
||||
this.eventBus = options.eventBus;
|
||||
this.downloadManager = options.downloadManager;
|
||||
@ -49,8 +46,7 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
this._appendAttachment.bind(this));
|
||||
}
|
||||
|
||||
PDFAttachmentViewer.prototype = {
|
||||
reset: function PDFAttachmentViewer_reset(keepRenderedCapability) {
|
||||
reset(keepRenderedCapability = false) {
|
||||
this.attachments = null;
|
||||
|
||||
// Remove the attachments from the DOM.
|
||||
@ -61,20 +57,19 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
// not be replaced is when appending file attachment annotations.
|
||||
this._renderedCapability = createPromiseCapability();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_dispatchEvent:
|
||||
function PDFAttachmentViewer_dispatchEvent(attachmentsCount) {
|
||||
_dispatchEvent(attachmentsCount) {
|
||||
this.eventBus.dispatch('attachmentsloaded', {
|
||||
source: this,
|
||||
attachmentsCount: attachmentsCount,
|
||||
attachmentsCount,
|
||||
});
|
||||
|
||||
this._renderedCapability.resolve();
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@ -106,24 +101,22 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
window.open(viewerUrl);
|
||||
return false;
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_bindLink:
|
||||
function PDFAttachmentViewer_bindLink(button, content, filename) {
|
||||
button.onclick = function downloadFile(e) {
|
||||
_bindLink(button, content, filename) {
|
||||
button.onclick = () => {
|
||||
this.downloadManager.downloadData(content, filename, '');
|
||||
return false;
|
||||
}.bind(this);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PDFAttachmentViewerRenderParameters} params
|
||||
*/
|
||||
render: function PDFAttachmentViewer_render(params) {
|
||||
params = params || {};
|
||||
render(params = {}) {
|
||||
var attachments = params.attachments || null;
|
||||
var attachmentsCount = 0;
|
||||
|
||||
@ -162,13 +155,13 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
}
|
||||
|
||||
this._dispatchEvent(attachmentsCount);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to append FileAttachment annotations to the sidebar.
|
||||
* @private
|
||||
*/
|
||||
_appendAttachment: function PDFAttachmentViewer_appendAttachment(item) {
|
||||
_appendAttachment(item) {
|
||||
this._renderedCapability.promise.then(function (id, filename, content) {
|
||||
var attachments = this.attachments;
|
||||
|
||||
@ -182,19 +175,16 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() {
|
||||
}
|
||||
}
|
||||
attachments[id] = {
|
||||
filename: filename,
|
||||
content: content,
|
||||
filename,
|
||||
content,
|
||||
};
|
||||
this.render({
|
||||
attachments: attachments,
|
||||
attachments,
|
||||
keepRenderedCapability: true,
|
||||
});
|
||||
}.bind(this, item.id, item.filename, item.content));
|
||||
},
|
||||
};
|
||||
|
||||
return PDFAttachmentViewer;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
PDFAttachmentViewer,
|
||||
|
@ -17,7 +17,7 @@ import {
|
||||
addLinkAttributes, PDFJS, removeNullCharacters
|
||||
} from './pdfjs';
|
||||
|
||||
var DEFAULT_TITLE = '\u2013';
|
||||
const DEFAULT_TITLE = '\u2013';
|
||||
|
||||
/**
|
||||
* @typedef {Object} PDFOutlineViewerOptions
|
||||
@ -31,48 +31,45 @@ var DEFAULT_TITLE = '\u2013';
|
||||
* @property {Array|null} outline - An array of outline objects.
|
||||
*/
|
||||
|
||||
class PDFOutlineViewer {
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
/**
|
||||
* @constructs PDFOutlineViewer
|
||||
* @param {PDFOutlineViewerOptions} options
|
||||
*/
|
||||
function PDFOutlineViewer(options) {
|
||||
constructor(options) {
|
||||
this.outline = null;
|
||||
this.lastToggleIsShow = true;
|
||||
|
||||
this.container = options.container;
|
||||
this.linkService = options.linkService;
|
||||
this.eventBus = options.eventBus;
|
||||
}
|
||||
|
||||
PDFOutlineViewer.prototype = {
|
||||
reset: function PDFOutlineViewer_reset() {
|
||||
reset() {
|
||||
this.outline = null;
|
||||
this.lastToggleIsShow = true;
|
||||
|
||||
// Remove the outline from the DOM.
|
||||
this.container.textContent = '';
|
||||
|
||||
// Ensure that the left (right in RTL locales) margin is always reset,
|
||||
// to prevent incorrect outline alignment if a new document is opened.
|
||||
this.container.classList.remove('outlineWithDeepNesting');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_dispatchEvent: function PDFOutlineViewer_dispatchEvent(outlineCount) {
|
||||
_dispatchEvent(outlineCount) {
|
||||
this.eventBus.dispatch('outlineloaded', {
|
||||
source: this,
|
||||
outlineCount: outlineCount
|
||||
outlineCount,
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_bindLink: function PDFOutlineViewer_bindLink(element, item) {
|
||||
_bindLink(element, item) {
|
||||
if (item.url) {
|
||||
addLinkAttributes(element, {
|
||||
url: item.url,
|
||||
@ -80,21 +77,21 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
});
|
||||
return;
|
||||
}
|
||||
var self = this, destination = item.dest;
|
||||
var destination = item.dest;
|
||||
|
||||
element.href = self.linkService.getDestinationHash(destination);
|
||||
element.onclick = function () {
|
||||
element.href = this.linkService.getDestinationHash(destination);
|
||||
element.onclick = () => {
|
||||
if (destination) {
|
||||
self.linkService.navigateTo(destination);
|
||||
this.linkService.navigateTo(destination);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_setStyles: function PDFOutlineViewer_setStyles(element, item) {
|
||||
_setStyles(element, item) {
|
||||
var styleStr = '';
|
||||
if (item.bold) {
|
||||
styleStr += 'font-weight: bold;';
|
||||
@ -106,7 +103,7 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
if (styleStr) {
|
||||
element.setAttribute('style', styleStr);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend a button before an outline item which allows the user to toggle
|
||||
@ -114,20 +111,20 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_addToggleButton: function PDFOutlineViewer_addToggleButton(div) {
|
||||
_addToggleButton(div) {
|
||||
var toggler = document.createElement('div');
|
||||
toggler.className = 'outlineItemToggler';
|
||||
toggler.onclick = function(event) {
|
||||
event.stopPropagation();
|
||||
toggler.onclick = (evt) => {
|
||||
evt.stopPropagation();
|
||||
toggler.classList.toggle('outlineItemsHidden');
|
||||
|
||||
if (event.shiftKey) {
|
||||
if (evt.shiftKey) {
|
||||
var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
|
||||
this._toggleOutlineItem(div, shouldShowAll);
|
||||
}
|
||||
}.bind(this);
|
||||
};
|
||||
div.insertBefore(toggler, div.firstChild);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the visibility of the subtree of an outline item.
|
||||
@ -138,30 +135,29 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_toggleOutlineItem:
|
||||
function PDFOutlineViewer_toggleOutlineItem(root, show) {
|
||||
_toggleOutlineItem(root, show) {
|
||||
this.lastToggleIsShow = show;
|
||||
var togglers = root.querySelectorAll('.outlineItemToggler');
|
||||
for (var i = 0, ii = togglers.length; i < ii; ++i) {
|
||||
togglers[i].classList[show ? 'remove' : 'add']('outlineItemsHidden');
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse or expand all subtrees of the outline.
|
||||
*/
|
||||
toggleOutlineTree: function PDFOutlineViewer_toggleOutlineTree() {
|
||||
toggleOutlineTree() {
|
||||
if (!this.outline) {
|
||||
return;
|
||||
}
|
||||
this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PDFOutlineViewerRenderParameters} params
|
||||
*/
|
||||
render: function PDFOutlineViewer_render(params) {
|
||||
var outline = (params && params.outline) || null;
|
||||
render(params = {}) {
|
||||
var outline = params.outline || null;
|
||||
var outlineCount = 0;
|
||||
|
||||
if (this.outline) {
|
||||
@ -215,10 +211,7 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
||||
|
||||
this._dispatchEvent(outlineCount);
|
||||
}
|
||||
};
|
||||
|
||||
return PDFOutlineViewer;
|
||||
})();
|
||||
}
|
||||
|
||||
export {
|
||||
PDFOutlineViewer,
|
||||
|
Loading…
Reference in New Issue
Block a user