Skip to content

Commit 92dff42

Browse files
committed
Add the javascript hooks for handling the new railroad grammar
This adds the hooks to toggle the visibility of the railroad grammar. The status is stored in localstorage to keep it sticky.
1 parent 2eeb0aa commit 92dff42

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

theme/reference.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,52 @@ function spec_toggle_tests(rule_id) {
2222
el.classList.remove('popup-hidden');
2323
}
2424
}
25+
26+
function toggle_grammar() {
27+
const grammarRailroad = get_railroad();
28+
set_railroad(!grammarRailroad);
29+
update_railroad();
30+
}
31+
32+
function get_railroad() {
33+
let grammarRailroad = null;
34+
try {
35+
grammarRailroad = localStorage.getItem('grammar-railroad');
36+
} catch (e) {
37+
// Ignore error.
38+
}
39+
grammarRailroad = grammarRailroad === 'true' ? true : false;
40+
return grammarRailroad;
41+
}
42+
43+
function set_railroad(newValue) {
44+
try {
45+
localStorage.setItem('grammar-railroad', newValue);
46+
} catch (e) {
47+
// Ignore error.
48+
}
49+
}
50+
51+
function update_railroad() {
52+
const grammarRailroad = get_railroad();
53+
const railroads = document.querySelectorAll('.grammar-railroad');
54+
railroads.forEach(element => {
55+
if (grammarRailroad) {
56+
element.classList.remove('grammar-hidden');
57+
} else {
58+
element.classList.add('grammar-hidden');
59+
}
60+
});
61+
const buttons = document.querySelectorAll('.grammar-toggle');
62+
buttons.forEach(button => {
63+
if (grammarRailroad) {
64+
button.innerText = "Hide Railroad";
65+
} else {
66+
button.innerText = "Show Railroad";
67+
}
68+
});
69+
}
70+
71+
(function railroad_onload() {
72+
update_railroad();
73+
})();

0 commit comments

Comments
 (0)