-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesigns.js
56 lines (47 loc) · 1.66 KB
/
designs.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
/**
* @description Make the grid
*/
function makeGrid() {
let tableHeight = $('#inputHeight').val();
let tableWidth = $('#inputWidth').val();
$("#inputHeight").attr("value", tableHeight);
$("#inputWidth").attr("value", tableWidth);
for (let i = 0; i < tableHeight; i++) {
//create many elements and set their location once each
let tableRow = $('<tr></tr>');
$("#pixelCanvas").append(tableRow);
for (let j = 0; j < tableWidth; j++) {
//create many elements and set their location once each
let tableColumnData = $('<td></td>');
tableRow.append(tableColumnData);
}
}
}
// Submit and Reset functionality if any children and click on submit then reset the grid otherwise make the grid
$("#sizePicker").on("submit", function (event) {
event.preventDefault();
if ($("#pixelCanvas").children().length > 0) {
$("#pixelCanvas").empty();
makeGrid();
} else {
makeGrid();
}
})
/**
* @description Fill color to grid square element
* @param {object} squareElement - the current target of square element
*/
function fillColor(squareElement) {
let squareColor = $('#colorPicker').val();
$(squareElement).css("background-color", squareColor);
}
// When user clicking on a grid square causes only that square to change color
let changeColor = $("#pixelCanvas").on("click", "td", function (event) {
fillColor($(event.currentTarget));
});
// When user double click on a grid squuare causes only that sqaure to clean color
let cleanColor = $("#pixelCanvas").on("dblclick", "td", function () {
$(this).removeAttr("style");
});
changeColor();
cleanColor();