-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.html
934 lines (866 loc) · 50.8 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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
<!doctype html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Easy Toggle State, a tiny JS library to create UI components in no time</title>
<meta name="description" content="A tiny JavaScript library to easily toggle the state of any HTML element, and create UI components in no time">
<link rel="preload" as="fetch" type="application/json" crossorigin href="assets/filesize.json">
<link rel="preload" as="fetch" type="application/json" crossorigin href="assets/js/demos.json">
<link rel="preload" as="script" type="text/javascript" href="https://rawgit.com/Twikito/easy-toggle-state/master/dist/easy-toggle-state.min.js">
<link rel="preload" as="script" type="text/javascript" href="assets/js/prism.js">
<link rel="preload" as="image" type="image/jpeg" href="https://rawgit.com/Twikito/easy-toggle-state/master/docs/assets/img/rp1.jpg">
<link rel="preload" as="image" type="image/jpeg" href="https://rawgit.com/Twikito/easy-toggle-state/master/docs/assets/img/rp1_s.jpg">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicons/favicon-16x16.png">
<link rel="manifest" href="assets/favicons/site.webmanifest">
<link rel="mask-icon" href="assets/favicons/safari-pinned-tab.svg" color="#009d64">
<link rel="shortcut icon" href="assets/favicons/favicon.ico">
<meta name="msapplication-TileColor" content="#009d64">
<meta name="msapplication-config" content="assets/favicons/browserconfig.xml">
<meta name="theme-color" content="#009d64">
<meta property="og:title" content="Easy Toggle State, a tiny JS library to easily toggle the state of any HTML element and create UI components in no time.">
<meta property="og:description" content="Dropdown, navigation button, tooltip, collapsible panel, lightbox, tabs, switches made in minutes without worried about JavaScript.">
<meta property="og:url" content="https://twikito.github.io/easy-toggle-state/">
<meta property="og:type" content="website">
<meta property="og:locale" content="en_en">
<meta property="og:image" content="https://rawgit.com/Twikito/easy-toggle-state/master/docs/assets/favicons/og-image.jpg">
<meta property="og:image:width" content="279">
<meta property="og:image:height" content="279">
<meta name="twitter:card" content="summary">
<link rel="author" href="//github.com/Twikito">
<link rel="author" type="text/plain" href="humans.txt">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:500%7COpen+Sans:400,600">
<link rel="stylesheet" href="assets/css/prism.css">
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="assets/css/checkbox.css">
<link rel="stylesheet" href="assets/css/switchbox.css">
<link rel="stylesheet" href="assets/css/radio.css">
<link rel="stylesheet" href="assets/css/tooltip.css">
<link rel="stylesheet" href="assets/css/collapsible-panel.css">
<link rel="stylesheet" href="assets/css/tabs.css">
<link rel="stylesheet" href="assets/css/dropdown.css">
<link rel="stylesheet" href="assets/css/dialog.css">
<link rel="stylesheet" href="assets/css/lightbox.css">
<link rel="stylesheet" href="assets/css/navigation-icon.css">
</head>
<body>
<template id="demo-template">
<h4>
<a href=""></a>
</h4>
<div class="demo-container">
<div class="demo" id="">
<!-- demo -->
</div>
<button type="button" class="link-like small show-code" data-toggle-class data-toggle-target="">
<span class="show-code-show">show</span>
<span class="show-code-hide">hide</span>
code
</button>
</div>
<div class="code-container" id="">
<pre><code class="language-html line-numbers"></code></pre>
<div class="text-right small code-toolbar">
<a class="dl-css" href="" title="">download CSS</a>
-
<a class="dl-scss" href="" title="">SCSS</a>
-
<button type="button" class="link-like codepen" title="" data-title="" data-demo="" data-css="">open in CodePen</button>
</div>
</div>
</template>
<header id="header">
<h1>
<span class="logo">
<button type="button" class="logo-switch" title="Toggle that logo!" data-toggle-class="🤘😝" data-toggle-target="html">
<span class="logo-switch-bullet"></span>
</button>
<span class="logo-text">
Easy<br> Toggle<br> State
</span>
</span>
</h1>
</header>
<main class="wrapper">
<div id="download">
<p class="color-theme text-lg baseline">
<strong>A tiny JavaScript library to easily toggle the state of any <abbr title="HyperText Markup Language">HTML</abbr> element, and create <abbr title="User Interface">UI</abbr> components in no time.</strong>
</p>
<p>
Dropdown, navigation button, tooltip, collapsible panel, lightbox, tabs, switch like above to change theme…<br>
<abbr title="User Interface">UI</abbr> components made in minutes without worried about JavaScript. Only set a few <abbr title="HyperText Markup Language">HTML</abbr> attributes, and code the rest with your <abbr title="Cascading StyleSheet">CSS</abbr> skills.
</p>
<div class="download-links">
<a class="button" href="//raw.githubusercontent.com/Twikito/easy-toggle-state/master/dist/easy-toggle-state.min.js" title="Download Easy Toggle State compressed, production version">
<strong class="big">Download compressed</strong><br>
<span data-file-size="min.js">…</span> KB <small>– <span data-file-size="min.js.gzip">…</span> KB gzipped</small>
</a>
<a class="button" href="//raw.githubusercontent.com/Twikito/easy-toggle-state/master/dist/easy-toggle-state.js" title="Download Easy Toggle State uncompressed, development version">
<strong class="big">Download uncompressed</strong><br>
<span data-file-size="js">…</span> KB <small>– <span data-file-size="js.gzip">…</span> KB gzipped</small>
</a>
<a class="button button--grey" href="//github.com/Twikito/easy-toggle-state" title="View Easy Toggle State on GitHub">
<svg width="1em" class="github" viewBox="0 0 496 512" aria-hidden="true">
<title>GitHub</title>
<path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/>
</svg>
<span>View on GitHub</span>
</a>
</div>
</div>
<a class="nav-link" role="button" href="#navigation" title="Open navigation" data-toggle-class data-toggle-target="#navigation">
<span class="icon">
<svg width="1em" viewBox="0 0 100 100" role="img">
<title>Navigation icon</title>
<rect class="top-bar" x="0" y="15" width="100" height="12"/>
<rect class="mid-bar" x="0" y="44" width="100" height="12"/>
<rect class="bot-bar" x="0" y="73" width="100" height="12"/>
</svg>
<span class="sr-only">Go to navigation</span>
</span>
</a>
<nav id="navigation">
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#download">Direct download</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#why">Why?</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#demo">Demo page</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#examples">Examples</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#checkbox">Checkbox</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-checkbox">Simple checkbox</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#checkbox-with-aria">Checkbox with ARIA</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#checkbox-with-internal-label">Checkbox with internal label</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#checkbox-with-external-label">Checkbox with external label</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#switchbox">Switchbox</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#switchbox-with-external-label">Switchbox with external label</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#radio">Radio buttons</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-radio">Simple radio buttons</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#radio-with-arrows">Radio buttons and arrow keys</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#radio-with-aria">Radio buttons with ARIA</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#tooltip">Tooltip</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-tooltip">Simple tooltip</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#dblclick-tooltip">Double-click tooltip</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#collapsible-panel">Collapsible panel / accordion</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-collapsible-panel">Simple collapsible panel</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#collapsible-panel-with-escape">Collapsible panel and escape key</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#collapsible-panel-with-aria">Collapsible panel with ARIA</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#accordion">Accordion</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#tabs">Tabs</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-tabs">Simple tabs</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#tabs-with-arrows">Tabs and arrow keys</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#tabs-with-aria">Tabs with ARIA</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#dropdown">Dropdown</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-dropdown">Simple dropdown</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#dropdown-with-aria">Dropdown with ARIA</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#dialog">Dialog</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-dialog">Simple dialog</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#dialog-with-aria">Dialog with ARIA</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#lightbox">Lightbox</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-lightbox">Simple lightbox</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#navigation-icon">Navigation icon</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#simple-navigation-icon">Simple navigation icon</a></li>
</ul>
</li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#quickstart">Quickstart</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#quickstart-locally">Locally</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#quickstart-cdn">From CDN</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#quickstart-npm">With NPM</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#browser-support">Browser support</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#how-to-use">How to use</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#recommendation">First recommen<wbr>dation</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#toggling">Toggling</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-class" title="Basis: defining a trigger">data-toggle-class</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-class-on-trigger" title="Toggling only on trigger">data-toggle-class-on-trigger</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-class-on-target" title="Toggling only on target">data-toggle-class-on-target</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#toggling-combinations">Toggling combinations</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#targeting">Targeting</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-target" title="Basis: defining a target">data-toggle-target</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-target-parent" title="Targeting from the parent">data-toggle-target-parent</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-target-self" title="Targeting within the trigger">data-toggle-target-self</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-target-previous" title="Targeting the previous sibling element">data-toggle-target-previous</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-target-next" title="Targeting the next sibling element">data-toggle-target-next</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#advanced">Advanced</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-is-active" title="Active by default">data-toggle-is-active</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-group" title="Grouping triggers">data-toggle-group</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-radio-group" title="Radio-grouping triggers">data-toggle-radio-group</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-event" title="Toggle on another event">data-toggle-event</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-outside" title="Toggle off when outside">data-toggle-outside</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-outside-event" title="Event for toggle off when outside">data-toggle-outside-event</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-escape" title="Keyboard support: Escape">data-toggle-escape</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-arrows" title="Keyboard support: Arrows">data-toggle-arrows</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-modal" title="Targeting a modal">data-toggle-modal</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#data-toggle-trigger-off" title="Closing button">data-toggle-trigger-off</a></li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#a11y">Accessibility</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#custom-prefix">Customization</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#api">API</a>
<ul>
<li><a data-toggle-trigger-off="#navigation" href="#api-bundle">API using the bundle</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#api-esmodules">API using ES modules</a></li>
<li><a data-toggle-trigger-off="#navigation" href="#hooks">Hooks</a></li>
</ul>
</li>
</ul>
</li>
<li><a data-toggle-trigger-off="#navigation" href="#contribution">Contribution</a></li>
</ul>
</nav>
<hr>
<section id="why">
<h2>
<a href="#why">Why?</a>
</h2>
<p>A front-end developer often has to <strong>code scripts for interface components</strong>. Components such as dropdowns, navigation buttons, tooltips, expandable panels, lightboxes, tabs, etc.</p>
<p>The thing is… Most of these components expose a <strong>recurrent behavior</strong>: a trigger element toggles the state of one or more target elements. So why not code this behavior once and for all?</p>
<p>So here is a solution: <strong>a simple script to toggle the state of a trigger element</strong> with a <abbr title="Cascading StyleSheet">CSS</abbr> class. You can then <strong>associate this element</strong> with one or more others: let’s call them targets. By adding the right <abbr title="HyperText Markup Language">HTML</abbr> attributes, it can <strong>adapt to any contexts</strong> and behave like a chosen component.</p>
<p><strong>Only focus on adjusting the rest with your <abbr title="Cascading StyleSheet">CSS</abbr> creativity</strong>.</p>
</section>
<hr>
<section id="demo">
<h2>
<a href="#demo">Demo page</a>
</h2>
<p>Here is a full demo page where you can find some examples of <em>Easy Toggle State</em> real use cases. In this page, each interactible element is managed with the library, without any JavaScript more.</p>
<a class="demo-page" href="demo.html">
<img src="assets/img/demo-page.jpg" alt="Easy Toggle State demo page">
</a>
</section>
<hr>
<section id="examples">
<h2>
<a href="#examples">Examples</a>
</h2>
<p>Here are some demos to show you how this is powerful.</p>
<p>Of course, <strong>these examples can be made in other ways</strong>, with <em>Easy Toggle State</em> or not. For example, checkboxes, switchboxes and radio buttons can be made in pure <abbr title="Cascading StyleSheet">CSS</abbr> using natives inputs and labels.</p>
<section id="checkbox">
<h3>
<a href="#checkbox">Checkbox</a>
</h3>
<p>
You want to display a checkbox, i.e. a box with a checkmark that appears on click on this box.
Even if you should use the <code class="language-html"><input type="checkbox"></code> native component, in some cases, you can’t.
</p>
<section data-template="simple-checkbox"><i>Loading demo…</i></section>
<section data-template="checkbox-with-aria"><i>Loading demo…</i></section>
<section data-template="checkbox-with-internal-label"><i>Loading demo…</i></section>
<section data-template="checkbox-with-external-label"><i>Loading demo…</i></section>
</section>
<section id="switchbox">
<h3>
<a href="#switchbox">Switchbox</a>
</h3>
<p>
You want to display a switchbox, i.e. a box with a "ball" that moves on click on this box.
Even if you should use the <code class="language-html"><input type="checkbox"></code> native component, in some cases, you can’t.
</p>
<section data-template="switchbox-with-external-label"><i>Loading demo…</i></section>
</section>
<section id="radio">
<h3>
<a href="#radio">Radio buttons</a>
</h3>
<p>
You want to display some radio buttons, i.e. some circles which are filled on click on them, only one at a time.
Even if you should use the <code class="language-html"><input type="radio"></code> native component, in some cases, you can’t.
</p>
<section data-template="simple-radio"><i>Loading demo…</i></section>
<section data-template="radio-with-arrows"><i>Loading demo…</i></section>
<section data-template="radio-with-aria"><i>Loading demo…</i></section>
</section>
<section id="tooltip">
<h3>
<a href="#tooltip">Tooltip</a>
</h3>
<p>You want to put a tooltip on a text, i.e. show an element when hovering this text, and hide it when the cursor leaves this text.</p>
<p>In most of cases, tooltips are not a good idea for displaying information, and are not accessible to all, screen readers for instance, so please consider not using it, or only for trivial contents.</p>
<section data-template="simple-tooltip"><i>Loading demo…</i></section>
<section data-template="dblclick-tooltip"><i>Loading demo…</i></section>
</section>
<section id="collapsible-panel">
<h3>
<a href="#collapsible-panel">Collapsible panel / accordion</a>
</h3>
<p>
You want to create a collapsible panel, i.e. a frame, with some content, that can be collapsed on click on a button.
Even if you should use <code class="language-html"><details></code> and <code class="language-html"><summary></code> HTML elements, in some cases, you can’t.
</p>
<section data-template="simple-collapsible-panel"><i>Loading demo…</i></section>
<section data-template="collapsible-panel-with-escape"><i>Loading demo…</i></section>
<section data-template="collapsible-panel-with-aria"><i>Loading demo…</i></section>
<section data-template="accordion"><i>Loading demo…</i></section>
</section>
<section id="tabs">
<h3>
<a href="#tabs">Tabs</a>
</h3>
<p>You want to create some tabs, i.e. some panels visualizable by clicking on their associated button.</p>
<section data-template="simple-tabs"><i>Loading demo…</i></section>
<section data-template="tabs-with-arrows"><i>Loading demo…</i></section>
<section data-template="tabs-with-aria"><i>Loading demo…</i></section>
</section>
<section id="dropdown">
<h3>
<a href="#dropdown">Dropdown</a>
</h3>
<p>You want to create a dropdown, i.e. a list of choices that appears when you click on a button. Of course you should use <code class="language-html"><select></code> and <code class="language-html"><option></code> HTML elements, but in some cases, you can’t.</p>
<p>Note that <em>Easy Toggle State </em>do not deal with data, so it will not change trigger’s value when clicking on a option. Here, an event listener on click has been added on each option to handle this for this demo.</p>
<section data-template="simple-dropdown"><i>Loading demo…</i></section>
<section data-template="dropdown-with-aria"><i>Loading demo…</i></section>
</section>
<section id="dialog">
<h3>
<a href="#dialog">Dialog</a>
</h3>
<p>You want to create a dialog, i.e. an information or form box displayed in front of all page content on click on a trigger.</p>
<p>Even if you should use <code class="language-html"><dialog></code> HTML element, in some cases, you can’t.</p>
<section data-template="simple-dialog"><i>Loading demo…</i></section>
<section data-template="dialog-with-aria"><i>Loading demo…</i></section>
</section>
<section id="lightbox">
<h3>
<a href="#lightbox">Lightbox</a>
</h3>
<p>You want to create a lightbox, i.e. a box displayed in front of all page content to see a larger version of an image.</p>
<section data-template="simple-lightbox"><i>Loading demo…</i></section>
</section>
<section id="navigation-icon">
<h3>
<a href="#navigation-icon">Navigation icon</a>
</h3>
<p>You want to create a navigation icon, i.e. an icon that represents a button you can click on to make a navigation menu visible.</p>
<p>For a full navigation demo, go check the <a href="demo.html">demo page</a>.</p>
<section data-template="simple-navigation-icon"><i>Loading demo…</i></section>
</section>
</section>
<hr>
<section id="quickstart" class="language-bash">
<h2>
<a href="#quickstart">Quickstart</a>
</h2>
<section id="quickstart-locally">
<h3>
<a href="#quickstart-locally">Locally</a>
</h3>
<ul>
<li><a href="#download">Direct download</a></li>
<li>Or choose another version: <a href="//github.com/Twikito/easy-toggle-state/tree/master/dist">ES5 or ES6</a></li>
</ul>
<p>Then, add the script into your page:</p>
<pre><code class="language-html"><script src="./your-path/easy-toggle-state.min.js"></script></code></pre>
<p>and it’s done.</p>
</section>
<section id="quickstart-cdn">
<h3>
<a href="#quickstart-cdn">From <abbr title="Content Delivery Network">CDN</abbr></a>
</h3>
<p><em>Easy Toggle State</em> is available on some <abbr title="Content Delivery Network">CDN</abbr>, so you can link it directly from there instead of using it locally.</p>
<p>Go check <a href="//cdnjs.com/libraries/easy-toggle-state">easy-toggle-state on cdnjs</a>, or use <a href="//unpkg.com">unpkg</a> <abbr title="Application Programming Interface">API</abbr>.</p>
</section>
<section id="quickstart-npm">
<h3>
<a href="#quickstart-npm">With <abbr title="Node Package Manager">NPM</abbr></a>
</h3>
<p>Install with <a href="//www.npmjs.com/package/easy-toggle-state"><abbr title="Node Package Manager">npm</abbr></a>:</p>
<pre><code>npm install easy-toggle-state</code></pre>
<p>Then use <em>Easy Toggle State</em> into your application, inside your <abbr title="JavaScript">JS</abbr> file:</p>
<pre><code class="language-js">import easyToggle from "easy-toggle-state";
easyToggle();</code></pre>
<p>For example, you could make sure your <abbr title="Document Object Model">DOM</abbr> is fully loaded before initializing <em>Easy Toggle State</em> in your page. To do so:</p>
<pre><code class="language-js">import easyToggle from "easy-toggle-state";
const handler = () => {
easyToggle();
document.removeEventListener("DOMContentLoaded", handler);
};
document.addEventListener("DOMContentLoaded", handler);</code></pre>
<p>Refer to the <a href="#api-esmodules">API using ES modules</a> section to learn more about what you can do.</p>
</section>
<section id="browser-support">
<h3>
<a href="#browser-support">Browser support</a>
</h3>
<p><em>Easy Toggle State</em> library is written in <abbr title="ECMAScript 2016+">ES2016+</abbr>, so it supports browsers back to Edge 14, Firefox 43, Chrome 47, Safari 9 and Opera 34.</p>
<p>For more compatibility, you can use the <a href="//github.com/Twikito/easy-toggle-state/blob/master/dist/"><abbr title="ECMAScript 5">ES5</abbr> version</a>, making the library supports browsers back to <abbr title="Internet Explorer">IE</abbr> 10, Edge all versions, Firefox 4, Chrome 13, Safari 6 and Opera 12.1.</p>
<p>If you need even more browser compatibility, consider using <a href="//polyfill.io/">polyfill.io</a> in addition of the <abbr title="ECMAScript 5">ES5</abbr> version. This will make the bundle supports back to <abbr title="Internet Explorer">IE</abbr> 8.</p>
<p><a href="//kangax.github.io/compat-table/es6/" title="ECMAScript compatibility table">Learn more about <abbr title="ECMAScript">ES</abbr> compatibility</a>.</p>
</section>
</section>
<hr>
<section id="how-to-use">
<h2>
<a href="#how-to-use">How to use</a>
</h2>
<section id="recommendation">
<h3>
<a href="#recommendation">First recommendation</a>
</h3>
<p>Although you could use any element, <strong>I strongly recommend using only buttons for trigger elements</strong>. It’s more accessible, and it’s meant to be used for this kind of thing. The <a href="#examples">examples</a> will show you that.</p>
<p class="language-html">If you still want to use links with fake <code>href</code> values, such as <code>href="#"</code>, don’t forget to add <code>role="button"</code> attribute.</p>
</section>
<section id="toggling" class="language-html">
<h3>
<a href="#toggling">Toggling</a>
</h3>
<section id="data-toggle-class">
<h4>
<a href="#data-toggle-class">Basis: defining a trigger</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-class</code></dt>
<dd>
<div class="mb-5">
<pre><code><button data-toggle-class>…</button></code></pre>
<p>Here is the basic usage: Adding this attribute on a button will make it toggle the <abbr title="Cascading StyleSheet">CSS</abbr> class <code>is-active</code> on it on click. It becomes a trigger.</p>
</div>
<div class="mb-5">
<pre><code><button data-toggle-class="is-selected">…</button></code></pre>
<p>You can specify a class name of your own that you want to toggle instead: Here, by clicking on this trigger, the class <code>is-selected</code> will be toggled on it on click.</p>
</div>
<div>
<pre><code><button data-toggle-class="class1 class2 class3">…</button></code></pre>
<p>You can go further into toggling by filling the attribute with as many classes as you need: Here, a click on the trigger will toggle each class on it.</p>
</div>
</dd>
</dl>
</section>
<section id="data-toggle-class-on-trigger">
<h4>
<a href="#data-toggle-class-on-trigger">Toggling only on trigger</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-on-trigger</code></dt>
<dd>
<pre><code><button data-toggle-class-on-trigger="class1 class2 class3">…</button></code></pre>
<p>Since you are able to <a href="#targeting">specify a target</a>, you may want to toggle some classes only on the trigger. Here, each of those three classes will be toggled only on this trigger.</p>
</dd>
</dl>
</section>
<section id="toggling-with-target">
<h4>
<a href="#toggling-with-target">Toggling with a target</a>
</h4>
<p>You may want to <a href="#targeting">add a target</a> to your trigger.</p>
<pre><code><button data-toggle-class="class" data-toggle-target="selector">…</button></code></pre>
<p>This way, the class specified in the attribute <code>data-toggle-class</code> will be toggle on this trigger and on its target, defined by the selector.</p>
</section>
<section id="data-toggle-class-on-target">
<h4>
<a href="#data-toggle-class-on-target">Toggling only on target</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-on-target</code></dt>
<dd>
<pre><code><button data-toggle-class-on-target="class1 class2 class3" data-toggle-target="selector">…</button></code></pre>
<p>You may want to toggle some classes only on the target. Here, each of those three classes will be toggled only on this target.</p>
<p>Note that this attribute must be used with one of the <a href="#targeting">targeting attributes</a>.</p>
</dd>
</dl>
</section>
<section id="toggling-combinations">
<h4>
<a href="#toggling-combinations">Toggling combinations</a>
</h4>
<p>You can combine all toggling attributes, making <em>Easy Toggle State</em> compatible with any <abbr title="Cascading StyleSheet">CSS</abbr> framwork.</p>
<pre><code class="language-html"><button
data-toggle-class="is-open"
data-toggle-class-on-trigger="text-white font-bold bg-blue"
data-toggle-class-on-target="text-gray bg-white"
data-toggle-target="#plop">
…
</button></code></pre>
<p>Here, with this combination, a click on this trigger will toggle:</p>
<ul>
<li>the classes <code>is-open</code>, <code>text-white</code>, <code>font-bold</code>, <code>bg-blue</code> on this trigger</li>
<li>the classes <code>is-open</code>, <code>text-gray</code>, <code>bg-white</code> on the target, the element <code>#plop</code></li>
</ul>
</section>
</section>
<section id="targeting" class="language-html">
<h3>
<a href="#targeting">Targeting</a>
</h3>
<section id="data-toggle-target">
<h4>
<a href="#data-toggle-target">Basis: defining a target</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-target</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target="selector">…</button></code></pre>
<p>This is the basics in targeting: the attribute <code>data-toggle-target</code> tells this trigger to look in the whole page for one or several elements to target matching the selector.</p>
<p>This way, a click on the trigger will toggle the class on the trigger itself and on its one or several targets.</p>
<p>The <code>selector</code> value must be a valid <abbr title="Cascading StyleSheet">CSS</abbr> selector string, containing one or more selectors to match. Learn more about <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors"><abbr title="Cascading StyleSheet">CSS</abbr> selectors</a>.</p>
</dd>
</dl>
</section>
<section id="data-toggle-target-parent">
<h4>
<a href="#data-toggle-target-parent">Targeting from the parent</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-target-parent</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target-parent="selector">…</button></code></pre>
<p>Instead of looking in the whole page, you can search for one or several targets matching the selector only inside the trigger’s parent container.</p>
</dd>
</dl>
</section>
<section id="data-toggle-target-self">
<h4>
<a href="#data-toggle-target-self">Targeting within the trigger</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-target-self</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target-self="selector">…</button></code></pre>
<p>Instead of looking in the whole page, you can search for one or several targets matching the selector only inside the trigger itself.</p>
<p>See an example with <a href="#checkbox-with-internal-label">this checkbox</a>.</p>
</dd>
</dl>
</section>
<section id="data-toggle-target-previous">
<h4>
<a href="#data-toggle-target-previous">Targeting the previous sibling element</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-target-previous</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target-previous>…</button></code></pre>
<p>You can target the previous direct sibling element by using <code>data-toggle-target-previous</code> attribute.</p>
</dd>
</dl>
</section>
<section id="data-toggle-target-next">
<h4>
<a href="#data-toggle-target-next">Targeting the next sibling element</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-target-next</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target-next>…</button></code></pre>
<p>You can target the next direct sibling element by using <code>data-toggle-target-next</code> attribute.</p>
</dd>
</dl>
</section>
</section>
<section id="advanced" class="language-html">
<h3>
<a href="#advanced">Advanced</a>
</h3>
<section id="data-toggle-is-active">
<h4>
<a href="#data-toggle-is-active">Active by default</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-is-active</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-is-active>…</button></code></pre>
<p>Specify a trigger element and its targets to be active by default. As a consequence, they will be toggled once on initialization.</p>
<p>See an example with <a href="#simple-tabs">tabs</a>.</p>
</dd>
</dl>
</section>
<section>
<h4>
<a href="#data-toggle-group">Grouping triggers</a>
</h4>
<dl>
<dt id="data-toggle-group">Attribute: <code>data-toggle-group</code></dt>
<dd class="mb-10">
<pre><code><button data-toggle-class="class" data-toggle-group="name">…</button>
<button data-toggle-class="class" data-toggle-group="name">…</button></code></pre>
<p>Specify that a trigger is a part of a group, defined by a <code>name</code>. Only one trigger of a group can be active at a time. Of course, it must be used on at least two triggers to create a group.</p>
<p>They will actually behave like an <a href="#accordion">accordion component</a>.</p>
</dd>
<dt id="data-toggle-radio-group">Attribute: <code>data-toggle-radio-group</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-radio-group="name">…</button>
<button data-toggle-class="class" data-toggle-radio-group="name">…</button></code></pre>
<p>Specify that they are a part of a radio group, defined by a <code>name</code>. Only one trigger of a radio group can be active at a time. Of course, it must be used on at least two triggers to create a group.</p>
<p>Unlike a simple group as seen above, as soon as a trigger of a radio group has been activated, <strong>this radio group will always keep one trigger active</strong>. It will actually behave like <a href="#simple-radio">radio buttons</a> or <a href="#simple-tabs">tabs component</a>.</p>
<p>Note that a trigger of a radio grouped can’t have <code>data-toggle-outside</code><sup class="gotodef"><a href="#data-toggle-outside" title="Go to definition">[?]</a></sup> or <code>data-toggle-escape</code><sup class="gotodef"><a href="#data-toggle-escape" title="Go to definition">[?]</a></sup> behavior.</p>
</dd>
</dl>
</section>
<section id="data-toggle-event">
<h4>
<a href="#data-toggle-event">Toggle on another event</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-event</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-event="event">…</button></code></pre>
<p>Specify another event to toggle the trigger instead of the <code>click</code> event used by default. For example, <code>mouseover</code>.</p>
<p>See an example with a <a href="#simple-tooltip">tooltip</a>.</p>
</dd>
</dl>
</section>
<section>
<h4>
<a href="#data-toggle-outside">Toggle off when outside</a>
</h4>
<dl>
<dt id="data-toggle-outside">Attribute: <code>data-toggle-outside</code></dt>
<dd class="mb-10">
<pre><code><button data-toggle-class="class" data-toggle-outside>…</button></code></pre>
<p>When a trigger is active, specify to toggle off this trigger when you click again outside of it. If you use the <code>data-toggle-event</code><sup class="gotodef"><a href="#data-toggle-event" title="Go to definition">[?]</a></sup> attribute too on the trigger, the event used is the same.</p>
<p>Note that this attribute does not work on an element with <code>data-toggle-radio-group</code><sup class="gotodef"><a href="#data-toggle-radio-group" title="Go to definition">[?]</a></sup>.</p>
<p>See an example with a <a href="#simple-dropdown">dropdown</a>.</p>
</dd>
<dt id="data-toggle-outside-event">Attribute: <code>data-toggle-outside-event</code></dt>
<dd>
<pre><code><button
data-toggle-class="class"
data-toggle-outside
data-toggle-outside-event="event">
…
</button></code></pre>
<p>When using <code>data-toggle-outside</code><sup class="gotodef"><a href="#data-toggle-outside" title="Go to definition">[?]</a></sup> attribute, add this attribute to use a different event to toggle off outside of the trigger.</p>
<p>Note that this attribute only works when used in addition of <code>data-toggle-outside</code><sup class="gotodef"><a href="#data-toggle-outside" title="Go to definition">[?]</a></sup> attribute.</p>
<p>See an example with a <a href="#dblclick-tooltip">tooltip</a>.</p>
</dd>
</dl>
</section>
<section>
<h4>
<a href="#data-toggle-escape">Keyboard support</a>
</h4>
<dl>
<dt id="data-toggle-escape">Attribute: <code>data-toggle-escape</code></dt>
<dd class="mb-10">
<pre><code><button data-toggle-class="class" data-toggle-escape>…</button></code></pre>
<p>Specify that you can press the <kbd>escape</kbd> key to toggle off the trigger when it is already active.</p>
<p>Note that this attribute does not work on an element with <code>data-toggle-radio-group</code><sup class="gotodef"><a href="#data-toggle-radio-group" title="Go to definition">[?]</a></sup>.</p>
<p>See an example with a <a href="#collapsible-panel-with-escape">collapsible panel</a>.</p>
</dd>
<dt id="data-toggle-arrows">Attribute: <code>data-toggle-arrows</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-arrows data-toggle-group="name">…</button>
<button data-toggle-class="class" data-toggle-arrows data-toggle-group="name">…</button></code></pre>
<p>Used with a group attribute, specify that as soon as a trigger is focused, you can navigate through the triggers of the same group with arrows <kbd title="arrow up">↑</kbd> <kbd title="arrow right">→</kbd> <kbd title="arrow down">↓</kbd> <kbd title="arrow left">←</kbd>, <kbd>home</kbd> and <kbd>end</kbd> keys.</p>
<p>Remember that this attribute must be used with <code>data-toggle-group</code><sup class="gotodef"><a href="#data-toggle-group" title="Go to definition">[?]</a></sup> or <code>data-toggle-radio-group</code><sup class="gotodef"><a href="#data-toggle-radio-group" title="Go to definition">[?]</a></sup>.</p>
<p>See an example with <a href="#radio-with-arrows">radio buttons</a>.</p>
</dd>
</dl>
</section>
<section id="data-toggle-modal">
<h4>
<a href="#data-toggle-modal">Targeting a modal</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-modal</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-modal>…</button></code></pre>
<p>Specify that the target is a modal, such as a <a href="#dialog">dialog</a> or a <a href="#lightbox">lightbox</a>. This way, when the target is active (open), the focus is trapped inside this target until you close it. This means tabbing will only focus on focusable elements inside this target, leaving anything else outside be out of scope.</p>
<p>Be very careful when using this feature. A focus trap can be very annoying (and an accessibility fault) when used in a wrong way, so be sure your target is a modal component.</p>
</dd>
</dl>
</section>
<section id="data-toggle-trigger-off">
<h4>
<a href="#data-toggle-trigger-off">Closing button</a>
</h4>
<dl>
<dt>Attribute: <code>data-toggle-trigger-off</code></dt>
<dd>
<pre><code><button data-toggle-class="class" data-toggle-target="#plop">…</button>
<div id="plop">
<button data-toggle-trigger-off="#plop">…</button>
</div></code></pre>
<p>This attribute is meant to be used on an element inside a target. By doing so, it enables this element to toggle the related trigger back off when it is active. For example, a close button inside a <a href="#dialog">dialog</a> or a <a href="#lightbox">lightbox</a>.</p>
<p>Fill this attribute with a <abbr title="Cascading StyleSheet">CSS</abbr> selector matching that target element.</p>
<p>Remember that this attribute must be used on an element <strong>placed inside a target element</strong>.</p>
</dd>
</dl>
</section>
</section>
<section id="a11y" class="language-html">
<h3>
<a href="#a11y">Accessibility</a>
</h3>
<p>If a trigger or a target element has one of the supported <abbr title="Accessible Rich Internet Applications">ARIA</abbr> attributes, its value will also change, so please consider using the right roles and <abbr title="Accessible Rich Internet Applications">ARIA</abbr> attributes to optimize your components for accessibility.</p>
<p>The <a href="#examples">examples</a> will help you for that. Learn more about <a href="//developer.mozilla.org/en-US/docs/Web/Accessibility/An_overview_of_accessible_web_applications_and_widgets" title="An overview of accessible web applications and widgets, on MDN"><abbr title="Accessible Rich Internet Applications">ARIA</abbr></a>.</p>
<p>The <abbr title="Accessible Rich Internet Applications">ARIA</abbr> attributes supported by <em>Easy Toggle State</em> are:</p>
<ul>
<li><code>aria-checked</code></li>
<li><code>aria-expanded</code></li>
<li><code>aria-hidden</code></li>
<li><code>aria-pressed</code></li>
<li><code>aria-selected</code></li>
</ul>
</section>
<section id="custom-prefix" class="language-html">
<h3>
<a href="#custom-prefix">Customization</a>
</h3>
<p>You can change the prefix <code>toggle</code> in <code>data-toggle-class</code> and other attributes to prevent conflict with another <abbr title="JavaScript">JS</abbr> library. To do so, add this attribute to your <code><html></code> element with your new prefix:</p>
<pre><code class="language-html"><html data-easy-toggle-state-custom-prefix="my-prefix"></code></pre>
<p>It will so be set to all attributes like <code>data-my-prefix-class</code>.</p>
</section>
<section id="api" class="language-html">
<h3>
<a href="#api"><abbr title="Application Programming Interface">API</abbr></a>
</h3>
<section id="api-bundle">
<h4>
<a href="#api-bundle"><abbr title="Application Programming Interface">API</abbr> using the bundle (locally or from <abbr title="Content Delivery Network">CDN</abbr>)</a>
</h4>
<section class="mb-5" id="api-bundle-initialization">
<h5>
<a href="#api-bundle-initialization">initialization</a>
</h5>
<p>Initialize all trigger elements not yet binded.</p>
<pre><code class="language-js">window.easyToggleState();</code></pre>
<p>No parameter. Returns an <i>Array</i> of newly initialized trigger elements.</p>
</section>
<section class="mb-5" id="api-bundle-unbind">
<h5>
<a href="#api-bundle-unbind">unbind</a>
</h5>
<p>Unbind a trigger element, or a trigger element list.</p>
<pre><code class="language-js">window.easyToggleState.unbind( Node || NodeList );</code></pre>
<p>Takes a <i>Node</i> or a <i>NodeList</i> as parameter. Returns the same <i>Node</i> or <i>NodeList</i>.</p>
</section>
<section class="mb-5" id="api-bundle-unbindall">
<h5>
<a href="#api-bundle-unbindall">unbindAll</a>
</h5>
<p>Unbind all trigger elements.</p>
<pre><code class="language-js">window.easyToggleState.unbindAll();</code></pre>
<p>No parameter. Returns a <i>NodeList</i> of all newly unbinded trigger elements.</p>
</section>
<section class="mb-5" id="api-bundle-isactive">
<h5>
<a href="#api-bundle-isactive">isActive</a>
</h5>
<p>Get the state of a trigger element.</p>
<pre><code class="language-js">window.easyToggleState.isActive( Node );</code></pre>
<p>Takes a <i>Node</i> as parameter. Returns a <i>boolean</i>.</p>
</section>
</section>
<section id="api-esmodules">
<h4>
<a href="#api-esmodules"><abbr title="Application Programming Interface">API</abbr> using <abbr title="ECMAScript">ES</abbr> modules</a>
</h4>
<section class="mb-5" id="api-esmodules-initialization">
<h5>
<a href="#api-esmodules-initialization">initialization</a>
</h5>
<p>Initialize all trigger elements not yet binded.</p>
<pre><code class="language-js">import initialize from "easy-toggle-state";
initialize();</code></pre>
<p>No parameter. Returns an <i>Array</i> of newly initialized trigger elements.</p>
</section>
<section class="mb-5" id="api-esmodules-unbind">
<h5>
<a href="#api-esmodules-unbind">unbind</a>
</h5>
<p>Unbind a trigger element, or a trigger element list.</p>
<pre><code class="language-js">import { unbind } from "easy-toggle-state";
unbind( Node || NodeList );</code></pre>
<p>Takes a <i>Node</i> or a <i>NodeList</i> as parameter. Returns the same <i>Node</i> or <i>NodeList</i>.</p>
</section>
<section class="mb-5" id="api-esmodules-unbindall">
<h5>
<a href="#api-esmodules-unbindall">unbindAll</a>
</h5>
<p>Unbind all trigger elements.</p>
<pre><code class="language-js">import { unbindAll } from "easy-toggle-state";
unbindAll();</code></pre>
<p>No parameter. Returns a <i>NodeList</i> of all newly unbinded trigger elements.</p>
</section>
<section class="mb-5" id="api-esmodules-isactive">
<h5>
<a href="#api-esmodules-isactive">isActive</a>
</h5>
<p>Get the state of a trigger element.</p>
<pre><code class="language-js">import { isActive } from "easy-toggle-state";
isActive( Node );</code></pre>
<p>Takes a <i>Node</i> as parameter. Returns a <i>boolean</i>.</p>
</section>
</section>
<section id="hooks">
<h4>
<a href="#hooks">Hooks</a>
</h4>
<p>You can also add some hooks: each trigger and target element fires a <code>toggleBefore</code> event before and a <code>toggleAfter</code> event after toggling its state, so you can add event listeners on these events, and test the active state.</p>
<p>For example:</p>
<pre><code class="language-js">document.querySelector("#myTrigger").addEventListener("toggleAfter", event => {
console.log(`Active: ${window.easyToggleState.isActive(event.target)}`);
}, false);</code></pre>
</section>
</section>
</section>
<hr>
<section id="contribution">
<h2>
<a href="#contribution">Contribution</a>
</h2>
<ul>
<li>Clone the repo: <code class="language-bash">git clone https://github.com/twikito/easy-toggle-state.git</code></li>
<li>Development: <code class="language-bash">npm run build</code></li>
<li><a href="//github.com/Twikito/easy-toggle-state/fork">Fork repository on GitHub</a></li>
<li><a href="//github.com/Twikito/easy-toggle-state/issues">Report a bug</a></li>
<li><a href="//github.com/Twikito/easy-toggle-state/issues">Suggest a feature</a></li>
</ul>
</section>
</main>
<footer>
<div class="wrapper">
<p>
Proudly made
under <a href="//github.com/Twikito/easy-toggle-state/blob/master/LICENSE">MIT license</a>
on <a href="//github.com/Twikito/easy-toggle-state" title="View Easy Toggle State on GitHub">GitHub</a>
by <a href="//twikito.com">Matthieu Bué</a>.
</p>
</div>
</footer>
<script src="https://rawgit.com/Twikito/easy-toggle-state/master/dist/easy-toggle-state.min.js"></script>
<script src="assets/js/prism.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>