Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 12, 2024
1 parent 8306680 commit 6e8fcd6
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions panel/models/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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())
}
}
}
Expand Down

0 comments on commit 6e8fcd6

Please sign in to comment.