Convert the annotation layer builder to ES6 syntax

This commit is contained in:
Tim van der Meij 2017-04-23 20:52:58 +02:00
parent 99d35a1039
commit 3554a93c2b
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 53 additions and 72 deletions

View File

@ -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,

View File

@ -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) {}
}