forked from minhur/bootstrap-toggle
-
Notifications
You must be signed in to change notification settings - Fork 67
/
index.html
576 lines (545 loc) · 27.1 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
<!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="Bootstrap 4 Toggle is a bootstrap plugin that converts checkboxes into responsive toggles.">
<meta name="keywords" content="bootstrap, toggle, switch, bootstrap-toggle, bootstrap-switch, bootstrap-checkbox">
<meta name="author" content="https://github.com/gitbrent">
<meta name="version" content="v3.7.0">
<meta name="robots" content="index, follow">
<meta name="revisit-after" content="1 month">
<title>Bootstrap 4 Toggle Switch Button Checkbox</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css" integrity="sha384-5sAR7xN1Nv6T6+dT2mhtzEpVJvfS3NScPQTrOxhwjIuvcA67KV2R5Jz6kr4abQsz" crossorigin="anonymous">
<link rel="stylesheet" href="css/bootstrap4-toggle.css">
<link rel="stylesheet" href="doc/stylesheet.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light container mb-3" role="navigation">
<a class="navbar-brand" href="#">Bootstrap 4 Toggle</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto align-items-center">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item"><a class="nav-link" href="#installation">Installation</a></li>
<li class="nav-item"><a class="nav-link" href="#demos">Demos</a></li>
<li class="nav-item"><a class="nav-link d-none d-sm-none d-md-block" href="#usage">Usage</a></li>
<li class="nav-item"><a class="nav-link d-none d-sm-none d-md-block" href="#api">API</a></li>
<li class="nav-item"><a class="nav-link d-none d-sm-none d-md-block" href="#events">Events</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/gitbrent/bootstrap4-toggle/">GitHub</a></li>
<li class="nav-item"><a class="nav-link" href="https://github.com/gitbrent/bootstrap4-toggle/archive/master.zip">Download</a></li>
</ul>
</div>
</nav>
<div class="mast-head">
<div class="container">
<h1>Bootstrap Switch Button</h1>
<p><strong>Bootstrap Toggle</strong> is a jQuery plugin/widget that converts plain checkboxes into responsive toggle switch buttons.</p>
<!--<div class="mast-links">
<iframe src="https://ghbtns.com/github-btn.html?user=gitbrent&repo=bootstrap4-toggle&type=fork&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=gitbrent&repo=bootstrap4-toggle&type=star&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
</div>-->
</div>
</div>
</header>
<main>
<section id="updated" class="container my-5">
<div class="alert alert-success" role="alert">
<h3 class="alert-heading">Made for Bootstrap 4!</h3>
<h6 class="font-weight-light">This page and all of the switch buttons shown are running on Bootstrap 4.3</h6>
<hr>
<div class="row">
<div class="col-12 col-md-4 mb-1 mb-md-0">
<div class="row align-items-center">
<div class="col-2 p-0 p-md-2 text-right">
<i class="fas fa-check-circle text-success d-none d-sm-none d-md-none d-lg-block" style="font-size:48px"></i>
<i class="fas fa-check-circle text-success d-block d-sm-block d-md-block d-lg-none " style="font-size:24px"></i>
</div>
<div class="col-10">
Supports touch events
</div>
</div>
</div>
<div class="col-12 col-md-4 mb-1 mb-md-0">
<div class="row align-items-center">
<div class="col-2 p-0 p-md-2 text-right">
<i class="fas fa-check-circle text-success d-none d-sm-none d-md-none d-lg-block" style="font-size:48px"></i>
<i class="fas fa-check-circle text-success d-block d-sm-block d-md-block d-lg-none " style="font-size:24px"></i>
</div>
<div class="col-10">
Supports outline colors
</div>
</div>
</div>
<div class="col-12 col-md-4 mb-1 mb-md-0">
<div class="row align-items-center">
<div class="col-2 p-0 p-md-2 text-right">
<i class="fas fa-check-circle text-success d-none d-sm-none d-md-none d-lg-block" style="font-size:48px"></i>
<i class="fas fa-check-circle text-success d-block d-sm-block d-md-block d-lg-none " style="font-size:24px"></i>
</div>
<div class="col-10">
Includes a mini (-xs) size
</div>
</div>
</div>
</div>
</div>
</section>
<section id="installation" class="container my-5">
<h2>Installation</h2>
<hr>
<h3 class="text-secondary mt-4">CDN</h3>
<code class="highlight"><link href="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/css/bootstrap4-toggle.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/js/bootstrap4-toggle.min.js"></script></code>
<h3 class="text-secondary mt-4">Download</h3>
<a href="https://github.com/gitbrent/bootstrap4-toggle/releases/latest">GitHub Latest release</a>
<h3 class="text-secondary mt-4">NPM</h3>
<code class="highlight">npm install bootstrap4-toggle</code>
<h3 class="text-secondary mt-4">Yarn</h3>
<code class="highlight">yarn add bootstrap4-toggle</code>
</section>
<section id="demos" class="container my-5">
<h2>Demos</h2>
<hr>
<h3 class="text-secondary mt-4">Sizes</h3>
<p>Bootstrap toggle is available in different sizes.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-size="lg">
<input type="checkbox" checked data-toggle="toggle">
<input type="checkbox" checked data-toggle="toggle" data-size="sm">
<input type="checkbox" checked data-toggle="toggle" data-size="xs">
</div>
<h3 class="text-secondary mt-4">Custom Sizes</h3>
<p>Bootstrap toggle can handle custom sizes by <code>data-width</code> and <code>data-height</code> options.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-width="100" data-height="75">
<input type="checkbox" checked data-toggle="toggle" data-height="75">
<input type="checkbox" checked data-toggle="toggle" data-width="100">
</div>
<h3 class="text-secondary mt-4">Colors</h3>
<p>Bootstrap Toggle implements all standard bootstrap 4 button colors.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="primary">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="secondary">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="danger">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="warning">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="info">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="light">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="dark">
</div>
<h3 class="text-secondary mt-4">Outline Colors</h3>
<p>Bootstrap Toggle implements all standard bootstrap 4 button outline colors.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-primary" data-offstyle="outline-secondary">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-secondary" data-offstyle="outline-success">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-success" data-offstyle="outline-danger">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-danger" data-offstyle="outline-warning">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-warning" data-offstyle="outline-info">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-info" data-offstyle="outline-light">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-light" data-offstyle="outline-dark">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-dark" data-offstyle="outline-primary">
</div>
<h3 class="text-secondary mt-4">Dark Theme Colors</h3>
<p>Bootstrap Toggle colors look great on dark backgrounds.</p>
<div class="example bg-dark">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="primary" data-offstyle="secondary">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="secondary" data-offstyle="success">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="success" data-offstyle="danger">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="danger" data-offstyle="warning">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="info">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="info" data-offstyle="light">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="light" data-offstyle="dark" data-style="border">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="dark" data-offstyle="light" data-style="border">
</div>
<h3 class="text-secondary mt-4">Dark Theme Outline Colors</h3>
<p>Bootstrap Toggle outline colors look great on dark backgrounds.</p>
<div class="example bg-dark">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-primary" data-offstyle="outline-secondary">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-secondary" data-offstyle="outline-success">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-success" data-offstyle="outline-danger">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-danger" data-offstyle="outline-warning">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-warning" data-offstyle="outline-info">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-info" data-offstyle="outline-light">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-light" data-offstyle="outline-dark" data-style="border">
<input type="checkbox" checked data-toggle="toggle" data-onstyle="outline-dark" data-offstyle="outline-light" data-style="border">
</div>
<h3 class="text-secondary mt-4">Custom Style</h3>
<p>Style the buttons to fit an existing UX.</p>
<div class="example">
<!-- iOS Style: Rounded -->
<style>
.toggle.ios, .toggle-on.ios, .toggle-off.ios { border-radius: 20rem; }
.toggle.ios .toggle-handle { border-radius: 20rem; }
</style>
<input type="checkbox" checked data-toggle="toggle" data-style="ios">
<!-- Android Style: No radius -->
<style>
.toggle.android { border-radius: 0px;}
.toggle.android .toggle-handle { border-radius: 0px; }
</style>
<input type="checkbox" checked data-toggle="toggle" data-style="android" data-onstyle="info">
</div>
<h3 class="text-secondary mt-4">Custom Text</h3>
<p>The text can be changed easily with attributes or options.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-on="Ready" data-off="Not Ready" data-onstyle="success" data-offstyle="danger">
</div>
<h3 class="text-secondary mt-4">HTML, Icons, Images</h3>
<p>You can easily add icons or images since html is supported for on/off text.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-on="<i class='fa fa-play'></i> Play" data-off="<i class='fa fa-pause'></i> Pause">
</div>
<h3 class="text-secondary mt-4">Multiple Lines of Text</h3>
<p>Toggles with multiple lines will adjust its heights.</p>
<div class="example">
<input type="checkbox" checked data-toggle="toggle" data-on="Hello<br>World" data-off="Goodbye<br>World">
</div>
<h3 class="text-secondary mt-4">Animation Speed</h3>
<p>Transition speed can be easily controlled with css <code>transition</code> property on <code>.toggle-group</code>. You can also turn animation off completely.</p>
<div class="example">
<style>
.slow .toggle-group { transition: left 0.7s; -webkit-transition: left 0.7s; }
.fast .toggle-group { transition: left 0.1s; -webkit-transition: left 0.1s; }
.quick .toggle-group { transition: none; -webkit-transition: none; }
</style>
<input type="checkbox" checked data-toggle="toggle" data-style="slow">
<input type="checkbox" checked data-toggle="toggle" data-style="fast">
<input type="checkbox" checked data-toggle="toggle" data-style="quick">
</div>
<h3 class="text-secondary mt-4">Stacked checkboxes</h3>
<p>Simply add <code>data-toggle="toggle"</code> to convert checkboxes into toggles.</p>
<div class="example">
<div class="form-check pl-0">
<input id="stackedCheck1" class="form-check-input" type="checkbox" data-toggle="toggle" checked>
<label for="stackedCheck1" class="form-check-label">Enabled</label>
</div>
<div class="form-check pl-0">
<input id="stackedCheck2" class="form-check-input" type="checkbox" data-toggle="toggle" disabled>
<label for="stackedCheck2" class="form-check-label">Disabled</label>
</div>
</div>
<h3 class="text-secondary mt-4">Inline Checkboxes</h3>
<p>Simply add <code>data-toggle="toggle"</code> to a convert checkboxes into toggles.</p>
<div class="example">
<div class="form-check form-check-inline">
<input id="inlineCheckbox1" class="form-check-input" type="checkbox" data-toggle="toggle" data-style="mr-1" checked>
<label for="inlineCheckbox1" class="form-check-label">Enabled</label>
</div>
<div class="form-check form-check-inline">
<input id="inlineCheckbox2" class="form-check-input" type="checkbox" data-toggle="toggle" data-style="mr-1" disabled>
<label for="inlineCheckbox2" class="form-check-label">Disabled</label>
</div>
</div>
<section>
<section id="usage" class="container my-5 d-none d-sm-none d-md-block">
<h2>Usage</h2>
<hr>
<h3 class="text-secondary mt-4">Initialize with HTML</h3>
<p>Simply add <code>data-toggle="toggle"</code> to convert checkboxes into toggles.</p>
<div class="example">
<input id="chkToggle1" type="checkbox" data-toggle="toggle" checked>
</div>
<h3 class="text-secondary mt-4">Initialize with JavaScript</h3>
<p>Simply call the <code>bootstrapToggle</code> method to convert checkboxes into toggles. See <a href="#api">Options</a> for additional colors, etc.</p>
<div class="example">
<input id="chkToggle2" type="checkbox" checked>
<script>
$(function(){ $('#chkToggle2').bootstrapToggle() });
</script>
</div>
</section>
<section id="api" class="container my-5 d-none d-sm-none d-md-block">
<h2>API</h2>
<hr>
<h3 class="text-secondary mt-4">Options</h3>
<p>Options can be passed via data attributes or JavaScript. For data attributes, append the option name to <code>data-</code>, as in <code>data-on="Enabled"</code>.</p>
<div class="example">
<input type="checkbox" data-toggle="toggle" data-on="Enabled" data-off="Disabled">
<input type="checkbox" id="toggle-two">
<script>
$(function() {
$('#toggle-two').bootstrapToggle({
on: 'Enabled',
off: 'Disabled'
});
})
</script>
</div>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>on</code></td>
<td class="text-nowrap">string | html</td>
<td><code>"On"</code></td>
<td>Text of the <em>on</em> toggle label.</td>
</tr>
<tr>
<td><code>off</code></td>
<td>string | html</td>
<td><code>"Off"</code></td>
<td>Text of the <em>off</em> toggle label.</td>
</tr>
<tr>
<td><code class="text-nowrap">onstyle</code></td>
<td>string</td>
<td><code class="text-nowrap">"primary"</code></td>
<td>
Style of the <em>on</em> toggle.<br>Possible values are:
<code>primary</code>, <code>secondary</code>, <code>success</code>, <code>danger</code>, <code>warning</code>, <code>info</code>, <code>light</code>, <code>dark</code><br>
<small class="text-muted">Refer to Bootstrap <a href="https://getbootstrap.com/docs/4.3/components/buttons/" target="_blank">Button Options</a> documentation for more information.</small>
</td>
</tr>
<tr>
<td><code class="text-nowrap">offstyle</code></td>
<td>string</td>
<td><code class="text-nowrap">"light"</code></td>
<td>
Style of the <em>off</em> toggle.<br>Possible values are:
<code>primary</code>, <code>secondary</code>, <code>success</code>, <code>danger</code>, <code>warning</code>, <code>info</code>, <code>light</code>, <code>dark</code><br>
<small class="text-muted">Refer to Bootstrap <a href="https://getbootstrap.com/docs/4.3/components/buttons/" target="_blank">Button Options</a> documentation for more information.</small>
</td>
</tr>
<tr>
<td><code>size<code></td>
<td>string</td>
<td><em>null</em></td>
<td>
Size of the toggle. If set to <em>null</em>, button is default/normal size.<br>
Possible values are:
<code>lg</code>, <code>sm</code>, <code>xs</code><br>
<small class="text-muted">Refer to Bootstrap <a href="https://getbootstrap.com/docs/4.3/components/buttons/#sizes" target="_blank">Button Sizes</a> documentation for more information.</small>
</td>
</tr>
<tr>
<td><code>style</code></td>
<td>string</td>
<td><em>null</em></td>
<td>
Appends the provided value to the toggle's class attribute.
Use this to apply custom styles to the toggle.
</td>
</tr>
<tr>
<td><code>width</code></td>
<td>integer</td>
<td><em>null</em></td>
<td>
Sets the width of the toggle.<br>
If set to <em>null</em>, width will be calculated.
</td>
</tr>
<tr>
<td><code>height</code></td>
<td>integer</td>
<td><em>null</em></td>
<td>
Sets the height of the toggle.<br>
If set to <em>null</em>, height will be calculated.
</td>
</tr>
</tbody>
</table>
</div>
<h3 class="text-secondary mt-4">Methods</h3>
<p>Methods can be used to control toggles directly.</p>
<div class="example">
<input id="toggle-demo" type="checkbox" data-toggle="toggle">
</div>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Method</th>
<th>Example</th>
<th>Description</th>
<th>Demo</th>
</tr>
</thead>
<tbody>
<tr>
<td><em>initialize</em></td>
<td><code>$('#toggle-demo').bootstrapToggle()</code></td>
<td>Initializes the toggle plugin with options</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.init('#toggle-demo')">Initialize</button></td>
</tr>
<tr>
<td>destroy</td>
<td><code>$('#toggle-demo').bootstrapToggle('destroy')</code></td>
<td>Destroys the toggle</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.destroy('#toggle-demo')">Destroy</button></td>
</tr>
<tr>
<td>on</td>
<td><code>$('#toggle-demo').bootstrapToggle('on')</code></td>
<td>Sets the toggle to 'On' state</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.on('#toggle-demo')">On</button></td>
</tr>
<tr>
<td>off</td>
<td><code>$('#toggle-demo').bootstrapToggle('off')</code></td>
<td>Sets the toggle to 'Off' state</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.off('#toggle-demo')">Off</button></td>
</tr>
<tr>
<td>toggle</td>
<td><code>$('#toggle-demo').bootstrapToggle('toggle')</code></td>
<td>Toggles the state of the toggle</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.toggle('#toggle-demo')">Toggle</button></td>
</tr>
<tr>
<td>enable</td>
<td><code>$('#toggle-demo').bootstrapToggle('enable')</code></td>
<td>Enables the toggle</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.enable('#toggle-demo')">Enable</button></td>
</tr>
<tr>
<td>disable</td>
<td><code>$('#toggle-demo').bootstrapToggle('disable')</code></td>
<td>Disables the toggle</td>
<td><button class="btn btn-outline-dark btn-sm w-100" onclick="demo.disable('#toggle-demo')">Disable</button></td>
</tr>
</tbody>
</table>
</div>
<h3 class="text-secondary mt-4">Checked State</h3>
<p>You can determine the checked state of a toggle using the `checked` property.</p>
<div class="example">
<input id="toggle-state" type="checkbox" data-toggle="toggle">
</div>
<div id="chkState" class="example">
<button type="button" class="btn btn-outline-primary" onClick="showChkState()">Show Toggle State</button>
</div>
<p>
<div>Use the element property for checked state</div>
<code>document.getElementById('toggle-state').checked</code>
<div>Returns true/false</div>
</p>
</section>
<section id="events" class="container my-5 d-none d-sm-none d-md-block">
<h2>Events</h2>
<hr>
<h3 class="text-secondary mt-4">Event Propagation</h3>
<p>
<div class="label label-primary">Notes</div>
• All events are propagated to and from input element to the toggle.<br>
• Listen for events on the <code><input type="checkbox"></code> directly as the toggle stays synced with the input.
</p>
<div class="example">
<input id="toggle-event" type="checkbox" data-toggle="toggle">
<div id="console-event"></div>
<script>
$(function() {
$('#toggle-event').change(function() {
$('#console-event').html('Toggle: ' + $(this).prop('checked'))
})
})
</script>
</div>
<h3 class="text-secondary mt-4">Stopping Event Propagation</h3>
<p>
Passing <code>true</code> to the on/off methods will enable the silent option to prevent the control from propagating the change event in
cases where you want to update the controls on/off state, but do not want to fire the onChange event.
</p>
<div class="example">
<input id="toggle-silent" type="checkbox" data-toggle="toggle" onchange="$('#chgConsole').text(new Date().toISOString()+' ... change event fired!')">
<button class="btn btn-success" onclick="toggleApiOnSilent()" >On by API (silent)</button>
<button class="btn btn-success" onclick="toggleApiOffSilent()">Off by API (silent)</button>
<button class="btn btn-warning" onclick="toggleApiOnNotSilent()">On by API (not silent)</button>
<button class="btn btn-warning" onclick="toggleApiOffNotSilent()">On by API (not silent)</button>
<script>
function toggleApiOnSilent() {
$('#toggle-silent').bootstrapToggle('on', true);
}
function toggleApiOffSilent() {
$('#toggle-silent').bootstrapToggle('off', true);
}
function toggleApiOnNotSilent() {
$('#toggle-silent').bootstrapToggle('on');
}
function toggleApiOffNotSilent() {
$('#toggle-silent').bootstrapToggle('off');
}
</script>
<pre class="mb-0"><code id="chgConsole" class="text-info"></code></pre>
</div>
<h3 class="text-secondary mt-4">API vs Input</h3>
<p>This also means that using the API or Input to trigger events will work both ways.</p>
<div class="example">
<input id="toggle-trigger" type="checkbox" data-toggle="toggle">
<button class="btn btn-success" onclick="toggleApiOn()" >On by API</button>
<button class="btn btn-danger" onclick="toggleApiOff()">Off by API</button>
<button class="btn btn-success" onclick="toggleInpOn()" >On by Input</button>
<button class="btn btn-danger" onclick="toggleInpOff()">Off by Input</button>
<script>
function toggleApiOn() {
$('#toggle-trigger').bootstrapToggle('on');
}
function toggleApiOff() {
$('#toggle-trigger').bootstrapToggle('off');
}
function toggleInpOn() {
$('#toggle-trigger').prop('checked', true).change();
}
function toggleInpOff() {
$('#toggle-trigger').prop('checked', false).change();
}
</script>
</div>
</section>
</main>
<footer class="bg-light border-top p-4">
<div class="container">
<h4 class="font-weight-light">
Original by <a href="https://github.com/minhur" target="_blank">Min Hur</a> |
Updated by <a href="https://github.com/gitbrent" target="_blank">Brent Ely</a> |
Available on <a href="https://github.com/gitbrent/bootstrap4-toggle" target_"blank">GitHub</a> |
Licensed <a href="https://github.com/gitbrent/bootstrap4-toggle/blob/master/LICENSE" target_"blank">MIT</a>
</h4>
<p class="mt-4 mb-0">
<iframe src="https://ghbtns.com/github-btn.html?user=gitbrent&repo=bootstrap4-toggle&type=fork&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
<iframe src="https://ghbtns.com/github-btn.html?user=gitbrent&repo=bootstrap4-toggle&type=star&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px"></iframe>
</p>
</div>
</footer>
<!-- vvv scripts vvv -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script src="doc/script.js"></script>
<script src="js/bootstrap4-toggle.js"></script>
<!-- ^^^ scripts ^^^ -->
<script>
function showChkState() {
$('#chkState .badge').remove();
var chkBool = document.getElementById('toggle-state').checked;
$('#chkState button').after('<div class="badge badge-success px-3 py-2 mb-2 mx-3">'+chkBool+'</div>');
}
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-75147115-4"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-75147115-4');
</script>
</body>
</html>