documentation-3.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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/css/bootstrap.min.css" rel="stylesheet">
  12. <link href="docs/css/highlight.css" rel="stylesheet">
  13. <link href="dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet">
  14. <link href="docs/css/main.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><a href="https://github.com/nostalgiaz/bootstrap-switch" id="github"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
  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 <strong>3</strong></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/master.zip">3 (Stable)</a></li>
  40. <li><a href="https://github.com/nostalgiaz/bootstrap-switch/archive/v2.0.1.zip">2.0.1 (Legacy)</a></li>
  41. </ul>
  42. </li>
  43. <li><a href="#new">What's new</a></li>
  44. <li><a href="#start">Start</a></li>
  45. <li class="dropdown"><a href="#" data-toggle="dropdown">Documentation<span class="caret"></span></a>
  46. <ul class="dropdown-menu">
  47. <li><a href="/documentation-3.html">Version 3 (Stable)</a></li>
  48. <li><a href="/documentation-2.html">Version 2.0.1 (Legacy)</a></li>
  49. </ul>
  50. </li>
  51. <li><a href="https://github.com/nostalgiaz/bootstrap-switch/issues">Bug reports</a></li>
  52. </ul>
  53. </nav>
  54. </div>
  55. </header>
  56. <div class="container content">
  57. <h1 class="page-header">Documentation 3 (Stable)</h1>
  58. <div id="options-3">
  59. <h2 class="page-header">Options</h2>
  60. <table class="table table-bordered table-striped table-responsive">
  61. <thead>
  62. <tr>
  63. <th>Name</th>
  64. <th>Attribute</th>
  65. <th>Type</th>
  66. <th>Description</th>
  67. <th>Values</th>
  68. <th>Default</th>
  69. </tr>
  70. </thead>
  71. <tbody>
  72. <tr>
  73. <td>state</td>
  74. <td>checked</td>
  75. <td>Boolean</td>
  76. <td>The checkbox state</td>
  77. <td>true, false</td>
  78. <td>true</td>
  79. </tr>
  80. <tr>
  81. <td>size</td>
  82. <td>data-size</td>
  83. <td>String</td>
  84. <td>The checkbox state</td>
  85. <td>null, 'mini', 'small', 'normal', 'large'</td>
  86. <td>null</td>
  87. </tr>
  88. <tr>
  89. <td>animate</td>
  90. <td>data-animate</td>
  91. <td>Boolean</td>
  92. <td>Animate the switch</td>
  93. <td>true, false</td>
  94. <td>true</td>
  95. </tr>
  96. <tr>
  97. <td>disabled</td>
  98. <td>disabled</td>
  99. <td>Boolean</td>
  100. <td>Disable state</td>
  101. <td>true, false</td>
  102. <td>false</td>
  103. </tr>
  104. <tr>
  105. <td>readonly</td>
  106. <td>readonly</td>
  107. <td>Boolean</td>
  108. <td>Readonly state</td>
  109. <td>true, false</td>
  110. <td>false</td>
  111. </tr>
  112. <tr>
  113. <td>indeterminate</td>
  114. <td>Boolean</td>
  115. <td>indeterminate state</td>
  116. <td>true, false</td>
  117. <td>false</td>
  118. </tr>
  119. <tr>
  120. <td>onColor</td>
  121. <td>data-on-color</td>
  122. <td>String</td>
  123. <td>Color of the left side of the switch</td>
  124. <td>'primary', 'info', 'success', 'warning', 'danger', 'default'</td>
  125. <td>'primary'</td>
  126. </tr>
  127. <tr>
  128. <td>offColor</td>
  129. <td>data-off-color</td>
  130. <td>String</td>
  131. <td>Color of the right side of the switch</td>
  132. <td>'primary', 'info', 'success', 'warning', 'danger', 'default'</td>
  133. <td>'default'</td>
  134. </tr>
  135. <tr>
  136. <td>onText</td>
  137. <td>data-on-text</td>
  138. <td>String</td>
  139. <td>Text of the left side of the switch</td>
  140. <td>String</td>
  141. <td>'ON'</td>
  142. </tr>
  143. <tr>
  144. <td>offText</td>
  145. <td>data-off-text</td>
  146. <td>String</td>
  147. <td>Text of the right side of the switch</td>
  148. <td>String</td>
  149. <td>'OFF'</td>
  150. </tr>
  151. <tr>
  152. <td>labelText</td>
  153. <td>data-label-text</td>
  154. <td>String</td>
  155. <td>Text of the center handle of the switch</td>
  156. <td>String</td>
  157. <td>'&amp;nbsp;'</td>
  158. </tr>
  159. <tr>
  160. <td>baseClass</td>
  161. <td>data-base-class</td>
  162. <td>String</td>
  163. <td>Global class prefix</td>
  164. <td>String</td>
  165. <td>'bootstrap-switch'</td>
  166. </tr>
  167. <tr>
  168. <td>wrapperClass</td>
  169. <td>data-wrapper-class</td>
  170. <td>String | Array</td>
  171. <td>Container element class(es)</td>
  172. <td>String | Array</td>
  173. <td>'wrapper'</td>
  174. </tr>
  175. <tr>
  176. <td>onInit</td>
  177. <td></td>
  178. <td>Function</td>
  179. <td>Callback function to execute on initialization</td>
  180. <td>Function</td>
  181. <td>
  182. <pre><code class="javascript">function(event, state) {}</code></pre>
  183. </td>
  184. </tr>
  185. <tr>
  186. <td>onSwitchChange</td>
  187. <td></td>
  188. <td>Function</td>
  189. <td>Callback function to execute on switch state change</td>
  190. <td>Function</td>
  191. <td>
  192. <pre><code class="javascript">function(event, state) {}</code></pre>
  193. </td>
  194. </tr>
  195. </tbody>
  196. </table>
  197. <h3>Global Defaults Overriding</h3>
  198. <p>Follow the jQuery convention to override the default options of the library. For instance:</p>
  199. <pre><code>$.fn.bootstrapSwitch.defaults.size = 'large';
  200. $.fn.bootstrapSwitch.defaults.onColor = 'success';</code></pre>
  201. </div>
  202. <div id="methods-3">
  203. <h2 class="page-header">Methods</h2>
  204. <p>In Bootstrap Switch, every option is also a method.</p>
  205. <p>If the second parameter is omitted, the method return the current value.</p>
  206. <p>You can invoke methods as follows:</p>
  207. <pre><code>$('input[name="my-checkbox"]').bootstrapSwitch('state', true, true);</code></pre>
  208. <h3>Additional Methods</h3>
  209. <table class="table table-bordered table-striped table-responsive">
  210. <thead>
  211. <tr>
  212. <th>Name</th>
  213. <th>Description</th>
  214. </tr>
  215. </thead>
  216. <tbody>
  217. <tr>
  218. <td>toggleState</td>
  219. <td>Toggle the switch state</td>
  220. </tr>
  221. <tr>
  222. <td>toggleDisabled</td>
  223. <td>Toggle the disabled state</td>
  224. </tr>
  225. <tr>
  226. <td>toggleReadonly</td>
  227. <td>Toggle the readonly state</td>
  228. </tr>
  229. <tr>
  230. <td>destroy</td>
  231. <td>Destroy the instance of Bootstrap Switch</td>
  232. </tr>
  233. </tbody>
  234. </table>
  235. <h3>Special Behaviours</h3>
  236. <ul>
  237. <li>The method <code>state</code> can receive an optional third parameter <code>skip</code>. if true, <code>switchChange</code> event is not executed. The default is false.</li>
  238. <li>The method <code>toggleState</code> can receive an optional second parameter <code>skip</code>. if true, <code>switchChange</code> event is not executed. The default is false.</li>
  239. <li>The method <code>wrapperClass</code> can accepts a falsy value as second parameter. If so, it resets the class to its default.</li>
  240. </ul>
  241. </div>
  242. <div id="events-3">
  243. <h2 class="page-header">Events</h2>
  244. <p>
  245. All the events are namespaced, therefore always append <code>.bootstrapSwitch</code> when you
  246. attach your handlers.<br>
  247. You can register to the emitted events as follow:
  248. </p>
  249. <pre><code>$('input[name="my-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) {
  250. console.log(this); // DOM element
  251. console.log(event); // jQuery event
  252. console.log(state); // true | false
  253. });</code></pre>
  254. <table class="table table-bordered table-striped table-responsive">
  255. <thead>
  256. <tr>
  257. <th>Name</th>
  258. <th>Description</th>
  259. <th>Parameters</th>
  260. </tr>
  261. </thead>
  262. <tbody>
  263. <tr>
  264. <td>init</td>
  265. <td>Triggered on initialization. 'this' refers to the DOM element.</td>
  266. <td>event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>)</td>
  267. </tr>
  268. <tr>
  269. <td>switchChange</td>
  270. <td>Triggered on switch state change. 'this' refers to the DOM element.</td>
  271. <td>
  272. event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>),
  273. state (true | false)
  274. </td>
  275. </tr>
  276. </tbody>
  277. </table>
  278. </div>
  279. <div id="examples-3">
  280. <h2 class="page-header">Examples</h2>
  281. <p>To be included</p>
  282. <!--
  283. h3 State
  284. .row
  285. .col-sm-6
  286. input(type='checkbox', id='state-switch' checked)
  287. .col-sm-6
  288. .btn-group.pull-right
  289. button(type='button', id='state-switch-state', class='btn btn-default') Get State
  290. &nbsp;
  291. button(type='button', id='state-switch-on', class='btn btn-default') Set On
  292. &nbsp;
  293. button(type='button', id='state-switch-off', class='btn btn-default') Set Off
  294. &nbsp;
  295. button(type='button', id='state-switch-toggle', class='btn btn-default') Toggle State
  296. -->
  297. </div>
  298. </div>
  299. <div class="container bottom">
  300. <p>
  301. Licensed under the
  302. <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License, Version 2.0</a>
  303. · Created by
  304. <a href="https://github.com/nostalgiaz" target="_blank">Mattia Larentis</a>
  305. · Mantained by
  306. <a href="https://github.com/lostcrew" target="_blank">Emanuele Marchi</a>
  307. </p>
  308. </div>
  309. <script src="docs/js/jquery.min.js"></script>
  310. <script src="docs/js/bootstrap.min.js"></script>
  311. <script src="docs/js/highlight.js"></script>
  312. <script src="dist/js/bootstrap-switch.js"></script>
  313. <script src="docs/js/main.js"></script>
  314. </body>
  315. </html>