-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
91 lines (76 loc) · 2.45 KB
/
index.html
File metadata and controls
91 lines (76 loc) · 2.45 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Cards</title>
<style type="text/css">
body,
html {
display: block;
height: 100%;
width: 100%;
margin: 0 auto;
padding: 0;
}
h1 {
text-align: center;
}
#container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
}
.card {
flex: 1 1;
background-color: #000000;
text-align: center;
padding: 2em;
margin: 1em;
cursor: pointer;
border-radius: 1em;
font-size: 300%;
}
</style>
</head>
<body>
<h1>Cards</h1>
<div id="container">
</div>
<script type="text/javascript">
(function() {
/* Get the GET parameter */
var cards = window.location.search.substr(1).split("=")[1].split(",");
/* shuffle input array */
cards = shuffle(cards);
/* insert cards */
var container = document.getElementById("container");
for (var i = 0; i < cards.length; i++) {
container.insertAdjacentHTML('beforeend', `<span class='card'>${cards[i]}</span>`);
}
/* event management */
var cardElements = document.getElementsByClassName("card");
for (var i = 0; i < cardElements.length; i++) {
cardElements[i].addEventListener("click", function() {
this.style.backgroundColor = "white";
});
}
})();
/* Shuffle function taken from https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array */
function shuffle(array) {
var currentIndex = array.length,
temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
</script>
</body>
</html>