Repository navigation
Expand file tree
/
Copy pathjs.html
More file actions
219 lines (188 loc) · 7.66 KB
/
Copy pathjs.html
File metadata and controls
219 lines (188 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<script type="text/javascript">
// replace cmd keyboard shortcut w/ control on non-Mac platforms
const kPlatformMac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false;
if (!kPlatformMac) {
var kbds = document.querySelectorAll("kbd")
kbds.forEach(function(kbd) {
kbd.innerHTML = kbd.innerHTML.replace(/⌘/g, '⌃');
});
}
// tweak headings in pymd
document.querySelectorAll(".pymd span.co").forEach(el => {
if (!el.innerText.startsWith("#|")) {
el.style.fontWeight = 1000;
}
});
// citation format picker on landing page
document.querySelectorAll("[data-cite-picker]").forEach(picker => {
const tabs = picker.querySelectorAll("[data-citation-tab]");
const panels = picker.querySelectorAll("[data-citation-panel]");
const setActive = (format) => {
tabs.forEach(tab => {
const isActive = tab.dataset.citationTab === format;
tab.classList.toggle("is-active", isActive);
tab.setAttribute("aria-selected", isActive ? "true" : "false");
});
panels.forEach(panel => {
const isActive = panel.dataset.citationPanel === format;
panel.classList.toggle("is-active", isActive);
if (isActive) {
panel.removeAttribute("hidden");
} else {
panel.setAttribute("hidden", "hidden");
}
});
};
tabs.forEach(tab => {
tab.addEventListener("click", () => setActive(tab.dataset.citationTab));
});
});
// development-build banner: dismissable, and remembered once dismissed
(function () {
const banner = document.getElementById("bgms-dev-banner");
if (!banner) return;
const store = (() => {
try { return window.localStorage; } catch (e) { return null; }
})();
const KEY = "bgms-dev-banner-dismissed";
const hide = () => {
banner.remove();
document.body.classList.remove("bgms-dev-build");
document.documentElement.style.removeProperty("--bgms-dev-banner-height");
};
if (store && store.getItem(KEY) === "1") {
hide();
return;
}
// The banner sits above the fixed navbar, so its real height has to reach
// the CSS that pushes the navbar and the page down.
const setHeight = () => {
document.documentElement.style.setProperty(
"--bgms-dev-banner-height", banner.offsetHeight + "px");
};
setHeight();
window.addEventListener("resize", setHeight);
banner.querySelector(".bgms-dev-banner-dismiss").addEventListener("click", () => {
hide();
if (store) { try { store.setItem(KEY, "1"); } catch (e) { /* private mode */ } }
});
})();
// version switcher: a navbar dropdown built from versions.json at the site
// root. Missing or unreadable file (a local preview, say) means no dropdown.
(function () {
const offset = document.querySelector('meta[name="quarto:offset"]');
const navbar = document.querySelector("#quarto-header .navbar-nav.ms-auto");
if (!offset || !navbar) return;
// Where this build's own root is: /bgms/, /bgms/dev/, /bgms/v0.2.0.0/, ...
const buildBase = new URL(offset.content, window.location.href).pathname;
const parentOf = (path) => path.replace(/[^/]+\/$/, "");
const readJson = async (url) => {
try {
const response = await fetch(url, { cache: "no-cache" });
if (!response.ok) return null;
return await response.json();
} catch (e) {
return null;
}
};
const exists = async (url) => {
try {
const response = await fetch(url, { method: "HEAD" });
return response.ok;
} catch (e) {
return false;
}
};
const render = (siteRoot, entries, current) => {
const pagePath = window.location.pathname.slice(buildBase.length);
const item = document.createElement("li");
item.className = "nav-item dropdown bgms-version-switcher";
const toggle = document.createElement("a");
toggle.className = "nav-link dropdown-toggle";
toggle.setAttribute("role", "button");
toggle.setAttribute("href", "#");
toggle.setAttribute("aria-expanded", "false");
toggle.setAttribute("aria-haspopup", "true");
toggle.title = "Documentation version";
toggle.innerHTML = '<span class="menu-text"></span>';
toggle.querySelector(".menu-text").textContent = current.version;
const menu = document.createElement("ul");
menu.className = "dropdown-menu dropdown-menu-end";
entries.forEach(entry => {
const li = document.createElement("li");
const link = document.createElement("a");
link.className = "dropdown-item" + (entry === current ? " active" : "");
link.href = siteRoot + entry.dir;
link.innerHTML = '<span></span><span class="bgms-version-kind"></span>';
link.children[0].textContent = entry.version;
link.children[1].textContent = entry.kind === "release" ? "release" : "";
if (entry === current) link.setAttribute("aria-current", "true");
// Keep the reader on the same page across versions when that version
// has it, and send them to its homepage when it does not.
link.addEventListener("click", async (event) => {
event.preventDefault();
const home = siteRoot + entry.dir;
if (!pagePath) { window.location.href = home; return; }
const target = siteRoot + entry.dir + pagePath;
window.location.href =
(await exists(target)) ? target + window.location.hash : home;
});
li.appendChild(link);
menu.appendChild(li);
});
const close = () => {
menu.classList.remove("show");
toggle.setAttribute("aria-expanded", "false");
};
toggle.addEventListener("click", (event) => {
event.preventDefault();
const open = menu.classList.toggle("show");
toggle.setAttribute("aria-expanded", open ? "true" : "false");
});
document.addEventListener("click", (event) => {
if (!item.contains(event.target)) close();
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") close();
});
item.appendChild(toggle);
item.appendChild(menu);
navbar.insertBefore(item, navbar.firstChild);
};
(async function () {
// The index lives at the site root. A build one directory down, such as
// /dev/, finds it one level up.
let base = buildBase;
let index = await readJson(base + "versions.json");
if (!index) {
const up = parentOf(buildBase);
if (!up || up === buildBase) return;
base = up;
index = await readJson(base + "versions.json");
}
if (!index || typeof index.root !== "string" ||
!Array.isArray(index.versions)) return;
// The file names the root it belongs to. An archived build carries a
// frozen copy of it, so prefer the live one when this is not it.
let siteRoot = base;
if (index.root !== base && buildBase.startsWith(index.root)) {
siteRoot = index.root;
const live = await readJson(siteRoot + "versions.json");
if (live && Array.isArray(live.versions)) index = live;
}
const entries = index.versions
.filter(entry => typeof entry.path === "string" &&
entry.path.startsWith(index.root))
.map(entry => ({
version: entry.version,
kind: entry.kind,
dir: entry.path.slice(index.root.length)
}));
if (entries.length === 0) return;
const current = entries.find(
entry => entry.dir === buildBase.slice(siteRoot.length));
if (!current) return;
render(siteRoot, entries, current);
})();
})();
</script>