index.html 18.4 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
<!DOCTYPE html>
<html>
<head>
	<script> if (window.location.href.indexOf('minhur.github.io') > 0) window.location.replace('http://www.bootstraptoggle.com') </script>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="msvalidate.01" content="3638AEFC99423BA5CB586805286C39AA" />
	<meta name="description" content="Bootstrap Toggle is a highly flexible Bootstrap plugin that converts checkboxes into toggles." />
	<meta name="keywords" content="bootstrap, toggle, switch, bootstrap-toggle, bootstrap-switch" />
	<meta name="author" content="metatags generator">
	<meta name="robots" content="index, follow">
	<meta name="revisit-after" content="1 month">
	<title>Bootstrap Toggle</title>
	<link rel="canonical" href="http://www.bootstraptoggle.com">
	<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css" rel="stylesheet" >
	<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
	<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
	<link href="css/bootstrap-toggle.css" rel="stylesheet">
	<link href="doc/stylesheet.css" rel="stylesheet">
	<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
	<header>
		<nav class="navbar navbar-default container" role="navigation">
			<div class="container">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a class="navbar-brand" href="#">Bootstrap Toggle</a>
				</div>
				<div id="navbar" class="collapse navbar-collapse">
					<ul class="nav navbar-nav navbar-right">
						<li><a href="#usage">Usage</a></li>
						<li><a href="#api">API</a></li>
						<li><a href="#events">Events</a></li>
						<li><a href="#demos">Demos</a></li>
						<li><a href="https://github.com/minhur/bootstrap-toggle/issues">Issues</a></li>
						<li><a href="https://github.com/minhur/bootstrap-toggle/archive/master.zip">Download</a></li>
						<li>
							<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=watch" allowtransparency="true" frameborder="0" scrolling="0" width="62" height="20"></iframe>
						</li>
						<li>
							<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=fork" allowtransparency="true" frameborder="0" scrolling="0" width="53" height="20"></iframe>
						</li>
					</ul>
				</div>
			</div>
		</nav>
		<div class="mast-head">
			<div class="container">
				<h1>Bootstrap Toggle</h1>
				<p>Bootstrap Toggle is a highly flexible Bootstrap plugin that converts checkboxes into toggles</p>
				<div class="mast-links">
					<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=watch&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="150" height="30"></iframe>
					<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=fork&count=true&size=large" allowtransparency="true" frameborder="0" scrolling="0" width="150" height="30"></iframe>
				</div>
			</div>
		</div>
	</header>

	<main>
		<div class="container">
			<h2>Getting Started</h2>
			<hr>
			<h3>Installation</h3>
			<p>You can <a href="https://github.com/minhur/bootstrap-toggle/archive/master.zip">download</a> the latest version of Bootstrap Toggle or use CDN to load the library.</p>
			<p><span class="label label-warning">Warning</span> If you are using Bootstrap v2.3.2, use <code>bootstrap2-toggle.min.js</code> and <code>bootstrap2-toggle.min.css</code> instead.</p>
			<code class="highlight">&lt;link href="https://gitcdn.github.io/bootstrap-toggle/2.2.0/css/bootstrap-toggle.min.css" rel="stylesheet"&gt;
