-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathreference.js
78 lines (71 loc) · 2.17 KB
/
reference.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
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
/* On the test summary page, toggles the popup for the uncovered tests. */
function spec_toggle_uncovered(item_index) {
let el = document.getElementById(`uncovered-${item_index}`);
const currently_hidden = el.classList.contains('popup-hidden');
const all = document.querySelectorAll('.uncovered-rules-popup');
all.forEach(element => {
element.classList.add('popup-hidden');
});
if (currently_hidden) {
el.classList.remove('popup-hidden');
}
}
function spec_toggle_tests(rule_id) {
let el = document.getElementById(`tests-${rule_id}`);
const currently_hidden = el.classList.contains('popup-hidden');
const all = document.querySelectorAll('.tests-popup');
all.forEach(element => {
element.classList.add('popup-hidden');
});
if (currently_hidden) {
el.classList.remove('popup-hidden');
}
}
function toggle_railroad() {
const grammarRailroad = get_railroad();
set_railroad(!grammarRailroad);
update_railroad();
}
function show_railroad() {
set_railroad(true);
update_railroad();
}
function get_railroad() {
let grammarRailroad = null;
try {
grammarRailroad = localStorage.getItem('grammar-railroad');
} catch (e) {
// Ignore error.
}
grammarRailroad = grammarRailroad === 'true' ? true : false;
return grammarRailroad;
}
function set_railroad(newValue) {
try {
localStorage.setItem('grammar-railroad', newValue);
} catch (e) {
// Ignore error.
}
}
function update_railroad() {
const grammarRailroad = get_railroad();
const railroads = document.querySelectorAll('.grammar-railroad');
railroads.forEach(element => {
if (grammarRailroad) {
element.classList.remove('grammar-hidden');
} else {
element.classList.add('grammar-hidden');
}
});
const buttons = document.querySelectorAll('.grammar-toggle-railroad');
buttons.forEach(button => {
if (grammarRailroad) {
button.innerText = "Hide syntax diagram";
} else {
button.innerText = "Show syntax diagram";
}
});
}
(function railroad_onload() {
update_railroad();
})();