index.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="Turn checkboxes and radio buttons in toggle switches.">
  8. <meta name="author" content="Mattia Larentis, Emanuele Marchi and Peter Stein">
  9. <title>Bootstrap Switch · Turn checkboxes and radio buttons in toggle switches</title>
  10. <link href="http://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet">
  11. <link href="docs/lib/css/bootstrap.min.css" rel="stylesheet">
  12. <link href="docs/lib/css/highlight.css" rel="stylesheet">
  13. <link href="dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet">
  14. <link href="docs/index.css" rel="stylesheet">
  15. <script>
  16. var _gaq = _gaq || [];
  17. _gaq.push(['_setAccount', 'UA-43092768-1']);
  18. _gaq.push(['_trackPageview']);
  19. (function () {
  20. var ga = document.createElement('script');
  21. ga.type = 'text/javascript';
  22. ga.async = true;
  23. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  24. var s = document.getElementsByTagName('script')[0];
  25. s.parentNode.insertBefore(ga, s);
  26. })();
  27. </script>
  28. </head>
  29. <body>
  30. <header role="banner" class="navbar navbar-default navbar-fixed-top top">
  31. <div class="container">
  32. <div class="navbar-header">
  33. <button type="button" data-toggle="collapse" data-target="#collapse" class="navbar-toggle"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="../" class="navbar-brand">Bootstrap Switch</a>
  34. </div>
  35. <nav id="collapse" role="navigation" class="collapse navbar-collapse">
  36. <ul class="nav navbar-nav">
  37. <li class="dropdown"><a href="#" data-toggle="dropdown">Download<span class="caret"></span></a>
  38. <ul class="dropdown-menu">
  39. <li><a href="https://github.com/nostalgiaz/bootstrap-switch/archive/3.0.zip">3 (Release candidate)</a></li>
  40. <li><a href="https://github.com/nostalgiaz/bootstrap-switch/archive/master.zip">2.0.1</a></li>
  41. </ul>
  42. </li>
  43. <li><a href="#getting-started">Getting Started</a></li>
  44. <li class="dropdown"><a href="#documentation-3" data-toggle="dropdown">Documentation 3<span class="caret"></span></a>
  45. <ul class="dropdown-menu">
  46. <li><a href="#options">Options</a></li>
  47. <li><a href="#methods">Methods</a></li>
  48. <li><a href="#additional-methods">Additional Methods</a></li>
  49. <li><a href="#events">Events</a></li>
  50. </ul>
  51. </li>
  52. <li class="dropdown"><a href="#documentation-2" data-toggle="dropdown">Documentation 2.0.1<span class="caret"></span></a>
  53. <ul class="dropdown-menu">
  54. <li><a href="#options">Options</a></li>
  55. <li><a href="#methods">Methods</a></li>
  56. <li><a href="#events">Events</a></li>
  57. </ul>
  58. </li>
  59. <li><a href="https://github.com/nostalgiaz/bootstrap-switch/issues">Bug reports</a></li>
  60. </ul>
  61. </nav>
  62. </div>
  63. </header>
  64. <div class="container">
  65. <div class="header">
  66. <h2 class="title">Bootstrap Switch</h2>
  67. <p class="lead">Turn checkboxes and radio buttons in toggle switches.</p>
  68. <p>Download your version:</p>
  69. <p>
  70. <input type="checkbox" name="download-version" checked data-size="large" data-on-text="3 RC" data-off-text="2.0.1">
  71. </p>
  72. <p><a href="https://github.com/nostalgiaz/bootstrap-switch/archive/3.0.zip" id="download-3" class="btn btn-lg btn-primary">Download 3 (Release candidate)</a><a href="https://github.com/nostalgiaz/bootstrap-switch/archive/master.zip" id="download-2" class="btn btn-lg btn-primary">Download 2.0.1 (Stable)</a></p>
  73. </div>
  74. <div id="getting-started">
  75. <h1 class="page-header">Getting Started</h1>
  76. <p>Include the dependencies: jQuery, Bootstrap and Bootstrap Switch CSS + Javascript.</p>
  77. <pre><code>[...]
  78. &lt;link href="bootstrap.css" rel="stylesheet"&gt;
  79. &lt;link href="bootstrap-switch.css" rel="stylesheet"&gt;
  80. &lt;script src="jquery.js"&gt;&lt;/script&gt;
  81. &lt;script src="bootstrap-switch.js"&gt;&lt;/script&gt;
  82. [...]</code></pre>
  83. <p>Add your checkbox.</p>
  84. <pre><code>&lt;input type="checkbox" name="my-checkbox" checked&gt;</code></pre>
  85. <p>Initialize Bootstrap Switch.</p>
  86. <pre><code>$("[name='my-checkbox']").bootstrapSwitch();</code></pre>
  87. <p>Enjoy.</p>
  88. </div>
  89. <div id="documentation-3">
  90. <h1 class="page-header">Documentation 3</h1>
  91. <div id="options">
  92. <h2>Options</h2>
  93. <table class="table table-bordered table-striped table-responsive">
  94. <thead>
  95. <tr>
  96. <th>Name</th>
  97. <th>Type</th>
  98. <th>Description</th>
  99. <th>Values</th>
  100. <th>Default</th>
  101. </tr>
  102. </thead>
  103. <tbody>
  104. <tr>
  105. <td>state</td>
  106. <td>Boolean</td>
  107. <td>The checkbox state</td>
  108. <td>true, false</td>
  109. <td>'checked' attribute or true</td>
  110. </tr>
  111. <tr>
  112. <td>size</td>
  113. <td>String</td>
  114. <td>The checkbox state</td>
  115. <td>'mini', 'small', 'normal', 'large'</td>
  116. <td>'normal'</td>
  117. </tr>
  118. <tr>
  119. <td>animate</td>
  120. <td>Boolean</td>
  121. <td>Animate the switch</td>
  122. <td>true, false</td>
  123. <td>true</td>
  124. </tr>
  125. <tr>
  126. <td>disabled</td>
  127. <td>Boolean</td>
  128. <td>Disable state</td>
  129. <td>true, false</td>
  130. <td>'disabled' attribute or false</td>
  131. </tr>
  132. <tr>
  133. <td>readonly</td>
  134. <td>Boolean</td>
  135. <td>Readonly state</td>
  136. <td>true, false</td>
  137. <td>'readonly' attribute or false</td>
  138. </tr>
  139. <tr>
  140. <td>onColor</td>
  141. <td>String</td>
  142. <td>Color of the left side of the switch</td>
  143. <td>'primary', 'info', 'success', 'warning', 'danger', 'default'</td>
  144. <td>'primary'</td>
  145. </tr>
  146. <tr>
  147. <td>offColor</td>
  148. <td>String</td>
  149. <td>Color of the right side of the switch</td>
  150. <td>'primary', 'info', 'success', 'warning', 'danger', 'default'</td>
  151. <td>'default'</td>
  152. </tr>
  153. <tr>
  154. <td>onText</td>
  155. <td>String</td>
  156. <td>Text of the left side of the switch</td>
  157. <td>String</td>
  158. <td>'ON'</td>
  159. </tr>
  160. <tr>
  161. <td>offText</td>
  162. <td>String</td>
  163. <td>Text of the right side of the switch</td>
  164. <td>String</td>
  165. <td>'OFF'</td>
  166. </tr>
  167. <tr>
  168. <td>labelText</td>
  169. <td>String</td>
  170. <td>Text of the center handle of the switch</td>
  171. <td>String</td>
  172. <td>'&amp;nbsp;'</td>
  173. </tr>
  174. <tr>
  175. <td>baseClass</td>
  176. <td>String</td>
  177. <td>Prefix of every other used class</td>
  178. <td>String</td>
  179. <td>'bootstrap-switch'</td>
  180. </tr>
  181. <tr>
  182. <td>wrapperClass</td>
  183. <td>String | Array</td>
  184. <td>Container element class(es)</td>
  185. <td>String | Array</td>
  186. <td>'wrapper'</td>
  187. </tr>
  188. <tr>
  189. <td>onModifierClass</td>
  190. <td>String</td>
  191. <td>On Modifier class, used when the switch state is true</td>
  192. <td>String</td>
  193. <td>'on'</td>
  194. </tr>
  195. <tr>
  196. <td>offModifierClass</td>
  197. <td>String</td>
  198. <td>Off Modifier class, used when the switch state is false</td>
  199. <td>String</td>
  200. <td>'off'</td>
  201. </tr>
  202. <tr>
  203. <td>focusedModifierClass</td>
  204. <td>String</td>
  205. <td>Focused Modifier class, used when the switch is focused</td>
  206. <td>String</td>
  207. <td>'focused'</td>
  208. </tr>
  209. <tr>
  210. <td>animateModifierClass</td>
  211. <td>String</td>
  212. <td>Animate Modifier class, used to apply CSS animation to the switch</td>
  213. <td>String</td>
  214. <td>'animate'</td>
  215. </tr>
  216. <tr>
  217. <td>disabledModifierClass</td>
  218. <td>String</td>
  219. <td>Disabled Modifier class, used the switch is disabled</td>
  220. <td>String</td>
  221. <td>'disabled'</td>
  222. </tr>
  223. <tr>
  224. <td>readonlyModifierClass</td>
  225. <td>String</td>
  226. <td>Readonly Modifier class, used the switch is readonly</td>
  227. <td>String</td>
  228. <td>'readonly'</td>
  229. </tr>
  230. <tr>
  231. <td>onInit</td>
  232. <td>Function</td>
  233. <td>Callback function to execute on initialization</td>
  234. <td>Function</td>
  235. <td>
  236. <pre><code class="javascript">function(event, state) {}</code></pre>
  237. </td>
  238. </tr>
  239. <tr>
  240. <td>onSwitchChange</td>
  241. <td>Function</td>
  242. <td>Callback function to execute on switch state change</td>
  243. <td>Function</td>
  244. <td>
  245. <pre><code class="javascript">function(event, state) {}</code></pre>
  246. </td>
  247. </tr>
  248. </tbody>
  249. </table>
  250. </div>
  251. <div id="methods">
  252. <h2>Methods</h2>
  253. <p>In Bootstrap Switch, every option is also a method.</p>
  254. <p>You can call a method in this way:</p>
  255. <pre><code>$('input[name="my-checkbox"]').bootstrapSwitch('state'[, true][, true]);</code></pre>
  256. <p>If the second parameter is not specified, the current option is returned.</p>
  257. <p>Pass 'true' to 'state' as third parameter, or to 'toggleState' as second parameter in order to avoid the `switchChange` event execution.</p>
  258. </div>
  259. <div id="additional-methods">
  260. <h2>Additional Methods</h2>
  261. <table class="table table-bordered table-striped table-responsive">
  262. <thead>
  263. <tr>
  264. <th>Name</th>
  265. <th>Description</th>
  266. </tr>
  267. </thead>
  268. <tbody>
  269. <tr>
  270. <td>toggleState</td>
  271. <td>Toggle the switch state</td>
  272. </tr>
  273. <tr>
  274. <td>toggleDisabled</td>
  275. <td>Toggle the disabled state</td>
  276. </tr>
  277. <tr>
  278. <td>toggleReadonly</td>
  279. <td>Toggle the readonly state</td>
  280. </tr>
  281. <tr>
  282. <td>destroy</td>
  283. <td>Destroy the instance of Bootstrap Switch</td>
  284. </tr>
  285. </tbody>
  286. </table>
  287. </div>
  288. <div id="events">
  289. <h2>Events</h2>
  290. <p>You can register to the emitted events as follow:</p>
  291. <pre><code>$('input[name="my-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) {
  292. console.log(this); // DOM element
  293. console.log(event); // jQuery event
  294. console.log(state); // true | false
  295. });</code></pre>
  296. <table class="table table-bordered table-striped table-responsive">
  297. <thead>
  298. <tr>
  299. <th>Name</th>
  300. <th>Description</th>
  301. <th>Parameters</th>
  302. </tr>
  303. </thead>
  304. <tbody>
  305. <tr>
  306. <td>init</td>
  307. <td>Triggered on initialization. 'this' refers to the DOM element.</td>
  308. <td>event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>)</td>
  309. </tr>
  310. <tr>
  311. <td>switchChange</td>
  312. <td>Triggered on switch state change. 'this' refers to the DOM element.</td>
  313. <td>
  314. event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>),
  315. state (true | false)
  316. </td>
  317. </tr>
  318. </tbody>
  319. </table>
  320. </div>
  321. <div id="examples">
  322. <h2>Examples<small>To be included</small></h2>
  323. <!--
  324. h3 State
  325. .row
  326. .col-sm-6
  327. input(type='checkbox', id='state-switch' checked)
  328. .col-sm-6
  329. .btn-group.pull-right
  330. button(type='button', id='state-switch-state', class='btn btn-default') Get State
  331. &nbsp;
  332. button(type='button', id='state-switch-on', class='btn btn-default') Set On
  333. &nbsp;
  334. button(type='button', id='state-switch-off', class='btn btn-default') Set Off
  335. &nbsp;
  336. button(type='button', id='state-switch-toggle', class='btn btn-default') Toggle State
  337. -->
  338. </div>
  339. </div>
  340. <div id="documentation-2">
  341. <h1 class="page-header">Documentation 2.0.1<small>To be included</small></h1>
  342. <!--
  343. #options
  344. h2 Options
  345. table.table.table-bordered.table-striped.table-responsive
  346. thead
  347. tr
  348. th Name
  349. th Type
  350. th Description
  351. th Values
  352. th Default
  353. tbody
  354. tr
  355. td state
  356. td Boolean
  357. td The checkbox state
  358. td true, false
  359. td 'checked' attribute or true
  360. tr
  361. td size
  362. td String
  363. td The checkbox state
  364. td 'mini', 'small', 'normal', 'large'
  365. td 'normal'
  366. tr
  367. td animate
  368. td Boolean
  369. td Animate the switch
  370. td true, false
  371. td true
  372. tr
  373. td disabled
  374. td Boolean
  375. td Disable state
  376. td true, false
  377. td 'disabled' attribute or false
  378. tr
  379. td readonly
  380. td Boolean
  381. td Readonly state
  382. td true, false
  383. td 'readonly' attribute or false
  384. tr
  385. td onColor
  386. td String
  387. td Color of the left side of the switch
  388. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  389. td: 'primary'
  390. tr
  391. td offColor
  392. td String
  393. td Color of the right side of the switch
  394. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  395. td: 'default'
  396. tr
  397. td onText
  398. td String
  399. td Text of the left side of the switch
  400. td String
  401. td: 'ON'
  402. tr
  403. td offText
  404. td String
  405. td Text of the right side of the switch
  406. td String
  407. td: 'OFF'
  408. tr
  409. td labelText
  410. td String
  411. td Text of the center handle of the switch
  412. td String
  413. td: '&amp;nbsp;'
  414. tr
  415. td baseClass
  416. td String
  417. td Prefix of every other used class
  418. td String
  419. td 'bootstrap-switch'
  420. tr
  421. td wrapperClass
  422. td String | Array
  423. td Container element class(es)
  424. td String | Array
  425. td 'wrapper'
  426. tr
  427. td containerClass
  428. td String | Array
  429. td Wrapper element class(es)
  430. td String | Array
  431. td 'container'
  432. tr
  433. td handleOnClass
  434. td String | Array
  435. td Handle On element class(es)
  436. td String | Array
  437. td 'handle-on'
  438. tr
  439. td handleOffClass
  440. td String | Array
  441. td Handle Off element class(es)
  442. td String | Array
  443. td 'handle-off'
  444. tr
  445. td labelClass
  446. td String | Array
  447. td Label element class(es)
  448. td String | Array
  449. td 'label'
  450. tr
  451. td onModifierClass
  452. td String
  453. td On Modifier class, used when the switch state is true
  454. td String
  455. td 'on'
  456. tr
  457. td offModifierClass
  458. td String
  459. td Off Modifier class, used when the switch state is false
  460. td String
  461. td 'off'
  462. tr
  463. td focusedModifierClass
  464. td String
  465. td Focused Modifier class, used when the switch is focused
  466. td String
  467. td 'focused'
  468. tr
  469. td animateModifierClass
  470. td String
  471. td Animate Modifier class, used to apply CSS animation to the switch
  472. td String
  473. td 'animate'
  474. tr
  475. td disabledModifierClass
  476. td String
  477. td Disabled Modifier class, used the switch is disabled
  478. td String
  479. td 'disabled'
  480. tr
  481. td readonlyModifierClass
  482. td String
  483. td Readonly Modifier class, used the switch is readonly
  484. td String
  485. td 'readonly'
  486. tr
  487. td onInit
  488. td Function
  489. td Callback function to execute on initialization
  490. td Function
  491. td: pre: code.javascript function(event, state) {}
  492. tr
  493. td onSwitchChange
  494. td Function
  495. td Callback function to execute on switch state change
  496. td Function
  497. td: pre: code.javascript function(event, state) {}
  498. -->
  499. </div>
  500. </div>
  501. <script src="docs/lib/js/jquery.min.js"></script>
  502. <script src="docs/lib/js/bootstrap.min.js"></script>
  503. <script src="docs/lib/js/highlight.js"></script>
  504. <script src="dist/js/bootstrap-switch.js"></script>
  505. <script src="docs/index.js"></script>
  506. </body>
  507. </html>