Merge pull request #15360 from Snuffleupagus/Popup-IGNORE_TYPES

Properly ignore PopupAnnotations with custom `trigger`-elements
This commit is contained in:
Tim van der Meij 2022-09-03 12:56:38 +02:00 committed by GitHub
commit 783c722661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1736,35 +1736,31 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
} }
class PopupAnnotationElement extends AnnotationElement { class PopupAnnotationElement extends AnnotationElement {
constructor(parameters) {
const isRenderable = !!(
parameters.data.titleObj?.str ||
parameters.data.contentsObj?.str ||
parameters.data.richText?.str
);
super(parameters, { isRenderable });
}
render() {
// Do not render popup annotations for parent elements with these types as // Do not render popup annotations for parent elements with these types as
// they create the popups themselves (because of custom trigger divs). // they create the popups themselves (because of custom trigger divs).
const IGNORE_TYPES = [ static IGNORE_TYPES = new Set([
"Line", "Line",
"Square", "Square",
"Circle", "Circle",
"PolyLine", "PolyLine",
"Polygon", "Polygon",
"Ink", "Ink",
]; ]);
this.container.className = "popupAnnotation"; constructor(parameters) {
const { data } = parameters;
if (IGNORE_TYPES.includes(this.data.parentType)) { const isRenderable =
return this.container; !PopupAnnotationElement.IGNORE_TYPES.has(data.parentType) &&
!!(data.titleObj?.str || data.contentsObj?.str || data.richText?.str);
super(parameters, { isRenderable });
} }
const selector = `[data-annotation-id="${this.data.parentId}"]`; render() {
const parentElements = this.layer.querySelectorAll(selector); this.container.className = "popupAnnotation";
const parentElements = this.layer.querySelectorAll(
`[data-annotation-id="${this.data.parentId}"]`
);
if (parentElements.length === 0) { if (parentElements.length === 0) {
return this.container; return this.container;
} }