Explorer

html-ui.explorer-script

description
The JS of the explorer (html-ui.explorer): opens the rows of the current page (/edit/, /h/ and /batch/ are read as /p/), marks its link with aria-current, loads the parts of a module when it is opened, and closes the explorer on narrow screens
type
String
expression
"const tree = document.querySelector(\"details.explorer\");\nif (matchMedia(\"(max-width: 760px)\").matches) tree.open = false;\nconst here = decodeURIComponent(location.pathname).replace(/^\\/(edit|h|batch)\\//, \"/p/\");\nconst mark = () => {\n  for (const a of tree.querySelectorAll(\"a\")) {\n    if (decodeURIComponent(a.pathname) === here) a.setAttribute(\"aria-current\", \"page\");\n  }\n};\nconst loadParts = async (details) => {\n  if (details.dataset.loaded) return;\n  details.dataset.loaded = \"1\";\n  try {\n    const response = await fetch(details.dataset.parts);\n    if (response.ok) details.querySelector(\"ul\").innerHTML = await response.text();\n  } catch {}\n  mark();\n};\nfor (const details of tree.querySelectorAll(\"details[data-parts]\")) {\n  details.addEventListener(\"toggle\", () => {\n    if (details.open) loadParts(details);\n  });\n}\nlet current;\nfor (const details of tree.querySelectorAll(\"details[data-path]\")) {\n  const p = details.dataset.path;\n  if (here === p || here.startsWith(p + \"/\") || (details.dataset.parts && here.startsWith(p + \".\"))) {\n    details.open = true;\n    current = details;\n  }\n}\nmark();\nif (current) {\n  const top = current.querySelector(\"summary\").offsetTop;\n  if (top > tree.clientHeight / 2) tree.scrollTop = top - tree.clientHeight / 3;\n}\n"
visibility
public
html-ui.explorer-script (project html-ui, branch remove-deploy-button, snapshot dt2aPjQUrIkBOz-2trTI6JX-dnOvCsvqp9O2GMbdWn8)
id: V1luxHBnochDnfOK00TU3Ae4Gq9ql4HyKmsnaUOcV0I
content hash: ZrarVjBUZBk5z3mB94CevgcB7CA3A7R9lAk-BzpNfQE