Convert the annotation layer builder to ES6 syntax
This commit is contained in:
parent
99d35a1039
commit
3554a93c2b
@ -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');
|
|
||||||
self.div.className = 'annotationLayer';
|
|
||||||
self.pageDiv.appendChild(self.div);
|
|
||||||
parameters.div = self.div;
|
|
||||||
|
|
||||||
AnnotationLayer.render(parameters);
|
|
||||||
if (typeof mozL10n !== 'undefined') {
|
|
||||||
mozL10n.translate(self.div);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
hide: function AnnotationLayerBuilder_hide() {
|
this.div = document.createElement('div');
|
||||||
if (!this.div) {
|
this.div.className = 'annotationLayer';
|
||||||
return;
|
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
|
* @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,
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user