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. 114
      web/annotation_layer_builder.js
  2. 9
      web/interfaces.js

114
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,88 +40,74 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() {
this.div = null; this.div = null;
} }
AnnotationLayerBuilder.prototype = /**
/** @lends AnnotationLayerBuilder.prototype */ { * @param {PageViewport} viewport
* @param {string} intent (default value is 'display')
/** */
* @param {PageViewport} viewport render(viewport, intent = 'display') {
* @param {string} intent (default value is 'display') this.pdfPage.getAnnotations({ intent }).then((annotations) => {
*/
render: function AnnotationLayerBuilder_render(viewport, intent) {
var self = this;
var parameters = { 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) { if (this.div) {
viewport = viewport.clone({ dontFlip: true }); // If an annotationLayer already exists, refresh its children's
parameters = { // transformation matrices.
viewport: viewport, AnnotationLayer.update(parameters);
div: self.div, } else {
annotations: annotations, // Create an annotation layer div and render the annotations
page: self.pdfPage, // if there is at least one annotation.
renderInteractiveForms: self.renderInteractiveForms, if (annotations.length === 0) {
linkService: self.linkService, return;
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'); 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() {
if (!this.div) {
return;
} }
this.div.setAttribute('hidden', 'true'); });
} }
};
return AnnotationLayerBuilder; hide() {
})(); if (!this.div) {
return;
}
this.div.setAttribute('hidden', 'true');
}
}
/** /**
* @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