&lt;script src="https://gitcdn.github.io/bootstrap-toggle/2.2.0/js/bootstrap-toggle.min.js"&gt;&lt;/script&gt;</code>

			<h3>Bower Install</h3>
			<p></p>
			<code class="highlight bash">bower install bootstrap-toggle</code>
		</div>
		<div id="usage" class="container">
			<h2>Usage</h2>
			<hr>

			<h3>Basic example</h3>
			<p>Simply add <code>data-toggle="toggle"</code> to convert checkboxes into toggles.</p>
			<div class="example">
				<input type="checkbox" checked data-toggle="toggle">
			</div>

			<h3>Stacked checkboxes</h3>
			<p>Refer to Bootstrap <a href="http://getbootstrap.com/css/#forms-controls" target="_blank">Form Controls</a> documentation to create stacked checkboxes. Simply add <code>data-toggle="toggle"</code> to convert checkboxes into toggles.</p>
			<div class="example">
				<div class="checkbox">
					<label>
						<input type="checkbox" data-toggle="toggle">
						Option one is enabled
					</label>
				</div>
				<div class="checkbox disabled">
					<label>
						<input type="checkbox" disabled data-toggle="toggle">
						Option two is disabled
					</label>
				</div>
			</div>

			<h3>Inline Checkboxes</h3>
			<p>Refer to Bootstrap <a href="http://getbootstrap.com/css/#forms-controls" target="_blank">Form Controls</a> documentation to create inline checkboxes. Simply add <code>data-toggle="toggle"</code> to a convert checkboxes into toggles.</p>
			<div class="example">
				<label class="checkbox-inline">
					<input type="checkbox" checked data-toggle="toggle"> First
				</label>
				<label class="checkbox-inline">
					<input type="checkbox" data-toggle="toggle"> Second
				</label>
				<label class="checkbox-inline">
					<input type="checkbox" data-toggle="toggle"> Third
				</label>
			</div>
		</div>

		<div id="api" class="container">
			<h2>API</h2>
			<hr>

			<h3>Initialize by JavaScript</h3>
			<p>Initialize toggles with id <code>toggle-one</code> with a single line of JavaScript.</p>
			<div class="example">
				<input id="toggle-one" checked type="checkbox">
				<script>
					$(function() {
						$('#toggle-one').bootstrapToggle();
					})
				</script>
			</div>

			<h3>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>on</td>
					<td>string | html</td>
					<td><code>"On"</code></td>
					<td>Text of the <em>on</em> toggle</td>
				</tr>
				<tr>
					<td>off</td>
					<td>string | html</td>
					<td><code>"Off"</code></td>
					<td>Text of the <em>off</em> toggle</td>
				</tr>
				<tr>
					<td>size</td>
					<td>string</td>
					<td><code>"normal"</code></td>
					<td>
						Size of the toggle. Possible values are:<code>large</code>,<code>normal</code>,<code>small</code>,<code>mini</code><br>
						Refer to Bootstrap <a href="http://getbootstrap.com/css/#buttons-sizes" target="_blank">Button Sizes</a> documentation for more information.
					</td>
				</tr>
				<tr>
					<td>onstyle</td>
					<td>string</td>
					<td><code>"primary"</code></td>
					<td>
						Style of the <em>on</em> toggle.<br>Possible values are:<code>default</code>,<code>primary</code>,<code>success</code>,<code>info</code>,<code>warning</code>,<code>danger</code><br>
						Refer to Bootstrap <a href="http://getbootstrap.com/css/#buttons-options" target="_blank">Button Options</a> documentation for more information.
					</td>
				</tr>
				<tr>
					<td>offstyle</td>
					<td>string</td>
					<td><code>"default"</code></td>
					<td>
						Style of the <em>off</em> toggle.<br>Possible values are:<code>default</code>,<code>primary</code>,<code>success</code>,<code>info</code>,<code>warning</code>,<code>danger</code><br>
						Refer to Bootstrap <a href="http://getbootstrap.com/css/#buttons-options" target="_blank">Button Options</a> documentation for more information.
					</td>
				</tr>
				<tr>
					<td>style</td>
					<td>string</td>
					<td></td>
					<td>
						Appends the value to the class attribute of the toggle. This can be used to apply custom styles. Refer to Custom Styles for reference.
					</td>
				</tr>
				<tr>
					<td>width</td>
					<td>integer</td>
					<td><em>null</em></td>
					<td>
						Sets the width of the toggle. if set to <em>null</em>, width will be calculated.
					</td>
				</tr>
				<tr>
					<td>height</td>
					<td>integer</td>
					<td><em>null</em></td>
					<td>
						Sets the height of the toggle. if set to <em>null</em>, height will be calculated.
					</td>
				</tr>
				</tbody>
				</table>
			</div>

			<h3>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-default btn-xs" 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-default btn-xs" 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-default btn-xs" 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-default btn-xs" 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-default btn-xs" 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-default btn-xs" 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-default btn-xs" onclick="demo.disable('#toggle-demo')">Disable</button></td>
				</tr>
				</tbody>
				</table>
			</div>
		</div>


		<div id="events" class="container">
			<h2>Events</h2>
			<hr>

			<h3>Event Propagation</h3>
			<p><span class="label label-primary">Note</span> All events are propagated to and from input element to the toggle. </p>
			<p>You should listen to events from the <code>&lt;input type="checkbox"></code> directly rather than look for custom events.</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>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="toggleOn()">On by API</button>
				<button class="btn btn-danger" onclick="toggleOff()">Off by API</button>
				<button class="btn btn-success" onclick="toggleOnByInput()">On by Input</button>
				<button class="btn btn-danger" onclick="toggleOffByInput()">Off by Input</button>
				<script>
					function toggleOn() {
						$('#toggle-trigger').bootstrapToggle('on')
					}
					function toggleOff() {
						$('#toggle-trigger').bootstrapToggle('off')	
					}
					function toggleOnByInput() {
						$('#toggle-trigger').prop('checked', true).change()
					}
					function toggleOffByInput() {
						$('#toggle-trigger').prop('checked', false).change()
					}
				</script>
			</div>
		</div>

		<div id="demos" class="container">
			<h2>Demos</h2>
			<hr>

			<h3>Sizes</h3>
			<p>Bootstrap toggle is available in different sizes. Refer to Bootstrap <a href="http://getbootstrap.com/css/#buttons-sizes" target="_blank">Button Sizes</a> documentation for more information.</p>
			<div class="example">
				<input type="checkbox" checked data-toggle="toggle" data-size="large">
				<input type="checkbox" checked data-toggle="toggle" data-size="normal">
				<input type="checkbox" checked data-toggle="toggle" data-size="small">
				<input type="checkbox" checked data-toggle="toggle" data-size="mini">
			</div>
			
			<h3>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>Colors</h3>
			<p>Bootstrap Toggle supports various colors. Refer to Bootstrap <a href="http://getbootstrap.com/css/#buttons-options" target="_blank">Button Options</a> documentation for more information.</p>
			<div class="example">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="primary">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="success">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="info">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="warning">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="danger">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="default">
			</div>

			<h3>Colors Mix</h3>
			<p>You can style on state as well as the off state.</p>
			<div class="example">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="success" data-offstyle="danger">
				<input type="checkbox" checked data-toggle="toggle" data-onstyle="warning" data-offstyle="info">
			</div>

			<h3>Custom Style</h3>
			<p>Customized styles can be applied as easily.</p>
			<div class="example">
				<style>
					.toggle.ios, .toggle-on.ios, .toggle-off.ios { border-radius: 20px; }
					.toggle.ios .toggle-handle { border-radius: 20px; }
				</style>
				<input type="checkbox" checked data-toggle="toggle" data-style="ios">
				<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>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>Icons/Html Text</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>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>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-class="fast">
				<input type="checkbox" checked data-toggle="toggle" data-style="quick">
			</div>
		<div>
	</main>
	<footer>
		<div class="container">
			<p>
				<img class="nyt-logo" src="doc/nyt.png">
				<img class="nyt-logo" src="doc/nytdev.svg">
			</p>
			<p>Designed and built by <a href="https://github.com/minhur" target="_blank">Min Hur</a> for <a href="http://developers.nytimes.com" target="_blank">The New York Times Company</a></p>
			<p>Latest Version: 2.2.0 | Code licensed under MIT</p>
			<p>
				<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110" height="20"></iframe>
				<iframe src="https://mdo.github.io/github-buttons/github-btn.html?user=minhur&repo=bootstrap-toggle&type=fork&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="95" height="20"></iframe>
			</p>
		</div>
	</footer>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
	<script src="doc/script.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
	<script src="js/bootstrap-toggle.js"></script>
	<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
		ga('create', 'UA-55669452-1', 'auto');
		ga('send', 'pageview');
	</script>
</body>
</html>