Browse Source

Convert the annotation layer builder to ES6 syntax

Tim van der Meij 8 years ago
parent
commit
3554a93c2b
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
  1. 72
      web/annotation_layer_builder.js
  2. 9
      web/interfaces.js

72
web/annotation_layer_builder.js

@ -26,15 +26,11 @@ import { SimpleLinkService } from './pdf_link_service';
* @property {DownloadManager} downloadManager * @property {DownloadManager} downloadManager
*/ */
/** class AnnotationLayerBuilder {
* @class
*/
var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
/** /**
* @param {AnnotationLayerBuilderOptions} options * @param {AnnotationLayerBuilderOptions} options
* @constructs AnnotationLayerBuilder
*/ */
function AnnotationLayerBuilder(options) { constructor(options) {
this.pageDiv = options.pageDiv; this.pageDiv = options.pageDiv;
this.pdfPage = options.pdfPage; this.pdfPage = options.pdfPage;
this.renderInteractiveForms = options.renderInteractiveForms; this.renderInteractiveForms = options.renderInteractiveForms;
@ -44,32 +40,23 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
this.div = null; this.div = null;
} }
AnnotationLayerBuilder.prototype =
/** @lends AnnotationLayerBuilder.prototype */ {
/** /**
* @param {PageViewport} viewport * @param {PageViewport} viewport
* @param {string} intent (default value is 'display') * @param {string} intent (default value is 'display')
*/ */
render: function AnnotationLayerBuilder_render(viewport, intent) { render(viewport, intent = 'display') {
var self = this; this.pdfPage.getAnnotations({ intent }).then((annotations) => {
var parameters = { var parameters = {
intent: (intent === undefined ? 'display' : intent), viewport: viewport.clone({ dontFlip: true }),
}; div: this.div,
annotations,
this.pdfPage.getAnnotations(parameters).then(function (annotations) { page: this.pdfPage,
viewport = viewport.clone({ dontFlip: true }); renderInteractiveForms: this.renderInteractiveForms,
parameters = { linkService: this.linkService,
viewport: viewport, downloadManager: this.downloadManager,
div: self.div,
annotations: annotations,
page: self.pdfPage,
renderInteractiveForms: self.renderInteractiveForms,
linkService: self.linkService,
downloadManager: self.downloadManager,
}; };
if (self.div) { if (this.div) {
// If an annotationLayer already exists, refresh its children's // If an annotationLayer already exists, refresh its children's
// transformation matrices. // transformation matrices.
AnnotationLayer.update(parameters); AnnotationLayer.update(parameters);
@ -80,52 +67,47 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
return; return;
} }
self.div = document.createElement('div'); this.div = document.createElement('div');
self.div.className = 'annotationLayer'; this.div.className = 'annotationLayer';
self.pageDiv.appendChild(self.div); this.pageDiv.appendChild(this.div);
parameters.div = self.div; parameters.div = this.div;
AnnotationLayer.render(parameters); AnnotationLayer.render(parameters);
if (typeof mozL10n !== 'undefined') { if (typeof mozL10n !== 'undefined') {
mozL10n.translate(self.div); mozL10n.translate(this.div);
} }
} }
}); });
}, }
hide: function AnnotationLayerBuilder_hide() { hide() {
if (!this.div) { if (!this.div) {
return; return;
} }
this.div.setAttribute('hidden', 'true'); this.div.setAttribute('hidden', 'true');
} }
}; }
return AnnotationLayerBuilder;
})();
/** /**
* @constructor
* @implements IPDFAnnotationLayerFactory * @implements IPDFAnnotationLayerFactory
*/ */
function DefaultAnnotationLayerFactory() {} class DefaultAnnotationLayerFactory {
DefaultAnnotationLayerFactory.prototype = {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage, createAnnotationLayerBuilder(pageDiv, pdfPage,
renderInteractiveForms) { renderInteractiveForms = false) {
return new AnnotationLayerBuilder({ return new AnnotationLayerBuilder({
pageDiv: pageDiv, pageDiv,
pdfPage: pdfPage, pdfPage,
renderInteractiveForms: renderInteractiveForms, renderInteractiveForms,
linkService: new SimpleLinkService(), linkService: new SimpleLinkService(),
}); });
} }
}; }
export { export {
AnnotationLayerBuilder, AnnotationLayerBuilder,

9
web/interfaces.js

@ -108,14 +108,13 @@ IPDFTextLayerFactory.prototype = {
/** /**
* @interface * @interface
*/ */
function IPDFAnnotationLayerFactory() {} class IPDFAnnotationLayerFactory { // eslint-disable-line no-unused-vars
IPDFAnnotationLayerFactory.prototype = {
/** /**
* @param {HTMLDivElement} pageDiv * @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage * @param {PDFPage} pdfPage
* @param {boolean} renderInteractiveForms * @param {boolean} renderInteractiveForms
* @returns {AnnotationLayerBuilder} * @returns {AnnotationLayerBuilder}
*/ */
createAnnotationLayerBuilder: function (pageDiv, pdfPage, createAnnotationLayerBuilder(pageDiv, pdfPage,
renderInteractiveForms) {} renderInteractiveForms = false) {}
}; }

Loading…
Cancel
Save