Skip to content

Commit c099a6f

Browse files
committed
Add a separate JS file for shuffling the funding page
1 parent 981f33f commit c099a6f

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/assets.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub struct CSSFiles {
106106
#[derive(Serialize, Debug)]
107107
pub struct JSFiles {
108108
tools_install: String,
109+
funding_shuffle: String,
109110
}
110111

111112
#[derive(Serialize, Debug)]
@@ -125,6 +126,7 @@ pub fn compile_assets(
125126
let fonts_css_file = compile_sass(root_dir, out_dir, "fonts", base_url)?;
126127
let vendor_css_file = concat_vendor_css(root_dir, out_dir, vec!["tachyons"])?;
127128
let tools_install_js = build_js_file(root_dir, out_dir, "tools-install")?;
129+
let funding_shuffle_js = build_js_file(root_dir, out_dir, "funding-shuffle")?;
128130

129131
Ok(AssetFiles {
130132
css: CSSFiles {
@@ -134,6 +136,7 @@ pub fn compile_assets(
134136
},
135137
js: JSFiles {
136138
tools_install: format!("{base_url}/{tools_install_js}"),
139+
funding_shuffle: format!("{base_url}/{funding_shuffle_js}"),
137140
},
138141
})
139142
}

static/scripts/funding-shuffle.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// From https://stackoverflow.com/a/2450976/1107768
2+
function shuffle(array) {
3+
let currentIndex = array.length;
4+
5+
// While there remain elements to shuffle...
6+
while (currentIndex !== 0) {
7+
// Pick a remaining element...
8+
let randomIndex = Math.floor(Math.random() * currentIndex);
9+
currentIndex--;
10+
11+
// And swap it with the current element.
12+
[array[currentIndex], array[randomIndex]] = [
13+
array[randomIndex], array[currentIndex]];
14+
}
15+
}
16+
17+
document.addEventListener("DOMContentLoaded", () => {
18+
// Shuffle people to reduce ordering bias
19+
const wrapper = document.querySelector("#people");
20+
const children = Array(...wrapper.children);
21+
shuffle(children);
22+
wrapper.replaceChildren(...children);
23+
});

templates/funding.html.hbs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,8 @@
2525
{{> member member=member baseurl=../baseurl }}
2626
{{/each}}
2727
</div>
28-
<script type="text/javascript">
29-
// From https://stackoverflow.com/a/2450976/1107768
30-
function shuffle(array) {
31-
let currentIndex = array.length;
32-
33-
// While there remain elements to shuffle...
34-
while (currentIndex !== 0) {
35-
// Pick a remaining element...
36-
let randomIndex = Math.floor(Math.random() * currentIndex);
37-
currentIndex--;
38-
39-
// And swap it with the current element.
40-
[array[currentIndex], array[randomIndex]] = [
41-
array[randomIndex], array[currentIndex]];
42-
}
43-
}
44-
45-
document.addEventListener("DOMContentLoaded", () => {
46-
// Shuffle people to reduce ordering bias
47-
const wrapper = document.querySelector("#people");
48-
const children = Array(...wrapper.children);
49-
shuffle(children);
50-
wrapper.replaceChildren(...children);
51-
});
52-
</script>
28+
<script type="text/javascript" src="{{assets.js.funding_shuffle}}"></script>
5329
</section>
54-
5530
{{/inline}}
5631

5732
{{~> (lookup this "parent")~}}

0 commit comments

Comments
 (0)