-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatives.html
More file actions
289 lines (271 loc) · 8.97 KB
/
creatives.html
File metadata and controls
289 lines (271 loc) · 8.97 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body class="container" style="padding: 10px;">
<div id="drawer" class="drawer">
<div class="container">
<div class="header">
<h4>Creative Creation</h4>
<a href="javascript:void(0)" class="closebtn" onclick="closeForm()">×</a>
</div>
<form class="row g-3 form" id="creativeForm" onsubmit="addCreative(); return false">
<div class="col-md-12">
<label for="title" class="form-label">Title</label>
<input type="text" name="title" class="form-control" id="title" required>
</div>
<div class="col-md-12">
<label for="subtitle" class="form-label">Subtitle</label>
<input type="text" name="subtitle" class="form-control" id="subtitle" required>
</div>
<div class="col-12" id='backgroundColor'>
<h4> Background Color : </h4>
</div>
<div class="col-12">
<button class="btn btn-primary" type="submit">Done</button>
</div>
</form>
</div>
</div>
<div class="main">
<h1 style="text-align: center;">Creatives</h1>
<div class="filters container row">
<h3>Filter by</h3>
<div style="display: flex;margin: 20px;">
<div class="col-md-3">
<h4>colors :</h4>
<div class="row colors" id="colors"></div>
</div>
<div class="col-md-3">
<h4>title/subtitle : </h4>
<input type="text" onkeyup="filter()" class="form-control" id="filtertxt" placeholder="title/subtitle">
</div>
</div>
<div class="row" style="align-items: center;">
<div class="col-md-6 progress">
<div class="progress-bar" id="progress-bar" role="progressbar"></div>
</div>
<div class="col-md-3">
<h4 id="progressAria">0/5 Creatives</h4>
</div>
</div>
</div>
<button id="addCreative" type="button" class="btn btn-outline-dark button" onclick="openForm()">+ Add Creative</button>
<div class="container " id="creatives"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
</script>
<script src="script.js"></script>
</body>
</html>
<style>
.box{
border: 2px solid black;
padding: 12px;
border-radius: 6px;
max-width: 500px;
text-align: center;
margin: 10px;
}
.box .box-title{
font-size: x-large;
font-weight: bolder;
margin: 10px;
}
.box .box-subtitle{
margin-top: 0;
margin-bottom: 16px;
}
.colors{
min-height: 100px;
margin: 10px;
}
.txt{
min-width: 200px;
max-width: 200px;
margin: 10px;
min-height: 100px;
padding: 10px;
}
.color-box{
min-width: 50px !important;
min-height: 25px !important;
}
.progress{
max-width: 500px;
border: 2px solid black;
border-radius: 15px !important;
padding: 0% !important;
margin-right: 10px;
}
.filters{
margin: 20px;
}
.button{
margin: 20px;
min-width: 200px;
}
.form{
padding: 20px;
}
.remove{
display: none;
}
/* the side navigation menu */
.drawer{
height: 100%;
/* 100% Full-height */
width: 0;
/* 0 width - change this with JavaScript */
position: fixed;
/* Stay in place */
z-index: 1;
/* Stay on top */
top: 0;
/* Stay at the top */
right: 0;
-webkit-box-shadow: -9px 4px 32px -15px rgba(0, 0, 0, 1);
-moz-box-shadow: -9px 4px 32px -15px rgba(0, 0, 0, 1);
box-shadow: -9px 4px 32px -15px rgba(0, 0, 0, 1);
overflow-x: hidden;
/* Disable horizontal scroll */
padding-top: 60px;
/* Place content 60px from the top */
transition: 0.5s;
/* 0.5 second transition effect to slide in the drawer */
}
/* Position and style the close button (top right corner) */
.drawer .closebtn {
position: absolute;
color: black;
text-decoration: none;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
</style>
<script>
var COLORS = [];
var PROGRESS = 0;
const URL = 'https://random-flat-colors.vercel.app/api/random?count=5';
function openForm() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
const res = JSON.parse(xmlHttp.response).colors;
console.log(res);
let colors = document.getElementById('backgroundColor');
let div = document.createElement('div');
div.id = 'radio';
div.className = 'col-md-6';
res.forEach((color) => {
let colorBox = ColorBox(color, 'radio');
div.appendChild(colorBox);
});
colors.appendChild(div);
}
};
xmlHttp.open('GET', URL, true);
xmlHttp.send(null);
document.getElementById('drawer').style.width = '35%';
document.getElementById('addCreative').disabled = true;
}
function closeForm() {
document.getElementById('radio').remove();
document.getElementById('drawer').style.width = '0';
document.getElementById('addCreative').disabled = false;
}
function Creative(title, subtitle, color) {
let creatives = document.getElementById('creatives');
let box = document.createElement('div');
let boxTitle = document.createElement('div');
let boxSubtitle = document.createElement('div');
box.className = 'box ' + color;
boxTitle.className = 'box-title';
boxSubtitle.className = 'box-subtitle';
boxTitle.textContent = title;
boxSubtitle.textContent = subtitle;
box.appendChild(boxTitle);
box.appendChild(boxSubtitle);
box.style.background = color;
creatives.appendChild(box);
}
function setProgress(val) {
let progressBar = document.getElementById('progress-bar');
document.getElementById('progressAria').textContent = val + '/5 Creatives';
progressBar.style.width = val * 20 + '%';
}
function ColorBox(color, type) {
let div = document.createElement('div');
let input = document.createElement('input');
let label = document.createElement('label');
div.className = 'form-check col-md-6';
input.className = 'form-check-input ' + type;
input.type = type;
input.required = true;
input.name = 'backgroundColor';
input.value = color;
label.className = 'form-check-label color-box ';
label.style.background = color;
div.appendChild(input);
div.appendChild(label);
if (type == 'checkbox') {
input.checked = true;
}
return div;
}
function addCreative() {
if (PROGRESS === 5) {
alert('Max number of creatives have been created');
return;
}
const form = document.getElementById('creativeForm');
let colors = document.getElementById('colors');
const title = form.elements['title'].value;
const subtitle = form.elements['subtitle'].value;
const color = form.elements['backgroundColor'].value;
Creative(title, subtitle, color);
PROGRESS += 1;
setProgress(PROGRESS);
if (!COLORS.includes(color)) {
var colorBox = ColorBox(color, 'checkbox');
colors.appendChild(colorBox);
COLORS.push(color);
}
closeForm();
form.elements['title'].value = '';
form.elements['subtitle'].value = '';
const checkboxes = document.querySelectorAll('input[type=checkbox]:checked');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].addEventListener('change', filter);
}
}
function filter() {
var array = [];
const creatives = document.getElementsByClassName('box');
const input = document.getElementById('filtertxt').value.toUpperCase();
const checkboxes = document.querySelectorAll('input[type=checkbox]:checked');
for (var i = 0; i < checkboxes.length; i++) {
array.push(checkboxes[i].value);
}
for (var i = 0; i < creatives.length; i++) {
let title = creatives[i].getElementsByClassName('box-title')[0].textContent.toUpperCase();
let subtitle = creatives[i].getElementsByClassName('box-subtitle')[0].textContent.toUpperCase();
if (array.includes(creatives[i].className.split(' ').pop())) {
if (input && title.toUpperCase().indexOf(input) == -1 && subtitle.toUpperCase().indexOf(input) == -1) {
creatives[i].style.display = 'none';
} else {
creatives[i].style.display = '';
}
} else {
creatives[i].style.display = 'none';
}
}
}
</script>