-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
113 lines (77 loc) · 2.5 KB
/
app.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
function makeGrid() {
for (let i = 0; i < 64; i++) {
let newDiv = $('<div class="cell">')
$('.grid').append(newDiv);
}
}
makeGrid();
const palette = [
'red',
'blue',
'yellow',
'green',
'pink',
'white',
'black',
'purple'
]
// $('.palette button').first().addClass('active');
function makePalette() {
for (let i = 0; i < palette.length; i++) {
const nextColor = palette[i]
const button = $('<button>')
.css('backgroundColor', nextColor);
$('.palette').append(button);
}
$('.palette button').first().addClass('active');
}
makePalette();
function onPaletteClick() {
$('.palette button').removeClass('active');
$(this).addClass('active')
}
$('.palette button').click(onPaletteClick);
function onGridClick() {
const element = $(this)
if (element.css('backgroundColor') === $('.palette .active').first().css('backgroundColor')) {
element.css('backgroundColor', 'rgba(0, 0, 0, 0)');
}
else {
element.css('backgroundColor', $('.palette .active').first().css('backgroundColor'))
}
}
$('.grid .cell').click(onGridClick);
// $('.grid .cell').click(onGridClick);
// $('.grid .cell').click(onGridClick);
function onClearClick() {
$('.grid .cell').css('backgroundColor', "");
}
$('.controls .clear').click(onClearClick);
function onFillAllClick() {
let color = $('.palette .active').css('backgroundColor');
$('.grid .cell').css('backgroundColor', color);
}
$('.controls .fill-all').click(onFillAllClick);
function onFillEmpty() {
const elements = $('.grid .cell')
for (let index = 0; index < elements.length; index = index + 1) {
let nextElement = $( elements[index] );
if (nextElement.css('backgroundColor') == 'rgba(0, 0, 0, 0)') {
nextElement.css('backgroundColor', $('.palette .active').css('backgroundColor'))
}
}
}
$('.controls .fill-empty').click(onFillEmpty)
// function addColor() {
// }
// const redButton = $('<button>')
// .css('backgroundColor', 'red');
// const blueButton = $('<button>')
// .css('backgroundColor', 'blue');
// const yellowButton = $('<button>')
// .css('backgroundColor', 'yellow');
// const greenButton = $('<button>')
// .css('backgroundColor', 'green');
// palette.append(blueButton);
// palette.append(yellowButton);
// palette.append(greenButton);