diff --git a/panel/models/html.ts b/panel/models/html.ts index 9f8c5f3a4a..a1ab0ae3c4 100644 --- a/panel/models/html.ts +++ b/panel/models/html.ts @@ -8,18 +8,16 @@ import {serializeEvent} from "./event-to-object" function searchAllDOMs(node: Element | ShadowRoot, selector: string): (Element | ShadowRoot)[] { let found: (Element | ShadowRoot)[] = [] - if (node instanceof Element && node.matches(selector)) { found.push(node) } node.children && Array.from(node.children).forEach(child => { found = found.concat(searchAllDOMs(child, selector)) }) - if (node instanceof Element && node.shadowRoot) { - found = found.concat(searchAllDOMs(node.shadowRoot, selector)); + found = found.concat(searchAllDOMs(node.shadowRoot, selector)) } - return found; + return found } @server_event("html_stream") @@ -151,17 +149,17 @@ export class HTMLView extends PanelMarkupView { run_scripts(this.container) } this._setup_event_listeners() - for (const anchor of this.container.querySelectorAll('a')) { - const link = anchor.getAttribute('href') - if (link && link.startsWith('#')) { - anchor.addEventListener('click', () => { + for (const anchor of this.container.querySelectorAll("a")) { + const link = anchor.getAttribute("href") + if (link && link.startsWith("#")) { + anchor.addEventListener("click", () => { const found = searchAllDOMs(document.body, link) if (found.length && found[0] instanceof Element) { found[0].scrollIntoView() } }) if (!this.root.has_finished() && window.location.hash === link) { - this.model.document.on_event('document_ready', () => anchor.scrollIntoView()) + this.model.document.on_event("document_ready", () => anchor.scrollIntoView()) } } }