1import { Controller } from "@hotwired/stimulus" 2 3const ROWS = ".game-category__item, .cz-menu__item" 4const CHANGED = ["turbo:load", "turbo:before-stream-render"] 5 6// Keeps the mark on the row for the page being looked at when the page changes 7// underneath the menu. A category is opened by pushing its address and fetching a 8// stream that replaces the game grid alone, so the menu that named it is never 9// re-rendered â the mark the server put there would sit on whichever page was 10// last loaded whole, however many categories were opened after it. 11// 12// Rows addressing a section of the page they are already on are left alone: which 13// of those is current is a question about scrolling, and cz-hub-spy answers it. 14export default class extends Controller { 15 connect() { 16 this.sync = () => this.mark() 17 CHANGED.forEach((name) => document.addEventListener(name, this.sync)) 18 window.addEventListener("popstate", this.sync) 19 } 20 21 disconnect() { 22 CHANGED.forEach((name) => document.removeEventListener(name, this.sync)) 23 window.removeEventListener("popstate", this.sync) 24 } 25 26 mark() { 27 const here = window.location.pathname 28 const scrolled = document.querySelector("[data-cz-hub-hero]") !== null 29 30 this.element.querySelectorAll(ROWS).forEach((row) => { 31 if (scrolled && row.dataset.czHubRow) return 32 if (!row.href || row.getAttribute("href").includes("#")) return 33 34 row.classList.toggle("is-current", new URL(row.href).pathname === here) 35 }) 36 37 // A group is marked by what it holds: the page its own label opens, or a row 38 // inside it that is current. 39 this.element.querySelectorAll(".cz-menu__group").forEach((group) => { 40 const label = group.querySelector(".cz-menu__tile") 41 const own = label && new URL(label.href).pathname === here 42 const inside = group.querySelector(".navbar__body .is-current") !== null 43 44 group.querySelector(".navbar__head").classList.toggle("is-current", own || inside) 45 }) 46 } 47};
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.