forked from thednp/bootstrap.native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
3510 lines (3136 loc) · 202 KB
/
index.html
File metadata and controls
3510 lines (3136 loc) · 202 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
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
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="The faster, lighter and more secure version of the Bootstrap JavaScript components.">
<meta name="keywords" content="JavaScript,Native JavaScript,native,Bootstrap,plugins,jQuery">
<meta name="author" content="thednp">
<link rel="shortcut icon" href="./assets/img/favicon.ico">
<link rel="apple-touch-icon" href="./assets/img/apple-touch-icon.png">
<title>Native JavaScript for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="./assets/css/offcanvas.css">
<!-- Prism: Code Highlight -->
<link rel="stylesheet" href="./assets/css/prism.css">
<!-- Custom styles for this template -->
<link rel="stylesheet" href="./assets/css/theme.css">
<!-- <script src="./dist/polyfill.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/js/ie10-viewport-bug-workaround.js"></script>
<script src="./dist/bootstrap-native.js"></script> -->
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-bootstrap">
<a data-toggle="tooltip" data-placement="bottom" class="navbar-brand mr-0 mr-md-2" title="<b>Native JavaScript for Bootstrap</b><br>The sweetest Vanilla JavaScript library for everyone" href="https://github.com/thednp/bootstrap.native/">
<svg class="d-inline-block align-top" width="36" height="36" viewBox="0 0 612 612" xmlns="http://www.w3.org/2000/svg" focusable="false"><title>Bootstrap</title>
<path fill="currentColor" d="M510 8a94.3 94.3 0 0 1 94 94v408a94.3 94.3 0 0 1-94 94H102a94.3 94.3 0 0 1-94-94V102a94.3 94.3 0 0 1 94-94h408m0-8H102C45.9 0 0 45.9 0 102v408c0 56.1 45.9 102 102 102h408c56.1 0 102-45.9 102-102V102C612 45.9 566.1 0 510 0z"></path><path fill="currentColor" d="M196.77 471.5V154.43h124.15c54.27 0 91 31.64 91 79.1 0 33-24.17 63.72-54.71 69.21v1.76c43.07 5.49 70.75 35.82 70.75 78 0 55.81-40 89-107.45 89zm39.55-180.4h63.28c46.8 0 72.29-18.68 72.29-53 0-31.42-21.53-48.78-60-48.78h-75.57zm78.22 145.46c47.68 0 72.73-19.34 72.73-56s-25.93-55.37-76.46-55.37h-74.49v111.4z"></path>
</svg>
<span class="d-inline-block align-middle hidden-xs">Native JavaScript for Bootstrap</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="offcanvas" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas-collapse navbar-collapse">
<ul class="navbar-nav ml-auto mr-0 d-none d-md-flex">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-expanded="false">Github</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="https://github.com/thednp/bootstrap.native/">Fork</a>
<a class="dropdown-item" href="https://github.com/thednp/bootstrap.native/wiki">Wiki</a>
<a class="dropdown-item" href="https://github.com/thednp/bootstrap.native/archive/master.zip">Download</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-expanded="false">Share</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" target="_blank" rel="noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=http://thednp.github.io/bootstrap.native/index.html" title="Share Native JavaScript for Bootstrap on Facebook">Facebook</a>
<a class="dropdown-item" target="_blank" rel="noreferrer"
href="https://twitter.com/home?status=Spread the word about %23BootstrapNative by @dnp_theme and download here http://thednp.github.io/bootstrap.native/index.html"
title="Share Native JavaScript for Bootstrap on Twitter">Twitter</a>
</div>
</li>
</ul>
<ul id="top-nav" class="navbar-nav d-flex d-md-none flex-column">
<li class="nav-item"><a class="nav-link" href="#componentAlert">Alert</a></li>
<li class="nav-item"><a class="nav-link" href="#componentButton">Button</a></li>
<li class="nav-item"><a class="nav-link" href="#componentCarousel">Carousel</a></li>
<li class="nav-item"><a class="nav-link" href="#componentCollapse">Collapse</a></li>
<li class="nav-item"><a class="nav-link" href="#componentDropdown">Dropdown</a></li>
<li class="nav-item"><a class="nav-link" href="#componentModal">Modal</a></li>
<li class="nav-item"><a class="nav-link" href="#componentPopover">Popover</a></li>
<li class="nav-item"><a class="nav-link" href="#componentScrollspy">ScrollSpy</a></li>
<li class="nav-item"><a class="nav-link" href="#componentTab">Tab</a></li>
<li class="nav-item"><a class="nav-link" href="#componentToast">Toast</a></li>
<li class="nav-item"><a class="nav-link" href="#componentTooltip">Tooltip</a></li>
</ul>
</div>
</nav>
<div id="myCarousel" class="carousel slide mb-5" data-ride="carousel" data-interval="7000" data-pause="hover">
<ol class="carousel-indicators">
<li data-toggle="tooltip" data-title="Download Native JavaScript for Bootstrap" data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-toggle="tooltip" data-title="Getting started with Native JavaScript" data-target="#myCarousel" data-slide-to="1"></li>
<li data-toggle="tooltip" data-title="Why BSN?" data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<div class="item-bg bg-indigo"></div>
<div class="container d-flex align-items-end h-100">
<div class="position-relative text-white text-left mb-5">
<h1>A better way to Bootstrap</h1>
<p>The faster, lighter and more secure set of JavaScript components for Bootstrap, developed on modern ES6/ES7 standards.<br> The <b>bootstrap.native</b>
library comes packed with build tools and well documented.</p>
<p><a class="btn btn-lg btn-primary" href="https://github.com/thednp/bootstrap.native/archive/master.zip">Download Now</a></p>
</div>
</div>
</div>
<div class="carousel-item">
<div class="item-bg bg-pink"></div>
<div class="container d-flex align-items-end h-100">
<div class="position-relative text-white text-center w-100 mb-5">
<h1>New to native JavaScript?</h1>
<p>Not to worry, <a style="color:#eee; text-decoration: underline" href="http://vanilla-js.com/" target="_blank">native JavaScript</a> is the coolest programing language
ever!<br> Far more powerful and requires almost <b>zero</b> maintenance on very long periods of time.</p>
<p><a class="btn btn-lg btn-primary" rel="noreferrer" href="http://blog.garstasio.com/you-dont-need-jquery/" target="_blank" role="button">Get started</a></p>
</div>
</div>
</div>
<div class="carousel-item">
<div class="item-bg bg-primary"></div>
<div class="container d-flex align-items-end h-100">
<div class="position-relative text-white text-right w-100 mb-5">
<h1>What's the fuzz?</h1>
<p>If you use mainly Bootstrap plugins in your projects, you may drop jQuery right away.<br>Why load jQuery if you don't really need it? It's too old school!</p>
<p><a class="btn btn-lg btn-light" rel="noreferrer" href="http://jsperf.com/jquery-vs-native-element-performance" target="_blank" role="button">See Now</a></p>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<svg class="carousel-control-prev-icon" viewBox="0 0 1024 1024" aria-hidden="true">
<path d="M658 686l-60 60-256-256 256-256 60 60-196 196z"></path>
</svg>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<svg class="carousel-control-next-icon" viewBox="0 0 1024 1024" aria-hidden="true">
<path d="M366 698l196-196-196-196 60-60 256 256-256 256z"></path>
</svg>
<span class="sr-only">Next</span>
</a>
</div>
<div class="container" id="container">
<section id="use">
<h2>Read First</h2>
<p>Welcome to the demo page! Before you do anything, please make sure to check the <a href="https://github.com/thednp/bootstrap.native/wiki">Wiki pages</a>,
as they give you quick start with using the library and also provide a good set of valuable guides on how to get the best out of it.</p>
<div class="list-group mb-3">
<a class="list-group-item list-group-item-action" href="https://github.com/thednp/bootstrap.native/wiki/Acknowledgements">
<h4>Acknowledgements</h4>
<p class="mb-0">A quick note on some of the similarities and differences with the original jQuery plugins. Nothing to worry about, but still good to know all the tricks on how to maximize your workflow.</p>
</a>
<a class="list-group-item list-group-item-action" href="https://github.com/thednp/bootstrap.native/wiki/How-to-use">
<h4>How to use</h4>
<p class="mb-0">An indepth guide on how to use it with stuff like <code>npm</code>, <code>RequireJS</code> or <b>CDN</b> links.</p>
</a>
<a class="list-group-item list-group-item-action" href="https://github.com/thednp/bootstrap.native/wiki/FAQs">
<h4>FAQs</h4>
<p class="mb-0">A short list of frequent asked questions regarding the use of the library.</p>
</a>
<a class="list-group-item list-group-item-action" href="https://github.com/thednp/bootstrap.native/wiki/Browser-support">
<h4>Browser Support</h4>
<p class="mb-0">A word on how to enable the library for legacy browsers.</p>
</a>
<a class="list-group-item list-group-item-action" href="https://github.com/thednp/bootstrap.native/wiki/About">
<h4>About</h4>
<p class="mb-0">Learn about the <code>bootstrap.native</code> project inception, goals and motivations.</p>
</a>
</div>
</section>
<div class="row">
<div class="col-md-9" data-spy="scroll" data-target="#side-nav" data-offset="84">
<section id="componentAlert">
<h2>Alert</h2>
<p>The <b>Alert</b> component covers the specific original events and public methods, but does not provide any option.
The component covers most essential JavaScript and DATA API, and does not require the class <code>alert-dismissible</code>
for the initialization to work.</p>
<section id="alertMethods">
<h3>Alert Methods</h3>
<p>The <b>Alert</b> component exposes two public methods to be used via JavaScript:</p>
<dl class="row">
<dt class="col-md-2">.close()</dt>
<dd class="col-md-10">The method hides an initialized alert and remove it from DOM.</dd>
<dt class="col-md-2">.dispose()</dt>
<dd class="col-md-10">Removes the component from target element. If the alert has been closed, calling this method
should produce no effect, since the alert was already removed from the DOM.</dd>
</dl>
</section>
<section id="alertEvents">
<h3>Alert Events</h3>
<p>The component's original events are same as with the original jQuery Plugin. The <code>event.target</code> of the
events is the <code><div class="alert"></code> element, and not the initialization target with the
<code>data-dismiss="alert"</code> attribute.</p>
<div class="table-responsive">
<table class="table table-bordered table-striped bs-events-table">
<thead>
<tr>
<th>Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>close.bs.alert</code></td>
<td>This event is fired immediately when the <code>close</code> instance method has been called.<br>
<b>This event can be default prevented.</b></td>
</tr>
<tr>
<td><code>closed.bs.alert</code></td>
<td>This event is fired when the alert has finished being hidden from the user.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="alertDATA">
<h3>Alert DATA API</h3>
<p>The component will initialize all elements with proper DATA API found in the DOM. Note that the
<code>data-dismiss="alert"</code> attribute is required for the triggering button.</p>
<pre><code class="language-markup"><!-- notice the <button> with the data-dismiss="alert" attribute -->
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<button id="myButtonAlert" type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
Some critical notice.
</div>
</code></pre>
</section>
<section id="alertJS">
<h3>Alert JavaScript API</h3>
<p>After inserting a new alert into the page, you can initialize it via JavaScript. Considering the above markup,
you can do the following:</p>
<pre><code class="language-javascript">// initialize
var myWarningAlertInit = new BSN.Alert('#myButtonAlert');
</code></pre>
<p>Also attach handlers to the original events:</p>
<pre><code class="language-javascript">// close.bs.alert
myButtonAlert.closest('.alert').addEventListener('close.bs.alert', function(event){
// do something cool
// event.target is <div class="alert">
}, false);
// closed.bs.alert
myButtonAlert.closest('.alert').addEventListener('closed.bs.alert', function(event){
// do something cool
// event.target is <div class="alert">
}, false);
</code></pre>
<p>Like all components of the library you can access the initialization object even if it was done via the DATA API:
</p>
<pre><code class="language-javascript">// find an element initialized via DATA API
var myAlertButton = document.getElementById('myAlertButton');
// reference the initialization object
var myAlertInit = myAlertButton.Alert;
// apply the public methods
myAlertInit.close();
// or
myAlertInit.dispose();
</code></pre>
</section>
<section id="alertExamples">
<h3>Alert Examples</h3>
<p>This alert has some handlers attached to <code>close.bs.alert</code> and <code>closed.bs.alert</code> events, so
check your console.</p>
<div id="alertDemo" class="alert alert-warning alert-dismissible fade show" role="alert">
<button type="button" class="close" id="alertDemo1" data-dismiss="alert" aria-label="Close"><span
aria-hidden="true">×</span></button>
<b>Holy guacamole!</b> Best check yo self, you're not looking too good.
</div>
<p>This alert uses the <code>closed.bs.alert</code> event to show another alert.</p>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4>Oh snap! You got an error!</h4>
<p>If you close this alert, your PC will start formatting your drive.</p>
<button type="button" class="btn btn-danger">Take this action</button>
</div>
</section>
</section>
<section id="componentButton">
<h2>Button</h2>
<p>The <b>Button</b> component provides toggle functionality for checkboxes and radio buttons and a custom event
for the button groups' toggling, not covered by the original jQuery plugin.</p>
<p><b>Button</b> doesn't cover the <a rel="noreferrer" href="http://getbootstrap.com/javascript/#buttons-single-toggle"
target="_blank">single toggle</a> functionality The supported toggle feature could very much fill the same purpose.
The component covers accessibility features instead:</p>
<ul>
<li>Users to toggle checkbox inputs via keyboard <kbd>Space</kbd> key, a must have feature for real world form application.
<a href="#buttonExamples">Examples</a> will showcase this feature.</li>
<li>Keyboard navigation for checkbox inputs can be done via the <kbd>Tab</kbd> / <kbd>Shift</kbd>+<kbd>Tab</kbd> keys,
while for radio inputs is done via <kbd><</kbd> and <kbd>></kbd> arrow keys.</li>
</ul>
<section id="buttonMethods">
<h3>Button Methods</h3>
<dl class="row">
<dt class="col-md-2">.dispose()</dt>
<dd class="col-md-10">Removes the component from target element.</dd>
</dl>
</section>
<section id="buttonEvents">
<h3>Button Events</h3>
<p>Unlike the original jQuery Plugin, the <b>Button</b> component comes with an original event, consistent in all
supported browsers. The <code>event.target</code> can be the element with the <code>data-toggle="buttons"</code>
attribute and the button that just changed it's active state.</p>
<div class="table-responsive">
<table class="table table-bordered table-striped bs-events-table">
<thead>
<tr>
<th>Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>change.bs.button</code></td>
<td>The event is fired for a <code>.btn-group</code> and each child <code>.btn</code> that changed it's
<code>checked</code> state.<br><b>This event can be default prevented.</b></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="buttonDATA">
<h3>Button DATA API</h3>
<p>The component will initialize all <code>.btn-group</code> elements with the <code>data-toggle="buttons"</code>
and works with radio buttons and checkboxes that use this markup:</p>
<pre><code class="language-markup"> <!-- the btn-group component -->
<div id="myRadioButtonGroup" class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input type="radio" checked> Checkbox 1 (pre-checked) <!-- OR type="radio" -->
</label>
<label class="btn btn-secondary">
<input type="radio"> Checkbox 2 <!-- OR type="radio" -->
</label>
<label class="btn btn-secondary">
<input type="radio"> Checkbox 3 <!-- OR type="radio" -->
</label>
</div>
</code></pre>
</section>
<section id="buttonJS">
<h3>Button JavaScript API</h3>
<p>If the above markup is present in the DOM when the library is loaded, it will initialize via DATA API, if
inserted later into the DOM, here's how to initialize it:</p>
<pre><code class="language-javascript">// initialize
var myRadioButtonGroupINIT = new BSN.Button('#myRadioButtonGroup');
</code></pre>
<p>The <code>myRadioButtonGroup</code> element now stores store the initialization object, just like the other
components of the library:</p>
<pre><code class="language-javascript">// reference the initialization, even for DATA API initialized btn-group elements
var myRadioButtonGroupINIT = myRadioButtonGroup.Button;
</code></pre>
<p>The only thing left to do is to attach handlers to the original events:</p>
<pre><code class="language-javascript">//let's do some custom binding action
myRadioButtonGroup.addEventListener('change.bs.button', function(event) {
// do something when anything inside the btn-group changes
// event.target is myRadioButtonGroup
});
myRadioButtonGroup.getElementsByTagName('INPUT')[0].addEventListener('change.bs.button',function(event) {
// do something only when THE FIRST input changes
// event.target is the first <input type="radio"> found in myRadioButtonGroup
});
</code></pre>
<p>Since the native <code>change</code> event isn't consistent in most legacy browsers, with the help of polyfills and
the original <code>change.bs.button</code> event you can easily bind other
functions into the context of a <code>.btn-group</code> and / or it's child inputs.</p>
</section>
<section id="buttonExamples">
<h3>Button Examples</h3>
<p>You should open your console to test the handler functions bound by the <code>change.bs.button</code> event of
the following checkboxes and radio buttons. You should notice that the event isn't triggered twice.</p>
<p>First we'll toggle some checkboxes. </p>
<p>
<span id="checkboxButtons" class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-secondary active">
<svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<path d="M610.97 656.333c0 0 361.421-260.813 321.331-559.309-0.87-6.502-3.021-10.906-5.734-13.722-2.765-2.816-7.014-5.018-13.466-5.888-291.686-41.011-546.509 328.806-546.509 328.806-221.082-26.47-205.005 17.613-305.869 259.891-19.302 46.182 11.981 62.106 46.285 49.101 34.304-12.902 109.978-41.523 109.978-41.523l132.608 135.578c0 0-27.955 77.517-40.602 112.589-12.698 35.123 2.816 67.123 48.026 47.411 236.749-103.219 279.859-86.733 253.952-312.934z m51.66-302.899c-30.618-31.386-30.618-82.125 0-113.51 30.618-31.283 80.23-31.283 110.899 0 30.618 31.283 30.618 82.074 0 113.51-30.669 31.283-80.333 31.283-110.899 0z" fill="currentColor"></path>
</svg>
<input type="checkbox" checked> Checkbox 1 (pre-checked)
</label>
<label class="btn btn-outline-secondary">
<input type="checkbox"> Checkbox 2
</label>
<label class="btn btn-outline-secondary">
<input type="checkbox"> Checkbox 3
</label>
</span>
</p>
<p>Finally we toggle radio buttons.</p>
<p>
<span id="radioButtons" class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-secondary">
<svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<path d="M610.97 656.333c0 0 361.421-260.813 321.331-559.309-0.87-6.502-3.021-10.906-5.734-13.722-2.765-2.816-7.014-5.018-13.466-5.888-291.686-41.011-546.509 328.806-546.509 328.806-221.082-26.47-205.005 17.613-305.869 259.891-19.302 46.182 11.981 62.106 46.285 49.101 34.304-12.902 109.978-41.523 109.978-41.523l132.608 135.578c0 0-27.955 77.517-40.602 112.589-12.698 35.123 2.816 67.123 48.026 47.411 236.749-103.219 279.859-86.733 253.952-312.934z m51.66-302.899c-30.618-31.386-30.618-82.125 0-113.51 30.618-31.283 80.23-31.283 110.899 0 30.618 31.283 30.618 82.074 0 113.51-30.669 31.283-80.333 31.283-110.899 0z" fill="currentColor"></path>
</svg>
<input type="radio" name="optionz" id="optionz1" checked> Radio 1 (preselected)
</label>
<label class="btn btn-outline-secondary active">
<input type="radio" name="optionz" id="optionz2"> Radio 2
</label>
<label class="btn btn-outline-secondary">
<input type="radio" name="optionz" id="optionz3"> Radio 3
</label>
</span>
</p>
<p>In addition, the component will also work outside the <code><div class="btn-group"></code>.</p>
<p>
<span class="btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-secondary">
<svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<path d="M610.97 656.333c0 0 361.421-260.813 321.331-559.309-0.87-6.502-3.021-10.906-5.734-13.722-2.765-2.816-7.014-5.018-13.466-5.888-291.686-41.011-546.509 328.806-546.509 328.806-221.082-26.47-205.005 17.613-305.869 259.891-19.302 46.182 11.981 62.106 46.285 49.101 34.304-12.902 109.978-41.523 109.978-41.523l132.608 135.578c0 0-27.955 77.517-40.602 112.589-12.698 35.123 2.816 67.123 48.026 47.411 236.749-103.219 279.859-86.733 253.952-312.934z m51.66-302.899c-30.618-31.386-30.618-82.125 0-113.51 30.618-31.283 80.23-31.283 110.899 0 30.618 31.283 30.618 82.074 0 113.51-30.669 31.283-80.333 31.283-110.899 0z" fill="currentColor"></path>
</svg>
<input type="radio" name="features" id="feature1"> Radio 1
</label>
<label class="btn btn-outline-secondary active">
<input type="radio" name="features" id="feature2" checked> Radio 2 (preselected)
</label>
<label class="btn btn-outline-secondary">
<input type="radio" name="features" id="feature3"> Radio 3
</label>
</span>
</p>
</section>
</section>
<section id="componentCarousel">
<h2>Carousel</h2>
<p>The <b>Carousel</b> component covers the original events, as well as a set of essential options and public methods.
In addition it also provides a solid DATA API, it adds a <code>paused</code> class to the target element when in
paused state, and a solid event handling implementation.</p>
<section id="carouselOptions">
<h3>Carousel Options</h3>
<div class="table-responsive">
<table class="table table-bordered table-striped js-options-table">
<thead>
<tr>
<th>Name</th>
<th>type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>keyboard</code></td>
<td><em>boolean</em></td>
<td><em>true</em></td>
<td>Option that allows yout to navigate the carousel with left and right arrows.</td>
</tr>
<tr>
<td><code>pause</code></td>
<td><em>boolean</em><br>or<br> the text <em>'hover'</em></td>
<td><em>'hover'</em></td>
<td>Option that makes possible to pause the carousel transition on mouse hover and touchdown. If you want to
disable pause on hover, do that via JavaScript or the <code>data-pause="false"</code> attribute.</td>
</tr>
<tr>
<td><code>touch</code></td>
<td><em>boolean</em></td>
<td><em>true</em></td>
<td>Option that enables support for touch events. This option is <code>true</code> by default, but you can
disable it via JavaScript or the <code>data-touch="false"</code> attribute.</td>
</tr>
<tr>
<td><code>interval</code></td>
<td><em>number</em></td>
<td><em>5000</em></td>
<td>Sets the component's delay between transitions in miliseconds. Can be set via JavaScript or the
<code>data-interval="INTERVAL"</code> attribute. If you want to disable the automatic transition, you can
set this option to <em>false</em>. The component will not automatically slide if the element is
not visible in the viewport.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="carouselMethods">
<h3>Carousel Methods</h3>
<dl class="row">
<dt class="col-md-2">.cycle()</dt>
<dd class="col-md-10">The method will cycle through items. Using the method while the animation is
running will produce no effect.</dd>
<dt class="col-md-2">.slideTo()</dt>
<dd class="col-md-10">The method will allow you to jump to the index of a certain item. Using the
method while the animation is running will produce no effect.</dd>
<dt class="col-md-2">.getActiveIndex()</dt>
<dd class="col-md-10">The method returns the index of the current active item.</dd>
<dt class="col-md-2">.dispose()</dt>
<dd class="col-md-10">Removes the component from target element.</dd>
</dl>
</section>
<section id="carouselEvents">
<h3>Carousel Events</h3>
<p>All the component's original event are triggered for the <code><div class="carousel"></code> element, and the
<code>event.relatedTarget</code> is the newly activated carousel item.</p>
<div class="table-responsive">
<table class="table table-bordered table-striped bs-events-table">
<thead>
<tr>
<th>Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>slide.bs.carousel</code></td>
<td>This event fires immediately when the <code>slideTo()</code> instance method is called.<br>
<b>This event can be default prevented.</b></td>
</tr>
<tr>
<td><code>slid.bs.carousel</code></td>
<td>This event is fired when transition has finished.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="carouselDATA">
<h3>Carousel DATA API</h3>
<p>The component covers most of the original implementation in regards to DATA API, except that you can ignore
some of the attributes for the controls, but they must have at least their specific class in order to work.
This is a basic template markup followed by a complete attribute breakdown:</p>
<pre><code class="language-markup"><!-- the Carousel component -->
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="5000" data-touch="true" data-pause="hover">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<img class="img-fluid" src="..." alt="...">
<div class="carousel-caption">
<h3>This is a carousel caption</h3>
</div>
</div>
<div class="carousel-item">
<img class="img-fluid" src="..." alt="...">
<div class="carousel-caption">
<h3>This is a caption</h3>
</div>
</div>
<div class="carousel-item">
<img class="img-fluid" src="..." alt="...">
<div class="carousel-caption">
<h3>This is another caption</h3>
</div>
</div>
</div>
<!-- Controls -->
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Prev</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</code></pre>
<p>A quick walk through the attributes:</p>
<ul>
<li><code>id="myCarousel"</code> is required if you append the above template into the DOM and need a way to
target this exact element;</li>
<li><code>data-ride="carousel"</code> is the attribute required if you want the <b>Carousel</b> component
to initialize your element on page load;</li>
<li><code>data-keyboard="false"</code> (not shown in the sample markup) is the attribute that enables carousel
navigation via keyboard left and right arrow keys;</li>
<li><code>data-interval="5000"</code> sets the automatic slide interval; the <code>false</code> value will
disable automatic slide transition; the usage of this attribute for each item is not implemented in BSN;</li>
<li><code>data-pause="hover"</code> is the attribute you can set to pause the carousel on mouse hover, but
it also adds a <code>paused</code> class to your carousel; if the above is also <code>false</code>,
this setting has no effect;</li>
<li><code>data-touch="true"</code> is the attribute you can set to enable touch support for your carousel,
however, you must have at least 3 <code>.carousel-item</code> elements in order to work;</li>
<li><code>data-slide-to="0"</code> is an attribute used by <code>.carousel-indicators</code> elements, BSN
does not require this attribute in order to work, it will simply look into elements of the
<code>.carousel-indicators</code>; when clicked will slide to the carousel item with the same index,
0 (zero) in this case;</li>
<li><code>data-slide="prev"</code> / <code>data-slide="next"</code> when clicked, will slide to the next /
previous carousel item; these attributes are <b>optional</b>, but the class <code>carousel-control</code> is
<b>required</b>;</li>
<li><code>href="#myCarousel"</code> attribute is not required for the next and previous controls; we will see
in the example below why now and how to do it with BSN;</li>
<li><code>class="carousel-item active"</code> / <code>class="active"</code> when <em>active</em> class is
present for a carousel item or indicator, that indicates which carousel item is currently shown to the user,
the above <code>.getActiveIndex()</code> method will look for it when needed.</li>
</ul>
</section>
<section id="carouselJS">
<h3>Carousel JavaScript API</h3>
<p>The component grants full access to the internal working via JavaScript; whether via the public methods or the
original events, you can do a whole bunch of things. Assuming the above markup have been injected into the DOM,
let's go ahead and initialize it:</p>
<pre><code class="language-javascript">// initialize with some options
var myCarouselInit = new BSN.Carousel('#myCarousel', { // these options values will override the ones set via DATA API
interval: false,
pause: false,
keyboard: false
});
</code></pre>
<p>And now we can play with the methods:</p>
<pre><code class="language-javascript">// use getActiveIndex()
var currentActiveItem = myCarouselInit.getActiveIndex();
// jump to a certain item
myCarouselInit.slideTo(2);
// if the carousel was set with `interval: false`
// we can do this to go to the next item
myCarouselInit.cycle();
// anytime you need to destroy
myCarouselInit.dispose();
</code></pre>
<p>As you probably expect by now, this component also stores the initialization in the element it targets on
initialization, even for instances where the DATA API was used:</p>
<pre><code class="language-javascript">// get some carousel item and reference the initialization
var mySpecialCarouselInit = document.getElementById('mySpecialCarousel').Carousel;
// apply methods
mySpecialCarouselInit.cycle();
</code></pre>
</section>
<section id="carouselExamples">
<h3>Carousel Example</h3>
<p>This is a test demonstrating the component capabilities and it's events, so open your console, and start
clicking, you will be noticed before and after the animation. Also know that there was no active item set by
default in the markup, proving the component can successfully manage this case by setting the first item as active
on initialization.</p>
<div class="thumbnail">
<div id="carouselGenericExample" class="carousel slide" data-ride="carousel" data-interval="false">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carouselGenericExample" data-slide-to="0"></li>
<li data-target="#carouselGenericExample" data-slide-to="1"></li>
<li data-target="#carouselGenericExample" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="carousel-item">
<img class="img-fluid" src="https://unsplash.it/837/300?image=0" alt="">
<div class="carousel-caption">
<h3>This is another carousel</h3>
</div>
</div>
<div class="carousel-item">
<img class="img-fluid" src="https://unsplash.it/837/300?image=10" alt="">
<div class="carousel-caption">
<h3>This is a caption</h3>
</div>
</div>
<div class="carousel-item">
<img class="img-fluid" src="https://unsplash.it/837/300?image=210" alt="">
<div class="carousel-caption">
<h3>This is another caption</h3>
</div>
</div>
</div>
<!-- Controls -->
<a class="carousel-control-prev" href="#carouselGenericExample" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselGenericExample" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div class="btn-group my-3">
<button class="btn btn-outline-secondary"
onclick="carouselGenericExample.Carousel.slideTo(0)">START</button>
<button class="btn btn-outline-secondary"
onclick="carouselGenericExample.Carousel.slideTo(carouselGenericExample.Carousel.getActiveIndex() - 1 )">PREV</button>
<button class="btn btn-outline-secondary"
onclick="carouselGenericExample.Carousel.slideTo(carouselGenericExample.Carousel.getActiveIndex() + 1 )">NEXT</button>
</div>
<p>These three independent buttons use some inline JavaScript to control the carousel:</p>
<pre><code class="language-markup"><button class="btn btn-secondary"
onclick="myCarousel.Carousel.slideTo(0)">
START
</button>
<button
class="btn btn-secondary"
onclick="myCarousel.Carousel.slideTo(myCarousel.Carousel.getActiveIndex() - 1 )">
PREV
</button>
<button
class="btn btn-secondary"
onclick="myCarousel.Carousel.slideTo(myCarousel.Carousel.getActiveIndex() + 1 )">
NEXT
</button>
</code></pre>
<p>This highlights the fact that we don't need to use <code>href="#myCarousel"</code>
attribute for the carousel controls, if the carousel itself has an ID, the above
markup shows you how to do it, easily:</p>
<ul>
<li>when clicked, the first <code><button></code> will slide to first slide</li>
<li>when clicked, the second <code><button></code> will slide to PREVIOUS slide</li>
<li>when clicked, the third <code><button></code> will slide to NEXT slide</li>
</ul>
</section>
</section>
<section id="componentCollapse">
<h2>Collapse</h2>
<p>The <b>Collapse</b> component covers the original events and methods of the jQuery plugin counterpart. This
component understands there is a triggering element that finds its target collapsible element via the
<code>data-target="#collapse-id"</code> attribute or the <code>href="#collapse-id"</code> attribute if it's a link.
</p>
<section id="collapseOptions">
<h3>Collapse Options</h3>
<p>The option below allow you to connect a collapse to a parent accordion.</p>
<div class="table-responsive">
<table class="table table-bordered table-striped js-options-table">
<thead>
<tr>
<th>Name</th>
<th>type</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>parent</code></td>
<td><em>selector</em><br>or<br>reference</td>
<td></td>
<td>Option to reference a parent to be used as an accordion. When a parent is set and found, it will enable
the functionality described in the <code>show()</code> method below. Can be set
via JavaScript or the <code>data-parent="SELECTOR"</code> attribute.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="collapseMethods">
<h3>Collapse Methods</h3>
<p>Calling any of the public methods while animation is running, will produce no effect.</p>
<dl class="row">
<dt class="col-md-2">.show()</dt>
<dd class="col-md-10">The method will expand a collapsible element. In addition, if the collapsible
element is part of an accordion (it's options include a reference to a parent), it will also close any other
visible collapsible element.</dd>
<dt class="col-md-2">.hide()</dt>
<dd class="col-md-10">The method hides a collapsible element.</dd>
<dt class="col-md-2">.toggle()</dt>
<dd class="col-md-10">The method will show / or hide a collapsible element using the above methods and
their full functionalities.</dd>
<dt class="col-md-2">.dispose()</dt>
<dd class="col-md-10">Removes the component from the target element.</dd>
</dl>
</section>
<section id="collapseEvents">
<h3>Collapse Events</h3>
<p>All the component's events are attached to the collapsible element and not its targeting button / element, with
other words, the <code>event.target</code> is the element with the <code>class="collapse"</code> attribute.</p>
<div class="table-responsive">
<table class="table table-bordered table-striped bs-events-table">
<thead>
<tr>
<th>Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>show.bs.collapse</code></td>
<td>This event fires immediately when the <code>show</code> instance method is called.<br>
<b>This event can be default prevented.</b></td>
</tr>
<tr>
<td><code>shown.bs.collapse</code></td>
<td>This event is fired when a collapse element has been made visible to the user.</td>
</tr>
<tr>
<td><code>hide.bs.collapse</code></td>
<td> This event is fired immediately when the <code>hide</code> method has been called. <br>
<b>This event can be default prevented.</b></td>
</tr>
<tr>
<td><code>hidden.bs.collapse</code></td>
<td>This event is fired when a collapse element has been hidden from the user.</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="collapseDATA">
<h3>Collapse DATA API</h3>
<p>In the following markup, the component will initialize the two <code>.btn</code> elements with the
<code>data-toggle="collapse"</code> attribute, both refferencing the same collapsible element via specific atttributes.</p>
<pre><code class="language-markup"><!-- toggle collapse via link with HREF reference -->
<a id="collapseLink" class="btn btn-primary" role="button" aria-expanded="false" aria-controls="collapseExample"
data-toggle="collapse" href="#collapseExample"> <!-- required DATA API -->
Link with href
</a>
<!-- AND / OR toggle collapse via button with data-target attribute reference -->
<button id="collapseButton" class="btn btn-primary" type="button" aria-expanded="false" aria-controls="collapseExample"
data-toggle="collapse" data-target="#collapseExample"> <!-- required DATA API -->
Button with data-target
</button>
<!-- and the basic collapsible template -->
<div class="collapse" id="collapseExample">
<div class="card card-body">
...
</div>
</div>
</code></pre>
<p>Now if we stack multiple collapsible elements and wrap them into one parent with an ID attribute and some helper
CSS classes, we can easily create an accordion.</p>
<pre><code class="language-markup"><!-- accordion template -->
<div class="accordion" id="myAccordion">
<div class="card">
<div class="card-header" id="headingOne">
<h4>
<a role="button" data-toggle="collapse" data-parent="#myAccordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse show" aria-labelledby="headingOne">
<div class="card-body">
Collapse CONTENT 1
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h4>
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#myAccordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" aria-labelledby="headingTwo">
<div class="card-body">
Collapse CONTENT 2
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h4>
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#myAccordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Collapsible Group Item #3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" aria-labelledby="headingThree">
<div class="card-body">
Collapse CONTENT 3
</div>
</div>
</div>
</div>
</code></pre>
</section>
<section id="collapseJS">
<h3>Collapse JavaScript API</h3>
<p>If the above single collapse template have been inserted into the DOM, you need to initialize it via JavaScript.
</p>
<pre><code class="language-javascript">// initialize the component for collapse trigger
var myCollapseInit = new BSN.Collapse('#collapseLink')
</code></pre>
<p>This now enables you to work with the public methods.</p>
<pre><code class="language-javascript">// call the show() right away
myCollapseInit.show();
// call the hide() later
myCollapseInit.hide();
// OR call toggle() some other time
myCollapseInit.toggle();
// lastly, destroy when needed
myCollapseInit.dispose();
</code></pre>
<p>Also we can attach some handlers to the original events:</p>
<pre><code class="language-javascript">// first, we need to reference the collapsible element
var myCollapseExample = document.getElementById(collapseLink.getAttribute('href').replace('#',''));
// attach a handler to the `show.bs.collapse` original event
myCollapseExample.addEventListener('show.bs.collapse', function(event){
// do something cool when .show() method is called
// event.target is myCollapseExample
}, false);
</code></pre>
<p>Alright, now let's say the above accordion template have been inserted into the DOM, you need to initialize its
collapsible elements right away via JavaScript.</p>
<pre><code class="language-javascript">// grab the accordion by its ID
var myAccordion = document.getElementById('myAccordion');
// grab the collapsible triggers for this accordion
var myAccordionTriggers = myAccordion.querySelectorAll('[data-toggle="collapse"]');
// initialize the component for each collapse trigger
Array.from(myAccordionTriggers).map(
collapseTrigger => new BSN.Collapse(
collapseTrigger,
{
parent: myAccordion
}
)
)
</code></pre>
<p>The component grants access to the initialization even for instances where the DATA API was used.</p>
<pre><code class="language-javascript">// grab the collapse trigger initialized via DATA API
var myCollapseTrigger = document.getElementById('myCollapseTrigger');
// reference the initialization
var myCollapseTriggerInit = myCollapseTrigger.Collapse;
</code></pre>
</section>
<section id="collapseExamples">
<h3>Collapse Examples</h3>
<h4>Single collapsible element</h4>
<p>Here's a quick demo with a single collapsible element, using the <code>.well</code> as the container, exactly as
described in the <a href="#collapseUsage">Usage</a> section. The demo also features the original events. </p>
<div id="collapseExampleWrapper">
<p>
<span class="btn-group">
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="true"
aria-controls="collapseExample">
<svg class="btn-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
<path d="M610.97 656.333c0 0 361.421-260.813 321.331-559.309-0.87-6.502-3.021-10.906-5.734-13.722-2.765-2.816-7.014-5.018-13.466-5.888-291.686-41.011-546.509 328.806-546.509 328.806-221.082-26.47-205.005 17.613-305.869 259.891-19.302 46.182 11.981 62.106 46.285 49.101 34.304-12.902 109.978-41.523 109.978-41.523l132.608 135.578c0 0-27.955 77.517-40.602 112.589-12.698 35.123 2.816 67.123 48.026 47.411 236.749-103.219 279.859-86.733 253.952-312.934z m51.66-302.899c-30.618-31.386-30.618-82.125 0-113.51 30.618-31.283 80.23-31.283 110.899 0 30.618 31.283 30.618 82.074 0 113.51-30.669 31.283-80.333 31.283-110.899 0z" fill="currentColor"></path>
</svg>