1import { Controller } from "../stimulus.js"; 2 3export default class extends Controller { 4 static targets = ["icon", "menu"]; 5 #isOpen = false; 6 7 connect() { 8 this.iconTarget.addEventListener("click", this.#handleIconClick); 9 document.addEventListener("click", this.#handleOutsideClick); 10 } 11 12 disconnect() { 13 this.iconTarget.removeEventListener("click", this.#handleIconClick); 14 document.removeEventListener("click", this.#handleOutsideClick); 15 if (this.#isOpen) this.#close(); 16 } 17 18 #handleIconClick = () => { 19 this.#isOpen ? this.#close() : this.#open(); 20 }; 21 22 #handleOutsideClick = (event) => { 23 if (!this.#isOpen) return; 24 if (this.element.contains(event.target)) return; 25 this.#close(); 26 }; 27 28 #open() { 29 this.#isOpen = true; 30 this.menuTarget.classList.remove("hidden"); 31 this.iconTarget.setAttribute("aria-expanded", "true"); 32 } 33 34 #close() { 35 this.#isOpen = false; 36 this.menuTarget.classList.add("hidden"); 37 this.iconTarget.setAttribute("aria-expanded", "false"); 38 } 39}
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.