-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
713 lines (649 loc) · 18 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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Checkbox</title>
<link rel="icon" type="image/png" href="check-box-with-check.png" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/themes/prism.min.css"
integrity="sha512-tN7Ec6zAFaVSG3TpNAKtk4DOHNpSwKHxxrsiw4GHKESGPs5njn/0sMCUMl2svV4wo4BK/rCP7juYz+zx+l6oeQ=="
crossorigin="anonymous"
/>
<style>
.Form__checkbox button {
width: 1.5em;
height: 1.5em;
position: relative;
border: 1px solid black;
}
.Form__checkbox button::after {
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: 3px;
content: '';
transform: scale(0);
transition: 0.05s transform ease;
}
.Form__checkbox.is-selected button:after {
background-color: black;
transform: scale(1);
}
.Form__checkbox.is-off,
.Form__checkbox[disabled],
.Form__checkbox[aria-disabled] {
opacity: 0.3;
pointer-events: none;
}
.Alert {
margin: 1em;
position: fixed;
top: 0;
right: 0;
z-index: 10;
}
</style>
</head>
<body>
<div class="Alert js-alert"></div>
<div class="container">
<div class="row my-5">
<div class="col-12">
<h1 class="m-0">
<a href="https://github.com/19h47/19h47-checkbox">Checkbox</a>
</h1>
</div>
</div>
<div class="row my-5">
<div class="col-12">
<p>
The plugin doesn't provided any style out of the box. You can do whatever
you want.
</p>
<p>
We used
<a href="https://getbootstrap.com/" target="_blank" rel="noreferer noopener"
>Boostrap</a
>
here for instance.
</p>
<pre
class="p-3 mt-0 mb-3"
><code class="language-html"><div role="checkbox" aria-checked="false">
<button type="button" tabindex="-1">Do you want to click me?</button>
<div style="display: none;">
<input id="option" name="option" value="false" type="checkbox" />
</div>
</div></code></pre>
<pre
class="p-3 mb-0 mt-3"
><code class="language-javascript">import Checkbox from '@19h47/checkbox';
const $checkbox = document.querySelector('[role="checkbox"]');
const checkbox = new Checkbox($checkbox);
checkbox.init();</code></pre>
</div>
</div>
<div class="row my-5">
<div class="col-12">
<div class="border px-3 py-4">
<h3 class="mb-3" id="sandwich-condiments">Sandwich Condiments</h3>
<div
class="js-sandwich-condiments"
role="group"
aria-labelledby="sandwich-condiments"
>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>Lettuce
<div class="d-none">
<input
id="lettuce"
name="condiments[]"
value="Lettuce"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>Tomato
<div class="d-none">
<input
id="tomato"
name="condiments[]"
value="Tomato"
type="checkbox"
/>
</div>
</div>
<fieldset class="border">
<div
class="Form__checkbox m-3 align-items-center d-flex js-tomato is-off"
tabindex="-1"
disabled
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>Roma
<div class="d-none">
<input id="roma" name="roma" value="Roma" type="checkbox" />
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex js-tomato is-off"
tabindex="-1"
disabled
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button
>Monterosa
<div class="d-none">
<input
id="monterosa"
name="monterosa"
value="Monterosa"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex js-tomato is-off"
tabindex="-1"
disabled
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button
>Beefsteak
<div class="d-none">
<input
id="beefsteak"
name="beefsteak"
value="Beefsteak"
type="checkbox"
/>
</div>
</div>
</fieldset>
<div
class="Form__checkbox m-3 align-items-center d-flex is-selected"
tabindex="0"
role="checkbox"
aria-checked="true"
>
<button
class="mr-3 is-selected"
type="button"
tabindex="-1"
></button
>Mustard
<div class="d-none">
<input
id="mustard"
name="condiments[]"
value="Mustard"
type="checkbox"
checked
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
<div>Sprouts</div>
<div class="d-none">
<input
id="sprouts"
name="condiments[]"
value="Sprouts"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox mx-3 mt-3 align-items-center d-flex disabled"
role="checkbox"
aria-checked="false"
aria-disabled="true"
tabindex="-1"
disabled
>
<button class="mr-3" type="button" tabindex="-1"></button>
<div>Disabled</div>
<div class="d-none">
<input
id="disabled"
name="condiments[]"
value="Disabled"
type="checkbox"
/>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row my-5">
<div class="col-12">
<pre
class="p-3 m-0"
><code class="language-javascript">import { CheckboxGroup } from '@19h47/checkbox';
const $element = document.querySelector('[role="group"]');
const checkboxgroup = new CheckboxGroup($element);
checkbox.init();</code></pre>
</div>
</div>
<div class="row my-5">
<div class="col-12">
<div class="border px-3 py-4">
<h3 class="mb-3" id="city-of-splendors">City of Splendors</h3>
<div class="border my-3">
<div
class="Form__checkbox m-3 align-items-center d-flex js-select-all"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Select All
<div class="d-none">
<input
id="select-all"
name="select-all"
value="select-all"
type="checkbox"
/>
</div>
</div>
</div>
<div
class="js-city-of-splendors mt-3"
role="group"
aria-labelledby="city-of-splendors"
>
<div
class="Form__checkbox mx-3 mb-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Curst
<div class="d-none">
<input id="curst" name="curst" value="Curst" type="checkbox" />
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Doppelganger, Greater
<div class="d-none">
<input
id="doppelganger-greater"
name="city-of-splendors[]"
value="Doppelganger, greater"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Duhlarkin
<div class="d-none">
<input
id="duhlarkin"
name="city-of-splendors[]"
value="Duhlarkin"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Ghaunadan
<div class="d-none">
<input
id="ghaunadan"
name="city-of-splendors[]"
value="Ghaunadan"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Gulguthydra
<div class="d-none">
<input
id="gulguthydra"
name="city-of-splendors[]ra"
value="Gulguthydra"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Hakeashar
<div class="d-none">
<input
id="hakeashar"
name="city-of-splendors[]"
value="Hakeashar"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Leucrotta, Greater
<div class="d-none">
<input
id="leucrotta-greater"
name="city-of-splendors[]"
value="Leucrotta, greater"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>Nyth
<div class="d-none">
<input
id="nyth"
name="city-of-splendors[]"
value="Nyth"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Palimpsest
<div class="d-none">
<input
id="palimpsest"
name="city-of-splendors[]"
value="Palimpsest"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Peltast
<div class="d-none">
<input
id="peltast"
name="city-of-splendors[]"
value="Peltast"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Raggamoffyn
<div class="d-none">
<input
id="raggamoffyn"
name="city-of-splendors[]"
value="Raggamoffyn"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Sewerm
<div class="d-none">
<input
id="sewerm"
name="city-of-splendors[]"
value="Sewerm"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
aria-disabled="true"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Shadowrath
<div class="d-none">
<input
id="shadowrath"
name="city-of-splendors[]"
value="Shadowrath"
type="checkbox"
disabled
/>
</div>
</div>
<div
class="Form__checkbox m-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Watchspider
<div class="d-none">
<input
id="watchspider"
name="city-of-splendors[]"
value="Watchspider"
type="checkbox"
/>
</div>
</div>
<div
class="Form__checkbox mx-3 mt-3 align-items-center d-flex"
tabindex="0"
role="checkbox"
aria-checked="false"
aria-disabled="true"
>
<button class="mr-3" type="button" tabindex="-1"></button>
Wereshark
<div class="d-none">
<input
id="wereshark"
name="city-of-splendors[]"
value="Wereshark"
type="checkbox"
disabled
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/plugins/autoloader/prism-autoloader.min.js"></script>
<script src="main.js"></script>
<script>
const alert = content => {
const div = document.createElement('div');
div.className = 'toast fade show';
div.style = 'toast fade show';
div.innerHTML = `<div class="toast-body">${content}</div>`;
div.setAttribute('role', 'alert');
div.setAttribute('aria-live', 'assertive');
div.setAttribute('aria-atomic', 'true');
return div;
};
const $alert = document.querySelector('.js-alert');
const onChange = content => {
const $el = alert(content);
$alert.appendChild($el);
$el.addEventListener(
'click',
() => $el.style.setProperty('display', 'none'),
false,
);
setTimeout(() => $el.parentNode.removeChild($el), 2000);
};
//
const $cityOfSplendors = document.querySelector('.js-city-of-splendors');
const $selectAll = document.querySelector('.js-select-all');
const checkboxgroup = new Checkbox.CheckboxGroup($cityOfSplendors);
const selectAll = new Checkbox.default($selectAll);
checkboxgroup.init();
selectAll.init();
const sandwichCondiments = document
.querySelector('.js-sandwich-condiments')
.querySelectorAll('[role="checkbox"]');
const tomatoes = [];
for (let i = 0; i < sandwichCondiments.length; i++) {
const $element = sandwichCondiments[i];
const checkbox = new Checkbox.default($element);
checkbox.init();
if ($element.classList.contains('js-tomato')) {
tomatoes.push(checkbox);
}
checkbox.$input.addEventListener('activate', event => {
const {
target: { value },
} = event;
onChange(`<strong>${value}</strong> has been activated!`);
if ('Tomato' === value) {
tomatoes.forEach(tomato => {
tomato.el.classList.remove('is-off');
tomato.el.setAttribute('tabIndex', '0');
tomato.el.removeAttribute('disabled');
tomato.activate();
});
}
});
checkbox.$input.addEventListener('deactivate', event => {
const {
target: { value },
} = event;
onChange(`<strong>${value}</strong> has been deactivated!`);
if ('Tomato' === value) {
tomatoes.forEach(tomato => {
tomato.el.classList.add('is-off');
tomato.el.setAttribute('tabIndex', '-1');
tomato.deactivate();
});
}
});
}
checkboxgroup.checkboxes.forEach(checkbox => {
checkbox.$input.addEventListener('activate', event => {
const {
target: { value },
} = event;
onChange(`<strong>${value}</strong> has been activated!`);
if (checkboxgroup.checkboxes.every(checkbox => checkbox.$input.checked)) {
selectAll.activate(false);
}
});
checkbox.$input.addEventListener('deactivate', event => {
const {
target: { value },
} = event;
onChange(`<strong>${value}</strong> has been deactivated!`);
console.log(
checkboxgroup.checkboxes.every(checkbox => checkbox.$input.checked),
);
if (!checkboxgroup.checkboxes.every(checkbox => checkbox.$input.checked)) {
selectAll.deactivate(false);
}
});
});
selectAll.$input.addEventListener('activate', event => {
checkboxgroup.checkboxes.forEach(checkbox => checkbox.activate());
});
selectAll.$input.addEventListener('deactivate', event => {
checkboxgroup.checkboxes.forEach(checkbox => checkbox.deactivate());
});
</script>
</body>
</html>