-
Notifications
You must be signed in to change notification settings - Fork 197
/
index.js
42 lines (36 loc) · 1.27 KB
/
index.js
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
import d3 from "d3";
import gaEventHandler from "./lib/eventhandler";
require("./lib/react_setup");
gaEventHandler();
// When a link is clicked and the current page becomes the definitions page,
// and there is an anchor in the link; then open the accordion corresponding to
// the anchor if one exists.
window.addEventListener("hashchange", openDefinitionAccordionForAnchor);
window.addEventListener("load", openDefinitionAccordionForAnchor);
function openDefinitionAccordionForAnchor() {
// Both /definitions and /definitions/ are required here because locally the
// trailing slash is present for all links for some reason.
if (
(window.location.pathname != "/definitions" &&
window.location.pathname != "/definitions/") ||
window.location.hash == ""
) {
return;
}
const accordionButtonWrapper = d3.select(window.location.hash);
if (hasChildElement(accordionButtonWrapper)) {
const accordionButton = accordionButtonWrapper[0][0].children[0];
if (accordionButton.ariaExpanded == "false") {
accordionButton.click();
}
}
}
function hasChildElement(d3Selection) {
return (
!!d3Selection &&
Array.isArray(d3Selection) &&
Array.isArray(d3Selection[0]) &&
!!d3Selection[0][0].children &&
!!d3Selection[0][0].children[0]
);
}