Validate the options before adding the ResizeObserver
in the PDFViewer
constructor (PR 15830 follow-up)
In the GENERIC viewer, it doesn't make sense to register the `ResizeObserver` if the `container`/`viewer` options are not valid.
This commit is contained in:
parent
0860a5b168
commit
9089e75cce
@ -230,20 +230,13 @@ class PDFViewer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.container = options.container;
|
this.container = options.container;
|
||||||
this.#resizeObserver.observe(this.container);
|
|
||||||
|
|
||||||
this.viewer = options.viewer || options.container.firstElementChild;
|
this.viewer = options.viewer || options.container.firstElementChild;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof PDFJSDev === "undefined" ||
|
typeof PDFJSDev === "undefined" ||
|
||||||
PDFJSDev.test("!PRODUCTION || GENERIC")
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
||||||
) {
|
) {
|
||||||
if (
|
if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
|
||||||
!(
|
|
||||||
this.container?.tagName.toUpperCase() === "DIV" &&
|
|
||||||
this.viewer?.tagName.toUpperCase() === "DIV"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error("Invalid `container` and/or `viewer` option.");
|
throw new Error("Invalid `container` and/or `viewer` option.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +247,8 @@ class PDFViewer {
|
|||||||
throw new Error("The `container` must be absolutely positioned.");
|
throw new Error("The `container` must be absolutely positioned.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.#resizeObserver.observe(this.container);
|
||||||
|
|
||||||
this.eventBus = options.eventBus;
|
this.eventBus = options.eventBus;
|
||||||
this.linkService = options.linkService || new SimpleLinkService();
|
this.linkService = options.linkService || new SimpleLinkService();
|
||||||
this.downloadManager = options.downloadManager || null;
|
this.downloadManager = options.downloadManager || null;
|
||||||
|
Loading…
Reference in New Issue
Block a user