-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolManupulationAndSizeChange.js
190 lines (167 loc) · 5.31 KB
/
toolManupulationAndSizeChange.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// tool change logic
let pencil = document.querySelector("#pencil");
let eraser = document.querySelector("#eraser");
let rect = document.querySelector("#rect");
let line = document.querySelector("#line");
// let sticky = document.querySelector("#sticky");
let options = document.querySelectorAll(".size-box");
let sizeBoxArr = document.querySelectorAll(".size-box");
let pencilSize = 5;
let eraserSize = 5;
let rectSize = 5;
let lineSize = 5;
// let bubbles = document.querySelectorAll(".size");
pencil.addEventListener("click", function () {
if (curTool == "pencil") {
options[0].style.display = "flex";
}
else {
for (let i = 0; i < options.length; i++) { // koi aur clicked aur usko options visible to vo remove ho jaaye
options[i].style.display = "none";
}
tool.strokeStyle = "red";
curTool = "pencil";
tool.lineWidth = pencilSize;
}
})
eraser.addEventListener("click", function () {
if (curTool == "eraser") {
options[1].style.display = "flex";
}
else {
for (let i = 0; i < options.length; i++) { // koi aur clicked aur usko options visible to vo remove ho jaaye
options[i].style.display = "none";
}
tool.strokeStyle = "white";
curTool = "eraser";
tool.lineWidth = eraserSize;
}
})
rect.addEventListener("click", function () {
if (curTool == "rect") {
options[2].style.display = "flex";
}
else {
for (let i = 0; i < options.length; i++) { // koi aur clicked aur usko options visible to vo remove ho jaaye
options[i].style.display = "none";
}
tool.strokeStyle = "red";
curTool = "rect";
tool.lineWidth = rectSize;
}
})
line.addEventListener("click", function () {
if (curTool == "line") {
options[3].style.display = "flex";
}
else {
for (let i = 0; i < options.length; i++) { // koi aur clicked aur usko options visible to vo remove ho jaaye
options[i].style.display = "none";
}
tool.strokeStyle = "red";
curTool = "line";
tool.lineWidth = lineSize;
}
})
// Color change logic
let redColor = document.querySelector(".red");
let greenColor = document.querySelector(".green");
let blueColor = document.querySelector(".blue");
redColor.addEventListener("click", function () {
tool.strokeStyle = "red";
})
greenColor.addEventListener("click", function () {
tool.strokeStyle = "green";
})
blueColor.addEventListener("click", function () {
tool.strokeStyle = "blue";
})
// Size change logic
// pencil
sizeBoxArr[0].addEventListener("click", function (e) {
let elements = ["size1", "size2", "size3", "size4"];
let allTheClasses = e.target.classList; // saari classes bta deta hai
let firstClass = allTheClasses[0];
let test = elements.includes(firstClass);
if (test) {
if (firstClass == "size1") {
pencilSize = 5;
}
else if (firstClass == "size2") {
pencilSize = 10;
}
else if (firstClass == "size3") {
pencilSize = 15;
}
else if (firstClass == "size4") {
pencilSize = 20;
}
}
tool.lineWidth = pencilSize;
})
// eraser
sizeBoxArr[1].addEventListener("click", function (e) {
let elements = ["size1", "size2", "size3", "size4"];
let allTheClasses = e.target.classList; // saari classes bta deta hai
let firstClass = allTheClasses[0];
let test = elements.includes(firstClass);
if (test) {
if (firstClass == "size1") {
eraserSize = 5;
}
else if (firstClass == "size2") {
eraserSize = 10;
}
else if (firstClass == "size3") {
eraserSize = 15;
}
else if (firstClass == "size4") {
eraserSize = 20;
}
}
tool.lineWidth = eraserSize;
})
// rect
sizeBoxArr[2].addEventListener("click", function (e) {
let elements = ["size1", "size2", "size3", "size4"];
let allTheClasses = e.target.classList; // saari classes bta deta hai
let firstClass = allTheClasses[0];
let test = elements.includes(firstClass);
if (test) {
if (firstClass == "size1") {
rectSize = 5;
}
else if (firstClass == "size2") {
rectSize = 10;
}
else if (firstClass == "size3") {
rectSize = 15;
}
else if (firstClass == "size4") {
rectSize = 20;
}
}
tool.lineWidth = rectSize;
})
// line
sizeBoxArr[3].addEventListener("click", function (e) {
let elements = ["size1", "size2", "size3", "size4"];
let allTheClasses = e.target.classList; // saari classes bta deta hai
let firstClass = allTheClasses[0];
let test = elements.includes(firstClass);
if (test) {
if (firstClass == "size1") {
lineSize = 5;
}
else if (firstClass == "size2") {
lineSize = 10;
}
else if (firstClass == "size3") {
lineSize = 15;
}
else if (firstClass == "size4") {
lineSize = 20;
}
}
tool.lineWidth = lineSize;
})