-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
232 lines (189 loc) · 8 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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
function myFizzBuzz() {
const divWidth = document.getElementById('div_width').value;
const divHeight = document.getElementById('div_height').value;
const fizzValue = document.getElementById('fizz_value').value;
const buzzValue = document.getElementById('buzz_value').value;
const radValue = document.getElementById('border_radius').value;
const errorMsg = document.getElementById('error_messages');
const mainContainer = document.getElementById('main');
const borderSolid = document.getElementById("border_style_solid");
const borderDashed = document.getElementById("border_style_dashed");
const borderDotted = document.getElementById("border_style_dotted");
let startValue = parseInt(document.getElementById('start_value').value);
let endValue = parseInt(document.getElementById('end_value').value);
let sectionCheck = mainContainer.hasChildNodes();
if (sectionCheck) {
return errorMsg.innerText += "-- already generated, delete first --";
};
// error check switch
switch (true) {
case divWidth == '':
errorMsg.innerText = '';
return errorMsg.innerText += "-- enter div width --";
break;
case divWidth == 0:
errorMsg.innerText = '';
return errorMsg.innerText += "-- div width can't be 0px --";
break;
case divWidth < 0:
errorMsg.innerText = '';
return errorMsg.innerText += "-- div width can't be negative --";
break;
case divWidth > 200:
errorMsg.innerText = '';
return errorMsg.innerText += "-- max div width is 200px --";
break;
case divHeight == '':
errorMsg.innerText = '';
return errorMsg.innerText += "-- enter div height --";
break;
case divHeight == 0:
errorMsg.innerText = '';
return errorMsg.innerText += "-- div height can't be 0px --";
break;
case divHeight < 0:
errorMsg.innerText = '';
return errorMsg.innerText += "-- div height can't be negative --";
break;
case divHeight > 200:
errorMsg.innerText = '';
return errorMsg.innerText += "-- max div height is 200px --";
break;
case startValue > endValue:
errorMsg.innerText = '';
return errorMsg.innerText += "-- start value must be lower than end value --";
break;
case startValue == '':
errorMsg.innerText = '';
return errorMsg.innerText += "-- please enter start value --";
break;
case endValue == '':
errorMsg.innerText = '';
return errorMsg.innerText += "-- please enter start value --";
break;
case radValue < 0:
errorMsg.innerText = '';
return errorMsg.innerText += "-- border radius can't be negative --";
break;
case radValue > 50:
errorMsg.innerText = '';
return errorMsg.innerText += "-- max border radius is 50% --";
break;
case borderSolid.checked == true && borderDashed.checked == true && borderDotted.checked == true:
errorMsg.innerText = '';
return errorMsg.innerText += "-- please select only one border type --";
break;
case borderSolid.checked == true && borderDashed.checked == true:
errorMsg.innerText = '';
return errorMsg.innerText += "-- please select only one border type --";
break;
case borderSolid.checked == true && borderDotted.checked == true:
errorMsg.innerText = '';
return errorMsg.innerText += "-- please select only one border type --";
break;
case borderDashed.checked == true && borderDotted.checked == true:
errorMsg.innerText = '';
return errorMsg.innerText += "-- please select only one border type --";
break;
};
errorMsg.innerText = '';
const myContainer = document.createElement('section');
myContainer.id = "container";
document.getElementById('main').appendChild(myContainer);
for (let i = startValue; i <= endValue; i++) {
const myDiv = document.createElement('div');
myDiv.id = "block_ID_" + i;
myDiv.className = 'div_class';
myDiv.innerText = i;
myDiv.style.width = divWidth + 'px';
myDiv.style.height = divHeight + 'px';
if (i % fizzValue === 0) {
myDiv.innerText += " FIZZ";
myDiv.className = "fizz_class";
};
if (i % buzzValue === 0) {
myDiv.innerText += " BUZZ";
myDiv.className = "buzz_class";
};
if (i % fizzValue === 0 && i % buzzValue === 0) {
myDiv.className = "both_class";
};
document.getElementById('container').appendChild(myDiv);
};
};
function changeColor() {
const divColorInput = document.getElementById('div_color');
const buzzColorInput = document.getElementById('buzz_color');
const fizzColorInput = document.getElementById('fizz_color');
const bothColorInput = document.getElementById('both_color');
let divColor = divColorInput.value;
let buzzColor = buzzColorInput.value;
let fizzColor = fizzColorInput.value;
let bothColor = bothColorInput.value;
$('.div_class').css("background-color", divColor);
$('.buzz_class').css("background-color", buzzColor);
$('.fizz_class').css("background-color", fizzColor);
$('.both_class').css("background-color", bothColor);
$('.div_class, .fizz_class, .buzz_class, .both_class').css("opacity", ".6");
};
function borderRadius() {
const divBorderRadiusInput = document.getElementById('border_radius');
let borderRadius = divBorderRadiusInput.value;
$('.div_class, .buzz_class, .fizz_class, .both_class').css("border-radius", borderRadius + '%');
};
function animationToggler() {
const animationToggler = document.getElementById("animations");
if (animationToggler.checked === false) {
$('.fizz_class, .buzz_class, .both_class').css("animation-name", 'none');
}
};
function borderToggler() {
const borderSolid = document.getElementById("border_style_solid");
const borderDashed = document.getElementById("border_style_dashed");
const borderDotted = document.getElementById("border_style_dotted");
switch (true) {
case borderSolid.checked === true:
$('.div_class, .fizz_class, .buzz_class, .both_class').css("border-style", 'solid');
break;
case borderDashed.checked === true:
$('.div_class, .fizz_class, .buzz_class, .both_class').css("border-style", 'dashed');
break;
case borderDotted.checked === true:
$('.div_class, .fizz_class, .buzz_class, .both_class').css("border-style", 'dotted');
break;
}
};
// generate button
const generateBtn = document.querySelector('#generate');
generateBtn.onclick = function allTogether() {
myFizzBuzz();
changeColor();
borderRadius();
animationToggler();
borderToggler();
};
// delete button
const deleteBtn = document.querySelector('#delete');
deleteBtn.onclick = function myDestroyer() {
const main = document.getElementById('main');
const errorMsg = document.getElementById('error_messages');
const target = document.getElementById('container');
let mainState = main.hasChildNodes();
if (mainState) {
target.parentNode.removeChild(target);
errorMsg.innerText = '';
} else {
return errorMsg.innerText = "-- nothing to delete, generate first --";
}
};
// settings button
const settingsBtn = document.querySelector('#settings');
settingsBtn.onclick = function showControls() {
const controls = document.getElementById('controls');
let property = controls.getAttribute('class');
if (property == 'div_controls') {
controls.setAttribute('class', 'inactive');
} else {
controls.setAttribute('class', 'div_controls');
}
};