-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.js
49 lines (42 loc) · 1.23 KB
/
cell.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
class Cell {
constructor(value) {
this.number = value;
this.isFixed = true;
}
createElement() {
this.element = document.createElement('div');
this.element.classList.add('cell');
this.updateNumberElement();
return this.element;
}
setActive(isActive, activeBackground) {
if(isActive) {
this.element.classList.add('active');
this.element.style.backgroundImage = activeBackground;
} else {
this.element.classList.remove('active');
this.element.style.backgroundImage = "";
}
}
setFixed(isFixed) {
this.isFixed = isFixed;
if(isFixed)
this.element.classList.add('is-fixed');
else
this.element.classList.remove('is-fixed');
}
setMistake(hasMistake) {
if(hasMistake)
this.element.classList.add('has-mistake');
else
this.element.classList.remove('has-mistake');
}
setNumber(number) {
this.number = number;
this.updateNumberElement();
}
updateNumberElement() {
if(this.element)
this.element.innerHTML = `<h1>${this.number !== null ? this.number : ''}</h1>`;
}
}