This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
104 lines (93 loc) · 5.73 KB
/
test.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
<html>
<head>
<meta charset="UTF-8"/>
<title>Basic Typescript React Client</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<div class="grid">
<div>
<button class="square" id="1-1">Strong and Stable<div class="separator-horizontal"></div></button>
<button class="square" id="1-2">I like hats<div class="separator-horizontal"></div></button>
<button class="square" id="1-3">Reference to Paddy Ashdown eating his hat<div class="separator-horizontal"></div></button>
<button class="square" id="1-4">A4<div class="separator-horizontal"></div></button>
<button class="square" id="1-5">A5</button>
</div>
<div>
<button class="square" id="2-1">B1<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="2-2">B2<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="2-3">B3<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="2-4">B4<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="2-5">B5<div class="separator-vertical"></div></button>
</div>
<div>
<button class="square" id="3-1">C1<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="3-2">C2<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="3-3">C3<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="3-4">C4<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="3-5">C5<div class="separator-vertical"></div></button>
</div>
<div>
<button class="square" id="4-1">D1<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="4-2">D2<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="4-3">D3<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="4-4">D4<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="4-5">D5<div class="separator-vertical"></div></button>
</div>
<div>
<button class="square" id="5-1">E1<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="5-2">E2<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="5-3">E3<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="5-4">E4<div class="separator-horizontal"></div><div class="separator-vertical"></div></button>
<button class="square" id="5-5">E5<div class="separator-vertical"></div></button>
</div>
</div>
<script src="./node_modules/react/dist/react.js"></script>
<script src="./node_modules/react-dom/dist/react-dom.js"></script>
<script src="./dist/bundle.js"></script>
<script type="text/javascript">
var classname = document.getElementsByClassName("square");
var clickFunc = function() {
var attribute = this.getAttribute("data-myattribute");
this.className += " complete";
updateGrid();
};
for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', clickFunc, false);
}
updateGrid();
function updateGrid() {
var squares = document.getElementsByClassName("square");
for (var i = 0; i < classname.length; i++) {
var square = squares[i];
var id = square.id;
var gridPosition = id.split('-');
var horizontalX = parseInt(gridPosition[0]) + 1;
var verticalY = parseInt(gridPosition[1]) + 1;
var horizontalNeighbour = document.getElementById(horizontalX + "-" + gridPosition[1]);
var verticalNeighbour = document.getElementById(gridPosition[0] + "-" + verticalY);
// console.log(horizontalNeighbour);
// console.log(verticalNeighbour);
if(horizontalNeighbour != null) {
console.log(id + " has class? " + hasClass(square, "complete") + " and " + hasClass(horizontalNeighbour, "complete"));
}
if(horizontalNeighbour != null && hasClass(square, "complete") && hasClass(horizontalNeighbour, "complete")) {
for(child in square.getElementsByClassName('separator-horizontal')) {
child.className = "separator-horizontal complete";
}
}
if(verticalNeighbour != null && hasClass(square, "complete") && hasClass(verticalNeighbour, "complete")) {
for(child in square.getElementsByClassName('separator-vertical')) {
child.className = "separator-vertical complete";
}
}
}
}
function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
</script>
</body>
</html>