oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1// links.js: the Links panel's toggle and its phone sheet (level-up spec
2// §4.3). Without it the panel follows its cookie, the View menu's Links
3// row posts to set it, and the page's foot holds the same lists.
4(function () {
5 "use strict";
6
7 function setCookie(value) {
8 document.cookie = "mapa-links=" + value + "; path=/; max-age=31536000; samesite=lax" +
9 (location.protocol === "https:" ? "; secure" : "");
10 }
11
12 function start() {
13 var panel = document.getElementById("mapa-links");
14 var app = document.querySelector("[mapa-app]");
15 if (!panel || !app) return;
16 var toggles = document.querySelectorAll(
17 '[data-estilo-toggle][aria-controls="mapa-links"], [data-mapa-command="toggle-links"]');
18
19 function show(open) {
20 panel.hidden = !open;
21 app.setAttribute("data-links", open ? "open" : "closed");
22 toggles.forEach(function (toggle) {
23 if (toggle.hasAttribute("aria-controls")) toggle.setAttribute("aria-expanded", open ? "true" : "false");
24 });
25 setCookie(open ? "open" : "closed");
26 }
27
28 toggles.forEach(function (toggle) {
29 toggle.disabled = false;
30 toggle.addEventListener("click", function (event) {
31 event.preventDefault();
32 var menu = toggle.closest("details");
33 if (menu) menu.open = false;
34 show(panel.hidden);
35 });
36 });
37
38 // The phone's sheet: the peek line opens it; Esc or the peek closes.
39 var peek = panel.querySelector("[mapa-peek]");
40 if (peek) {
41 // Drawn hidden: without script it would be a button that does
42 // nothing, and the page's foot already has the lists.
43 peek.hidden = false;
44 peek.addEventListener("click", function () {
45 var open = !panel.hasAttribute("data-open");
46 panel.toggleAttribute("data-open", open);
47 peek.setAttribute("aria-expanded", open ? "true" : "false");
48 });
49 document.addEventListener("keydown", function (event) {
50 if (event.key === "Escape" && panel.hasAttribute("data-open")) {
51 panel.removeAttribute("data-open");
52 peek.setAttribute("aria-expanded", "false");
53 peek.focus();
54 }
55 });
56 }
57 }
58
59 if (document.readyState === "loading") {
60 document.addEventListener("DOMContentLoaded", start);
61 } else {
62 start();
63 }
64})();
65