╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ script.js ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
312 313 document.addEventListener("click", (event) => { 314 const t = event.target; 315 if (t && t.tagName === "INPUT" && t.readOnly) t.select(); 316 }); 317 318 document.addEventListener("focusin", (event) => { 319 const t = event.target; 320 if (!t || !t.dataset || !t.dataset.focusId) return; 321 // sync the wasm focus to wherever the browser moved focus 322 wasmInstance.exports._setFocus(Number(t.dataset.focusId)); 323 // a click's mousedown fires this focusin before the click event. ticking 324 // here would rebuild #grid and destroy the node before its click lands, 325 // swallowing the navigation and forcing a second click — so don't 326 // re-render for a grid element. overlay controls live outside #grid and 327 // survive the diff, so they still tick. 328 if (!grid.contains(t)) wasmInstance.exports._tick(minRows(), maxCols()); 329 }); 330 331 grid.addEventListener("click", (event) => { 332 const span = event.target.closest(".clickable"); 333 if (!span) return; 334 // leave modified / non-left clicks (open-in-new-tab, etc.) to the browser 335 if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; 336 // wasm routes the click: an in-page link just moves focus and re-renders, 337 // a cross-page one calls _navigate. suppress the <a>'s own navigation so 338 // an in-page link doesn't also trigger a redundant full page load. 339 event.preventDefault(); 340 const focusId = Number(span.dataset.focusId); 341 wasmInstance.exports._onMouseClick(focusId); 342 wasmInstance.exports._tick(minRows(), maxCols()); 343 }); 344 345 let resizeTimer = null; 346 window.addEventListener("resize", () => { 347 clearTimeout(resizeTimer); 348 resizeTimer = setTimeout(() => { 349 wasmInstance.exports._tick(minRows(), maxCols()); 350 }, 100); 351 }); 352 }); 353