Skip to content

Commit 82e371c

Browse files
committed
Randomized display order of user pictures
1 parent c5b2612 commit 82e371c

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

public/js/photos.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@
1010
document.getElementById('photos_' + g).appendChild(thephoto);
1111
};
1212

13+
var menNums = randomNums(95);
14+
var womenNums = randomNums(95);
15+
var legoNums = randomNums(9); // Legos are people too
16+
1317
for (var i = 0; i <= 99; i++) {
14-
createImage(i, 'men');
18+
createImage(menNums[i], 'men');
1519
}
20+
1621
for (var i = 0; i <= 95; i++) {
17-
createImage(i, 'women');
22+
createImage(womenNums[i], 'women');
1823
}
24+
1925
for (var i = 0; i <= 9; i++) {
20-
createImage(i, 'lego');
26+
createImage(legoNums[i], 'lego');
2127
}
2228

2329
Array.prototype.slice.call(document.getElementsByTagName('img')).forEach(function(el) {
@@ -67,4 +73,26 @@
6773
}
6874
})();
6975
}
76+
77+
// It's <insert year here>, gotta be PC
78+
function randomNums(amt) {
79+
function shuffle(array) {
80+
var m = array.length, t, i;
81+
82+
// While there remain elements to shuffle…
83+
while (m) {
84+
85+
// Pick a remaining element
86+
i = Math.floor(Math.random() * m--);
87+
88+
// And swap it with the current element.
89+
t = array[m];
90+
array[m] = array[i];
91+
array[i] = t;
92+
}
93+
94+
return array;
95+
}
96+
return shuffle(new Array(amt).fill(0).map(function(v, i) { return i; }));
97+
}
7098
})();

views/pages/photos.ejs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,30 @@
1414

1515
<div class="frame">
1616

17+
<% if (Math.floor(Math.random() * 2) === 1) { %>
18+
<section id="women">
19+
<h2>Ladies</h2>
20+
<div id="photos_women"></div>
21+
</section>
22+
<section id="men">
23+
<h2>Gentlemen</h2>
24+
<div id="photos_men"></div>
25+
</section>
26+
<% } else { %>
1727
<section id="men">
1828
<h2>Gentlemen</h2>
1929
<div id="photos_men"></div>
2030
</section>
21-
2231
<section id="women">
2332
<h2>Ladies</h2>
2433
<div id="photos_women"></div>
2534
</section>
26-
35+
<% } %>
2736
<section id="lego">
2837
<h2>Lego</h2>
2938
<div id="photos_lego"></div>
3039
</section>
40+
3141
<% include ../snippets/ads %>
3242
</div>
3343
<% include ../snippets/footer %>

0 commit comments

Comments
 (0)