diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 8c5b66ef3..b9fb74065 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -26,15 +26,11 @@ import { SimpleLinkService } from './pdf_link_service'; * @property {DownloadManager} downloadManager */ -/** - * @class - */ -var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() { +class AnnotationLayerBuilder { /** * @param {AnnotationLayerBuilderOptions} options - * @constructs AnnotationLayerBuilder */ - function AnnotationLayerBuilder(options) { + constructor(options) { this.pageDiv = options.pageDiv; this.pdfPage = options.pdfPage; this.renderInteractiveForms = options.renderInteractiveForms; @@ -44,88 +40,74 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() { this.div = null; } - AnnotationLayerBuilder.prototype = - /** @lends AnnotationLayerBuilder.prototype */ { - - /** - * @param {PageViewport} viewport - * @param {string} intent (default value is 'display') - */ - render: function AnnotationLayerBuilder_render(viewport, intent) { - var self = this; + /** + * @param {PageViewport} viewport + * @param {string} intent (default value is 'display') + */ + render(viewport, intent = 'display') { + this.pdfPage.getAnnotations({ intent }).then((annotations) => { var parameters = { - intent: (intent === undefined ? 'display' : intent), + viewport: viewport.clone({ dontFlip: true }), + div: this.div, + annotations, + page: this.pdfPage, + renderInteractiveForms: this.renderInteractiveForms, + linkService: this.linkService, + downloadManager: this.downloadManager, }; - this.pdfPage.getAnnotations(parameters).then(function (annotations) { - viewport = viewport.clone({ dontFlip: true }); - parameters = { - viewport: viewport, - div: self.div, - annotations: annotations, - page: self.pdfPage, - renderInteractiveForms: self.renderInteractiveForms, - linkService: self.linkService, - downloadManager: self.downloadManager, - }; - - if (self.div) { - // If an annotationLayer already exists, refresh its children's - // transformation matrices. - AnnotationLayer.update(parameters); - } else { - // Create an annotation layer div and render the annotations - // if there is at least one annotation. - if (annotations.length === 0) { - return; - } - - self.div = document.createElement('div'); - self.div.className = 'annotationLayer'; - self.pageDiv.appendChild(self.div); - parameters.div = self.div; - - AnnotationLayer.render(parameters); - if (typeof mozL10n !== 'undefined') { - mozL10n.translate(self.div); - } + if (this.div) { + // If an annotationLayer already exists, refresh its children's + // transformation matrices. + AnnotationLayer.update(parameters); + } else { + // Create an annotation layer div and render the annotations + // if there is at least one annotation. + if (annotations.length === 0) { + return; } - }); - }, - hide: function AnnotationLayerBuilder_hide() { - if (!this.div) { - return; + this.div = document.createElement('div'); + this.div.className = 'annotationLayer'; + this.pageDiv.appendChild(this.div); + parameters.div = this.div; + + AnnotationLayer.render(parameters); + if (typeof mozL10n !== 'undefined') { + mozL10n.translate(this.div); + } } - this.div.setAttribute('hidden', 'true'); - } - }; + }); + } - return AnnotationLayerBuilder; -})(); + hide() { + if (!this.div) { + return; + } + this.div.setAttribute('hidden', 'true'); + } +} /** - * @constructor * @implements IPDFAnnotationLayerFactory */ -function DefaultAnnotationLayerFactory() {} -DefaultAnnotationLayerFactory.prototype = { +class DefaultAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage * @param {boolean} renderInteractiveForms * @returns {AnnotationLayerBuilder} */ - createAnnotationLayerBuilder: function (pageDiv, pdfPage, - renderInteractiveForms) { + createAnnotationLayerBuilder(pageDiv, pdfPage, + renderInteractiveForms = false) { return new AnnotationLayerBuilder({ - pageDiv: pageDiv, - pdfPage: pdfPage, - renderInteractiveForms: renderInteractiveForms, + pageDiv, + pdfPage, + renderInteractiveForms, linkService: new SimpleLinkService(), }); } -}; +} export { AnnotationLayerBuilder, diff --git a/web/interfaces.js b/web/interfaces.js index 291cfc440..6c2b9a02a 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -108,14 +108,13 @@ IPDFTextLayerFactory.prototype = { /** * @interface */ -function IPDFAnnotationLayerFactory() {} -IPDFAnnotationLayerFactory.prototype = { +class IPDFAnnotationLayerFactory { // eslint-disable-line no-unused-vars /** * @param {HTMLDivElement} pageDiv * @param {PDFPage} pdfPage * @param {boolean} renderInteractiveForms * @returns {AnnotationLayerBuilder} */ - createAnnotationLayerBuilder: function (pageDiv, pdfPage, - renderInteractiveForms) {} -}; + createAnnotationLayerBuilder(pageDiv, pdfPage, + renderInteractiveForms = false) {} +}