PageSourceSearch

https://pika.page/assets/controllers/anchor_links_controller-864e6…efba9ed768fa9cbbe0fae61705da0773509a50c5.js

js pika.page collected 2026-10-03 21:44:24 UTC 633 bytes, 23 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3export default class extends Controller {
4  connect() {
5    this.addAnchorLinks()
6  }
7
8  addAnchorLinks() {
9    const headings = this.element.querySelectorAll("h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]")
10
11    headings.forEach((heading) => {
12      const id = heading.id
13      if (id) {
14        const anchor = document.createElement("a")
15        anchor.href = `#${id}`
16        anchor.className = "anchor"
17        anchor.title = "Jump to this heading"
18        anchor.setAttribute("aria-hidden", "true")
19        heading.insertBefore(anchor, heading.firstChild)
20      }
21    })
22  }
23};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.