-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
201 lines (189 loc) · 4.15 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
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
// Cache the Border Corners' Inputs
const corners = document.querySelectorAll(".border-corner"),
c1 = document.querySelector("#corner-1"),
c2 = document.querySelector("#corner-2"),
c3 = document.querySelector("#corner-3"),
c4 = document.querySelector("#corner-4")
// Cache the 'demo' container
const demo = document.querySelector(".demo")
// Cache the 'code' container
const code = document.querySelector(".code")
for(let i = 0; i < corners.length; i++) {
// Attach an Event to each 'Corner's Input' change
corners[i].addEventListener("change", () => {
applyDemo()
})
}
function applyDemo() {
// Change the 'border-radius' value of the demo
let value = `${c1.value}px ${c2.value}px ${c3.value}px ${c4.value}px`
demo.style.borderRadius = value
// View the code
code.innerHTML = showCode(c1.value, c2.value, c3.value, c4.value)
}
function showCode(c1, c2, c3, c4) {
const codeNoPrefix = `
<span>-webkit-border-radius: ${c1}px ${c2}px ${c3}px ${c4}px;</span>
<span>-moz-border-radius: ${c1}px ${c2}px ${c3}px ${c4}px;</span>
<span>border-radius: ${c1}px ${c2}px ${c3}px ${c4}px;</span>
`
return codeNoPrefix
}
// Copy To Clipboard
const copyBtn = document.querySelector("#copy-btn")
const popup = document.querySelector(".popup")
copyBtn.addEventListener("click", () => {
copyToClipboard()
// Add the 'animated' class to the popup
popup.classList.add("animated")
// Remove that class
setTimeout(() => {
popup.classList.remove("animated")
}, 500)
})
function copyToClipboard(){
const tempTxt = document.createElement("textarea")
tempTxt.value = code.textContent
document.body.appendChild(tempTxt)
tempTxt.select()
document.execCommand("copy")
document.body.removeChild(tempTxt)
}
// Pre-Developed Shapes
let c1_val = c1.value,
c2_val = c2.value,
c3_val = c3.value,
c4_val = c4.value
const shapesCornerValues = [
{
c1_val: 150,
c2_val: 150,
c3_val: 150,
c4_val: 150
},
{
c1_val: 150,
c2_val: 150,
c3_val: 0,
c4_val: 0
},
{
c1_val: 0,
c2_val: 150,
c3_val: 150,
c4_val: 0,
},
{
c1_val: 0,
c2_val: 0,
c3_val: 150,
c4_val: 150
},
{
c1_val: 150,
c2_val: 0,
c3_val: 0,
c4_val: 150
},
{
c1_val: 150,
c2_val: 0,
c3_val: 150,
c4_val: 0
},
{
c1_val: 0,
c2_val: 150,
c3_val: 0,
c4_val: 150
},
{
c1_val: 150,
c2_val: 150,
c3_val: 150,
c4_val: 0
},
{
c1_val: 150,
c2_val: 150,
c3_val: 0,
c4_val: 150
},
{
c1_val: 150,
c2_val: 0,
c3_val: 150,
c4_val: 150
},
{
c1_val: 0,
c2_val: 150,
c3_val: 150,
c4_val: 150
},
{
c1_val: 150,
c2_val: 0,
c3_val: 0,
c4_val: 0
},
{
c1_val: 0,
c2_val: 150,
c3_val: 0,
c4_val: 0
},
{
c1_val: 0,
c2_val: 0,
c3_val: 150,
c4_val: 0
},
{
c1_val: 0,
c2_val: 0,
c3_val: 0,
c4_val: 150
},
{
c1_val: 300,
c2_val: 0,
c3_val: 0,
c4_val: 0
},
{
c1_val: 0,
c2_val: 300,
c3_val: 0,
c4_val: 0
},
{
c1_val: 0,
c2_val: 0,
c3_val: 300,
c4_val: 0
},
{
c1_val: 0,
c2_val: 0,
c3_val: 0,
c4_val: 300
},
{
c1_val: 50,
c2_val: 50,
c3_val: 50,
c4_val: 50
}
]
const shapesElements = document.querySelectorAll(".shape")
for(let i = 0; i < shapesElements.length; i++) {
shapesElements[i].addEventListener("click", () => {
// Overwrite the current demo's values with each shape values
c1.value = shapesCornerValues[i].c1_val
c2.value = shapesCornerValues[i].c2_val
c3.value = shapesCornerValues[i].c3_val
c4.value = shapesCornerValues[i].c4_val
applyDemo()
})
}