-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
119 lines (90 loc) · 2.43 KB
/
script.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
114
115
116
117
118
119
//BOARD CODE
var $src = $('#board');
var $wrap = $('<div id="board-overlay"></div>');
var $gsize = 15;
var $cols = 45;
var $rows = 25;
// Table
var $tbl = $('<table></table>');
for (var y = 1; y <= $rows; y++) {
var $tr = $('<tr></tr>');
for (var x = 1; x <= $cols; x++) {
var $td = $('<td></td>');
$td.css('width', $gsize+'px').css('height', $gsize+'px');
$tr.append($td);
}
$tbl.append($tr);
}
// Overlay
$wrap.append($tbl);
$src.after($wrap);
$('#board-overlay td').addClass('on');
//Clear
$('#clear').on('click', function(){
$('#board-overlay td').attr('class', 'on');
});
//COLOR SELECTOR
// Show current in current swatch
$('.swatch').on('click', function(){
var color = $(this).attr('id');
switch (color) {
case 'red':
$('#current').removeClass().addClass('red');
break;
case 'yellow':
$('#current').removeClass().addClass('yellow');
break;
case 'blue':
$('#current').removeClass().addClass('blue');
break;
case 'green':
$('#current').removeClass().addClass('green');
break;
case 'purple':
$('#current').removeClass().addClass('purple');
break;
case 'brown':
$('#current').removeClass().addClass('brown');
break;
case 'white':
$('#current').removeClass().addClass('white');
break;
case 'grey':
$('#current').removeClass().addClass('grey');
break;
case 'remove':
$('#current').removeClass().addClass('remove-sign');
break;
}
//Add Color to Board
$('#board-overlay td').on('click', function(){
switch (color) {
case 'red':
$(this).removeClass().addClass('red');
break;
case 'yellow':
$(this).removeClass().addClass('yellow');
break;
case 'blue':
$(this).removeClass().addClass('blue');
break;
case 'green':
$(this).removeClass().addClass('green');
break;
case 'purple':
$(this).removeClass().addClass('purple');
break;
case 'brown':
$(this).removeClass().addClass('brown');
break;
case 'white':
$(this).removeClass().addClass('white');
break;
case 'grey':
$(this).removeClass().addClass('grey');
break;
case 'remove':
$(this).removeClass();
}
});
});