-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumber.square.js
84 lines (62 loc) · 1.92 KB
/
number.square.js
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
var RCW = {};
(function(RCW) {
var _RED = "#df4a32";
var _WHITE = "#FFFFFF";
var _elm;
var _reset;
var _squares = [];
var _modifiying = false;
var reset = function() {
if (_modifiying === true) {
return;
}
_modifiying = true;
for (var idx = 0; idx < _squares.length; idx++) {
if (_squares[idx].enabled) {
_squares[idx].disable();
}
}
_modifiying = false;
};
var start = function() {
var square, row;
_elm = document.getElementById("numberSquare");
row = document.createElement("tr");
for (var idx = 0; idx < 100; idx++) {
if (idx > 0 && idx % 10 === 0) {
_elm.appendChild(row);
row = document.createElement("tr");
}
square = document.createElement("td");
square.innerText = (idx + 1);
square.enabled = false;
square.enable = function() {
this.style.backgroundColor = _WHITE;
this.style.color = _RED;
this.style.borderColor = _RED;
};
square.disable = function() {
this.style.backgroundColor = _RED;
this.style.color = _WHITE;
this.style.borderColor = _WHITE;
};
square.onclick = function() {
if (_modifiying === true) {
return;
}
if (this.enabled) {
this.disable();
} else {
this.enable();
}
this.enabled = !this.enabled;
};
_squares.push(square);
row.appendChild(square);
}
_elm.appendChild(row);
_reset = document.getElementById("clear");
_reset.onclick = reset;
};
RCW.start = start;
})(RCW);