-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
442 lines (369 loc) · 19 KB
/
index.html
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!-- REMAINING ISSUE - IE DOES NOT RECOGNIZE GRID GAP - NEED TO RENDER SOME OTHER WAY -->
<!DOCTYPE html>
<html>
<head>
<style>
* {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
/* @media screen and (max-width:767px) {
* {
font-size: 1rem;
}
} */
main {
width: 65vw;
margin: auto auto;
}
@media screen and (max-width:767px) {
main {
width: 90vw;
}
}
#objectBuilder>ol {
padding: 2rem;
}
@media screen and (max-width:767px) {
#objectBuilder>ol {
padding: 0;
}
}
input {
padding: 0.5rem;
border-bottom: 1px solid #e9e9e9;
border-top: none;
border-right: none;
border-left: none;
}
a {
opacity: 0.25;
display: block;
position: relative;
}
a h2 {
border-top: 1px solid black;
position: absolute;
bottom: 0;
width: 100%;
padding-bottom: 20%;
}
button#reset,
button#reset {
display: inline-block;
margin: 1rem;
}
.main-container .grid_container>div {
margin: 0 auto!important;
}
.grid_zone {
position: relative;
}
.grid_zone.selectable,
.grid_zone.next_selectable,
.grid_zone.not_selectable {
background-color: #e2e2e2;
transition: background-color 0.5s;
}
.grid_zone.not_selectable {
opacity: 0.25;
}
.grid_zone.next_selectable:after {
content: "";
background-image: url("data:image/svg+xml,%3Csvg width='400' height='400' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='none' d='M-1-1h402v402H-1z'/%3E%3Cg%3E%3Ctext stroke='%23000' transform='matrix(2.49488 0 0 2.49488 37.91 25.443)' font-family='Helvetica, Arial, sans-serif' font-size='250' y='156.746' x='-8.027' stroke-width='0'%3E+%3C/text%3E%3C/g%3E%3C/svg%3E");
background-color: transparent;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
opacity: 0.125;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
}
.grid_zone.first_selected,
.grid_zone.selected {
background-color: rgba(250, 0, 0, 1.0);
}
.grid_zone.selectable,
.grid_zone.next_selectable {
cursor: pointer;
}
.grid_zone.not_selectable {
cursor: text;
}
.grid_zone.selectable:hover,
.grid_zone.next_selectable:hover {
background-image: url("data:image/svg+xml,%3Csvg width='400' height='400' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='none' d='M-1-1h402v402H-1z'/%3E%3Cg%3E%3Ctext stroke='%23000' transform='matrix(2.49488 0 0 2.49488 37.91 25.443)' font-family='Helvetica, Arial, sans-serif' font-size='250' y='156.746' x='-8.027' stroke-width='0'%3E+%3C/text%3E%3C/g%3E%3C/svg%3E");
background-color: rgba(250, 0, 0, 1.0);
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
opacity: 0.5;
}
</style>
</head>
<body>
<main>
<h1 style="text-align:center;text-decoration: underline;text-transform: uppercase;">Build grid zone definitions</h1>
<br>
<form id="objectBuilder" action="
" style="width:inherit;margin:auto auto;border:1px solid #e9e9e9;text-align:center;border-radius:5px;box-shadow: inset 0px 0px 50px #e9e9e9;">
<ol style="padding: 0 3rem;">
<li>
<fieldset>
<legend>Row Tracks & Column Tracks</legend>
<div style="margin-top: 2rem;"><label for="rows">Enter number of row tracks: </label>
<input id="rows" name="rows" type="text" required="true" placeholder="Required"> <span style="color:red;">*</span></div>
<div style="margin-top: 2rem;"><label for="columns">Enter number of column tracks: </label>
<input id="columns" name="columns" type="text" required="true" placeholder="Required"> <span style="color:red;">*</span></div>
</fieldset>
</li>
<li style="margin-top: 2rem;">
<fieldset>
<legend>Zones</legend>
<div style="margin-top: 2rem;"><label for="zonesQty">Enter number of zones: </label>
<input id="zonesQty" name="Zones Qty" type="text" required="true" placeholder="Required"> <span style="color:red;">*</span></div>
</fieldset>
</li>
</ol>
<button id="submitBuild" type="submit">Build!</button>
</form>
<br>
<span class="instruction" style="display:block;"></span>
<div id="gridDisplay" style="text-align: center;position:relative;"></div>
</main>
<script>
var gridColsRowsDefsSubmit = document.getElementById("submitBuild"),
gridZonesDefsSubmit = document.getElementById("submitPost"),
zonesQtyInput = document.getElementById("zonesQty"),
styleSheet = document.createElement('style'),
gridDisplay = document.getElementById('gridDisplay'),
gridForm = document.getElementById('objectBuilder'),
breakGridObject = {},
gridObject = {
row: '',
col: ''
},
gridObjectsArray = [],
gridCellsArray = [];
gridColsRowsDefsSubmit.addEventListener('click', function(event) {
event.preventDefault();
var gridderCompile = '',
rowsQtyInput = document.getElementById("rows"),
columnsQtyInput = document.getElementById("columns"),
zonesMessageContainer = document.getElementsByClassName("instruction")[0],
columns = '',
rows = '',
totalChildNumber = rowsQtyInput.value * columnsQtyInput.value;
if (/[0-9]{1,}/.test(rowsQtyInput.value) == false || rowsQtyInput.value == 0) {
rowsQtyInput.value = '';
rowsQtyInput.setAttribute('placeholder', 'Greater than 0.');
} else if (/[0-9]{1,}/.test(columnsQtyInput.value) == false || columnsQtyInput.value == 0) {
columnsQtyInput.value = '';
columnsQtyInput.setAttribute('placeholder', 'Greater than 0.');
} else if (/[0-9]{1,}/.test(zonesQtyInput.value) == false || columnsQtyInput.value == 0) {
zonesQtyInput.value = '';
zonesQtyInput.setAttribute('placeholder', 'Greater than 0.');
} else if (zonesQtyInput.value > totalChildNumber) {
zonesQtyInput.value = '';
zonesQtyInput.setAttribute('placeholder', 'Less than row x cols.');
zonesMessageContainer.innerHTML = '';
} else {
styleSheet.setAttribute('id', 'builder');
document.head.appendChild(styleSheet);
gridForm.style.display = "none";
zonesMessageContainer.innerHTML = '<h2>' + columnsQtyInput.value + 'x' + rowsQtyInput.value + ' grid: You have chosen to create <strong class="zone_counter">' + zonesQtyInput.value + '</strong> zones.</h2><p>For each zone, click on grid cells to complete a 4-edge shape. (<em style="color:#b1b1b1;">Ex. rectangle or square</em>). Click "post" <b>when <span style="text-transform:uppercase;">current</span> zone is completed</b> to record the zone.</p><div style="text-align:center;"><button id="post" type="submit">Post!</button><button id="reset" type="reset">Reset!</button></div>';
var gridColsRowsDefsReset = document.getElementById("reset"),
gridCells = document.getElementsByClassName('selectable');
for (var i = 0; i < columnsQtyInput.value; i++) {
columns += ' 1fr';
}
for (var j = 0; j < rowsQtyInput.value; j++) {
rows += ' 1fr';
}
for (var k = 0; k < totalChildNumber; k++) {
gridderCompile += '<div class="grid_zone selectable" id="grid_' + (k + 1) + '" style="position:relative;border: 1px solid white;text-align: center;"><h3 style="margin: 0 0;width: 100%;height: auto;position: absolute;top: 50%;">#' + (k + 1) + '</h3></div>';
}
gridDisplay.innerHTML = '<div>' + gridderCompile + '</div>';
styleSheet.innerHTML = '#gridDisplay>div{position:relative;width:inherit;height:100vh;display:grid;grid-template-columns:' + columns + ';grid-template-rows:' + rows + ';}';
objectBuilderReset(gridDisplay, styleSheet, gridColsRowsDefsReset, zonesMessageContainer, rowsQtyInput, columnsQtyInput, zonesQtyInput, gridForm);
objectBuilderPost(zonesQtyInput.value);
buildArray(rowsQtyInput.value, columnsQtyInput.value);
for (var i = 0; i < gridCells.length; i++) {
//var gridCellsClassName = gridCells[i].getAttribute('class');
firstCellSelect(gridCells[i], nextCellSelect);
}
}
});
// FUNCTIONS
function objectBuilderReset(el, stylesheet, reset, messaging, rowsQtyInput, columnsQtyInput, zonesQtyInput, gridForm) {
reset.addEventListener('click', function() {
gridForm.style.display = "block";
rowsQtyInput.value = '';
columnsQtyInput.value = '';
zonesQtyInput.value = '';
el.innerHTML = '';
stylesheet.innerHTML = '';
reset.style.display = 'none';
messaging.innerHTML = '';
gridCellsArray = [];
});
}
function objectBuilderPost() {
var postButton = document.getElementById('post');
postButton.addEventListener('click', function() {
//get all selected cells
var selectedCells = document.querySelectorAll('div[class*="selected"]'),
selectedCellsArrayRows = [],
selectedCellsArrayCols = [],
selectedCellsArrayColsUnique = [],
selectedCellsArrayRowsUnique = [],
selectedCellsRows = '',
selectedCellsCols = '',
rowsColsProduct = '';
function rowObject() {
this.rowstart;
this.rowend;
this.rowspan;
this.colstart;
this.colend;
this.colspan;
};
for (var i = 0; i < selectedCells.length; i++) {
selectedCellsRows = selectedCells[i].getAttribute('row');
selectedCellsCols = selectedCells[i].getAttribute('col');
//push all selected cells' row value to array
selectedCellsArrayRows.push(selectedCellsRows);
//push all selected cells' column value to array
selectedCellsArrayCols.push(selectedCellsCols);
if (selectedCellsArrayRows[i - 1] != selectedCellsRows) {
selectedCellsArrayRowsUnique.push(selectedCellsArrayRows[i]);
}
if (selectedCellsArrayCols[i - 1] != selectedCellsCols) {
selectedCellsArrayColsUnique.push(selectedCellsArrayCols[i]);
}
}
var lastItemInArrayRow = selectedCellsArrayRowsUnique.length - 1;
var lastItemInArrayCol = selectedCellsArrayColsUnique.length - 1;
var newCellObject = new rowObject();
newCellObject.rowstart = parseInt(selectedCellsArrayRowsUnique[0]);
newCellObject.rowend = parseInt(selectedCellsArrayRowsUnique[lastItemInArrayRow]);
newCellObject.rowspan = (newCellObject.rowend - newCellObject.rowstart) + 1;
newCellObject.colstart = parseInt(selectedCellsArrayColsUnique[0]);
newCellObject.colend = parseInt(selectedCellsArrayColsUnique[lastItemInArrayCol]);
newCellObject.colspan = (newCellObject.colend - newCellObject.colstart) + 1;
zoneCreateValidator(newCellObject.rowspan, newCellObject.colspan, selectedCells, zonesQtyInput.value);
});
}
function zoneCreateValidator(el1, el2, el3, e4) {
var prod = el1 * el2;
var zoneCounter = document.getElementsByClassName('zone_counter')[0];
// console.log(zoneCounter);
//check if quantity of selected cells is less than 1
if (el3.length < 1) {
alert('No cells selected!');
//check if quantity of selected cells is exactly 1
} else if (el3.length == 1) {
alert('You have created a single cell zone!');
} else if (el3.length > 1 && el3.length != prod) {
alert('You have not created a complete zone!');
} else {
alert('Zone created. Thank you!');
//zoneCounter = zoneCounter.replace(/[0-9]{1,}/), zoneCounter - 1;
}
//https://stackoverflow.com/questions/9646943/check-if-each-item-in-an-array-is-identical-in-javascript
}
function buildArray(rows, cols) {
var cellEls = document.getElementsByClassName('grid_zone');
for (var i = 0; i < rows; i++) {
for (var j = 0; j < cols; j++) {
var gridObjectInstance = Object.create(gridObject);
gridObjectInstance.row = i + 1;
gridObjectInstance.col = j + 1;
gridCellsArray.push(gridObjectInstance);
}
}
for (var x = 0; x < cellEls.length; x++) {
for (var m = 0; m < gridCellsArray.length; m++) {
if (m == x) {
cellEls[x].setAttribute('row', gridCellsArray[m].row);
cellEls[x].setAttribute('col', gridCellsArray[m].col);
}
}
}
}
function firstCellSelect(item, callback) {
item.addEventListener('click', function() {
item.setAttribute('class', 'grid_zone selected');
if (typeof callback == "function")
callback(item);
});
}
function nextCellSelect(item) {
//get new inventory
var gridCells = document.getElementsByClassName('grid_zone');
var firstSelectedRow = item.getAttribute('row');
var firstSelectedCol = item.getAttribute('col');
var gridCellsNext = [];
for (var i = 0; i < gridCells.length; i++) {
var gridCellsClass = gridCells[i].getAttribute('class');
var gridCellsClassArray = gridCellsClass.split(" ");
var nextSelectedRow = gridCells[i].getAttribute('row');
var nextSelectedCol = gridCells[i].getAttribute('col');
//DEFINE NEXT SELECTABLE - 120619 - to be worked out so that not_selectable cells are NOT CLICKABLE.
if (gridCellsClass.match(/next_selectable/gi)) {
//console.log('CAN be clicked => ' + gridCells[i].innerHTML);
//click event available on these items ONLY.
continue;
} else {
if ((((nextSelectedRow == firstSelectedRow - 1 && nextSelectedCol == firstSelectedCol) ||
(nextSelectedRow == parseInt(firstSelectedRow) + 1 && nextSelectedCol == firstSelectedCol) ||
(nextSelectedRow == firstSelectedRow && nextSelectedCol == firstSelectedCol - 1) ||
(nextSelectedRow == firstSelectedRow && nextSelectedCol == parseInt(firstSelectedCol) + 1))) && !gridCellsClass.match(/selected/gi)) {
//console.log('CAN be clicked => ' + gridCells[i].innerHTML);
//click event available on these items ONLY.
} else {
//console.log('CANNOT be clicked => ' + gridCells[i].innerHTML);
//click event NOT available on these items.
this.removeEventListener("click", firstCellSelect, false);
}
}
}
//DEFINE NEXT SELECTABLE - 120619 - works visually, but does not suppress click function on non-adjacent cells.
for (var i = 0; i < gridCells.length; i++) {
var gridCellsClass = gridCells[i].getAttribute('class');
var gridCellsClassArray = gridCellsClass.split(" ");
var nextSelectedRow = gridCells[i].getAttribute('row');
var nextSelectedCol = gridCells[i].getAttribute('col');
if ((nextSelectedRow == firstSelectedRow - 1 && nextSelectedCol == firstSelectedCol) ||
(nextSelectedRow == parseInt(firstSelectedRow) + 1 && nextSelectedCol == firstSelectedCol) ||
(nextSelectedRow == firstSelectedRow && nextSelectedCol == firstSelectedCol - 1) ||
(nextSelectedRow == firstSelectedRow && nextSelectedCol == parseInt(firstSelectedCol) + 1)) {
if (gridCellsClass.indexOf('selected') > -1) {
continue;
} else {
gridCells[i].setAttribute('class', 'grid_zone next_selectable');
gridCellsNext.push(gridCells[i]);
gridCells[i].addEventListener('click', function() {
this.setAttribute('class', 'grid_zone selected');
});
}
}
}
notClickable(gridCellsNext);
}
function notClickable(array) {
var gridCells = document.getElementsByClassName('grid_zone');
for (var i = 0; i < gridCells.length; i++) {
var gridCellsClassName = gridCells[i].getAttribute('class');
if (gridCellsClassName.indexOf('grid_zone first_selected') > -1 || gridCellsClassName.indexOf('selected') > -1 || gridCellsClassName.indexOf('next_selectable') > -1) {
continue;
} else {
gridCells[i].setAttribute('class', 'grid_zone not_selectable');
}
}
}
</script>
</body>
</html>