index.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Bootstrap Switch by Mattia Larentis and Peter Stein</title>
  6. <meta name="description" content="Switches for radio buttons and checkboxes">
  7. <meta name="author" content="Mattia Larentis">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  9. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
  10. <link rel="stylesheet" href="../build/css/bootstrap3/bootstrap-switch.css" />
  11. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css">
  12. <link rel="stylesheet" href="http://bdmdesign.github.io/bootstrap-switch/static/stylesheets/flat-ui-fonts.css">
  13. <link rel="stylesheet" href="vendor/prism.css">
  14. <link rel="stylesheet" href="index.css">
  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. <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">
  31. </a>
  32. <div class="container">
  33. <div class="row">
  34. <div class="col-sm-10 col-sm-offset-1">
  35. <header class="jumbotron">
  36. <h1>Bootstrap switch</h1>
  37. <h4>by <a href="http://larentis.eu" target="_blank">Mattia Larentis</a> (<a href="https://twitter.com/spiritualguru">@SpiritualGuru</a>), <a href="http://www.bdmdesign.org/" target="_blank">Peter Stein</a> and <a href="http://www.lostcrew.it" target="_blank">Emanuele Marchi</a></h4>
  38. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&amp;repo=bootstrap-switch&amp;type=watch&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  39. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&amp;repo=bootstrap-switch&amp;type=fork&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  40. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&amp;type=follow&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  41. <iframe src="http://ghbtns.com/github-btn.html?user=BdMdesigN&amp;type=follow&amp;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  42. </header>
  43. <h2><a name="size" class="anchor" href="#size">Size</a></h2>
  44. <div class="bs-docs-example">
  45. <input type="checkbox" checked class="switch-large">
  46. <input type="checkbox" checked>
  47. <input type="checkbox" checked class="switch-small">
  48. <input type="checkbox" checked class="switch-mini">
  49. <br>
  50. <br>
  51. <span>Dimensions can be changed too:</span>
  52. <input type="checkbox" id="dimension-switch" checked>
  53. <br>
  54. <br>
  55. <button id="btn-size-large-switch" class="btn btn-default">Large</button>
  56. <button id="btn-size-regular-switch" class="btn btn-default">Regular</button>
  57. <button id="btn-size-small-switch" class="btn btn-default">Small</button>
  58. <button id="btn-size-mini-switch" class="btn btn-default">Mini</button>
  59. <br>
  60. </div>
  61. <pre class="language-markup">
  62. &lt;input type="checkbox" checked class="switch-large">
  63. &lt;input type="checkbox" checked>
  64. &lt;input type="checkbox" checked class="switch-small">
  65. &lt;input type="checkbox" checked class="switch-mini">
  66. &lt;input type="checkbox" checked></pre>
  67. <pre class="language-javascript">
  68. // Resets to the regular style
  69. $('#dimension-switch').bootstrapSwitch('setSizeClass', '');
  70. // Sets a mini switch
  71. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-mini');
  72. // Sets a small switch
  73. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-small');
  74. // Sets a large switch
  75. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-large');</pre>
  76. <h2><a name="colors" class="anchor" href="#colors">Colors</a></h2>
  77. <div class="bs-docs-example">
  78. <input type="checkbox" checked data-on="primary" data-off="info">
  79. <input type="checkbox" checked data-on="info" data-off="success">
  80. <input type="checkbox" checked data-on="success" data-off="warning">
  81. <input type="checkbox" checked data-on="warning" data-off="danger">
  82. <input type="checkbox" checked data-on="danger" data-off="default">
  83. <input type="checkbox" checked data-on="default" data-off="primary">
  84. <br>
  85. <br>
  86. <span>Colors can be changed too:</span>
  87. <input type="checkbox" id="change-color-switch" checked data-on="default" data-off="primary">
  88. <br>
  89. <br>
  90. <button id="btn-color-on-switch" class="btn btn-success">Change ON color</button>
  91. <button id="btn-color-off-switch" class="btn btn-danger">Change OFF color</button>
  92. </div>
  93. <pre class="language-markup">&lt;input type="checkbox" checked data-on="primary" data-off="info">
  94. &lt;input type="checkbox" checked data-on="info" data-off="success">
  95. &lt;input type="checkbox" checked data-on="success" data-off="warning">
  96. &lt;input type="checkbox" checked data-on="warning" data-off="danger">
  97. &lt;input type="checkbox" checked data-on="danger" data-off="default">
  98. &lt;input type="checkbox" checked data-on="default" data-off="primary">
  99. &lt;input type="checkbox" id="change-color-switch" checked data-on="default" data-off="primary"></pre>
  100. <pre class="language-javascript">
  101. $('#change-color-switch').bootstrapSwitch('setOnClass', 'success');
  102. $('#change-color-switch').bootstrapSwitch('setOffClass', 'danger');</pre>
  103. <h2><a name="animation" class="anchor" href="#animation">Animation <small>javascript</small></a></h2>
  104. <div class="bs-docs-example">
  105. <input type="checkbox" id="animated-switch" checked data-animated="false">
  106. <br>
  107. <br>
  108. <button id="btn-animate-switch" class="btn btn-default">Animate</button>
  109. <button id="btn-dont-animate-switch" class="btn btn-default">Don't animate</button>
  110. </div>
  111. <pre class="language-markup">&lt;input type="checkbox" checked data-animated="false"></pre>
  112. <pre class="language-javascript">
  113. // Enables animation for the selected item
  114. $('#animated-switch').bootstrapSwitch('setAnimated', true);
  115. // Disables animation for the selected item
  116. $('#animated-switch').bootstrapSwitch('setAnimated', false);</pre>
  117. <h2><a name="disabled" class="anchor" href="#disabled">Disabled</a></h2>
  118. <div class="bs-docs-example">
  119. <input type="checkbox" checked disabled>
  120. </div>
  121. <pre class="language-markup">
  122. &lt;input type="checkbox" checked disabled></pre>
  123. <h2><a name="text" class="anchor" href="#text">Text</a></h2>
  124. <div class="bs-docs-example">
  125. <input type="checkbox" id="label-switch" checked data-on-label="SI" data-off-label="NO">
  126. <br>
  127. <button id="btn-label-on-switch" class="btn btn-default">Change "On" label</button>
  128. <button id="btn-label-off-switch" class="btn btn-default">Change "Off" label</button>
  129. </div>
  130. <pre class="language-markup">&lt;input type="checkbox" checked data-on-label="SI" data-off-label="NO"></pre>
  131. <pre class="language-javascript">
  132. $('#label-switch').bootstrapSwitch('setOnLabel', 'I');
  133. $('#label-switch').bootstrapSwitch('setOffLabel', 'O');</pre>
  134. <h2><a name="label-text" class="anchor" href="#label-text">Label Text</a></h2>
  135. <div class="bs-docs-example">
  136. <input type="checkbox" checked data-text-label="TV">
  137. </div>
  138. <pre class="language-markup">&lt;input type="checkbox" checked data-text-label="TV"></pre>
  139. <h2><a name="html-text" class="anchor" href="#html-text">HTML text</a></h2>
  140. <div class="bs-docs-example">
  141. <input type="checkbox" checked data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
  142. </div>
  143. <pre class="language-markup">&lt;input type="checkbox" checked data-on-label="&lt;i class='icon-ok icon-white'>&lt;/i>" data-off-label="&lt;i class='icon-remove'>&lt;/i>"></pre>
  144. <h2><a name="html-text-label-icon" class="anchor" href="#html-text-label-icon">HTML text Label Icon</a></h2>
  145. <div class="bs-docs-example">
  146. <h5>Standard</h5>
  147. <input type="checkbox" checked class="switch-large" data-label-icon="icon-fullscreen" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
  148. <h5>Font Awesome</h5>
  149. <input type="checkbox" checked class="switch-large" data-label-icon="icon-youtube icon-large" data-on-label="<i class='icon-thumbs-up icon-white'></i>" data-off-label="<i class='icon-thumbs-down'></i>">
  150. <h5>Flat UI</h5>
  151. <input type="checkbox" class="switch-large" checked data-label-icon="fui-video" data-on-label="<i class='fui-check icon-white'></i>" data-off-label="<i class='fui-cross'></i>">
  152. </div>
  153. <pre class="language-markup">&lt;input type="checkbox" checked class="switch-large" data-label-icon="icon-fullscreen" data-on-label="&lt;i class='icon-ok icon-white'>&lt;/i>" data-off-label="&lt;i class='icon-remove'>&lt;/i>">
  154. &lt;input type="checkbox" checked class="switch-large" data-label-icon="icon-youtube icon-large" data-on-label="&lt;i class='icon-thumbs-up icon-white'>&lt;/i>" data-off-label="&lt;i class='icon-thumbs-down'>&lt;/i>">
  155. &lt;input type="checkbox" class="switch-large" checked data-label-icon="fui-video" data-on-label="&lt;i class='fui-check icon-white'>&lt;/i>" data-off-label="&lt;i class='fui-cross'>&lt;/i>"></pre>
  156. <h2><a name="event-handler-javascript" class="anchor" href="#event-handler-javascript">Event handler <small>JavaScript</small></a></h2>
  157. <div class="bs-docs-example">
  158. <input type="checkbox" id="switch-change" checked>
  159. </div>
  160. <pre class="language-javascript">
  161. $('#switch-change').on('switch-change', function (e, data) {
  162. var $element = $(data.el),
  163. value = data.value;
  164. console.log(e, $element, value);
  165. });</pre>
  166. <h2><a name="label-event-handler-javascript" class="anchor" href="#label-event-handler-javascript">Label Event handler <small>JavaScript</small></a></h2>
  167. <div class="bs-docs-example">
  168. <h5>Label 1</h5>
  169. <label id="label-toggle-switch">Click on this Text to change the switch state</label>
  170. <input type="checkbox" checked class="label-toggle-switch">
  171. <h5>Label 2</h5>
  172. <div id="label2-toggle-switch">
  173. <label class="label-change-switch">Click on this Text to change the switch state
  174. <input type="checkbox" checked class="label2-toggle-switch">
  175. </label>
  176. </div>
  177. </div>
  178. <pre class="language-markup">
  179. &lt;label id="label-toggle-switch">Click on this Text to change the switch state&lt;/label>
  180. &lt;input type="checkbox" checked />
  181. &lt;div id="label2-toggle-switch">
  182. &lt;label class="label-change-switch">Click on this Text to change the switch state
  183. &lt;input type="checkbox" checked />
  184. &lt;/label>
  185. &lt;/div></pre>
  186. <pre class="language-javascript">
  187. $('#label-toggle-switch').on('click', function(e, data) {
  188. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  189. });
  190. $('.label-toggle-switch').on('switch-change', function (e, data) {
  191. alert(data.value);
  192. });
  193. $('#label2-toggle-switch').on('switch-change', function(e, data) {
  194. alert(data.value);
  195. });</pre>
  196. <h2><a name="toggle-state" class="anchor" href="#toggle-state">Toggle State <small>javascript</small></a></h2>
  197. <div class="bs-docs-example">
  198. <input type="checkbox" id="toggle-state-switch" checked>
  199. <br>
  200. <br>
  201. <div id="toggle-state-switch-button-status" class="btny">Status!</div>
  202. <div id="toggle-state-switch-button-on" class="btn btn-default">ON!</div>
  203. <div id="toggle-state-switch-button" class="btn btn-default">Toggle me!</div>
  204. <div id="toggle-state-switch-button-off" class="btn btn-default">OFF!</div>
  205. </div>
  206. <pre class="language-javascript">
  207. $('#toggle-state-switch').bootstrapSwitch('status'); // true || false
  208. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  209. $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</pre>
  210. <h2><a name="destroy" class="anchor" href="#destroy">Destroy <small>javascript</small></a></h2>
  211. <div class="bs-docs-example">
  212. <input type="checkbox" id="destroy-switch" checked >
  213. <br>
  214. <br>
  215. <button id="btn-destroy-switch" class="btn btn-default">Destroy me!</button>
  216. </div>
  217. <pre class="language-javascript">$('#destroy-switch').bootstrapSwitch('destroy');</pre>
  218. <h2><a name="create" class="anchor" href="#create">Create <small>javascript</small></a></h2>
  219. <div class="bs-docs-example">
  220. <input id="create-switch" type="checkbox" checked>
  221. <br>
  222. <br>
  223. <div id="btn-create" class="btn btn-default">Create</div>
  224. </div>
  225. <pre class="language-javascript">$('#create-switch').bootstrapSwitch();</pre>
  226. <h2><a name="disabled-javascript" class="anchor" href="#disabled-javascript">Disabled <small>javascript</small></a></h2>
  227. <div class="bs-docs-example">
  228. <label for="disable-switch-input">amazing label</label>
  229. <input type="checkbox" id="disable-switch" checked>
  230. <br>
  231. <br>
  232. <button id="btn-is-active-switch" class="btn btn-default">Is active?</button>
  233. <button id="btn-toggle-activation-switch" class="btn btn-default">Toggle activation!</button>
  234. <button id="btn-disable-switch" class="btn btn-default">Disable!</button>
  235. <button id="btn-activate-switch" class="btn btn-default">Activate!</button>
  236. </div>
  237. <pre class="language-javascript">
  238. $('#disable-switch').bootstrapSwitch('isActive');
  239. $('#disable-switch').bootstrapSwitch('toggleActivation');
  240. $('#disable-switch').bootstrapSwitch('setActive', false); // true || false</pre>
  241. <h2><a name="radio-javascript" class="anchor" href="#radio-javascript">Radio <small>javascript</small></a></h2>
  242. <div class="bs-docs-example">
  243. <div class="form-group">
  244. <label for="option1">Option 1</label>
  245. <input id="option1" type="radio" name="radio1" value="option1" class="radio1 radio-no-uncheck">
  246. <label for="option2">Option 2</label>
  247. <input id="option2" type="radio" name="radio1" value="option2" class="radio1 radio-no-uncheck">
  248. <label for="option3">Option 3</label>
  249. <input id="option3" type="radio" name="radio1" value="option3" class="radio1 radio-no-uncheck">
  250. </div>
  251. </div>
  252. <pre class="language-markup">
  253. &lt;div class="form-group">
  254. &lt;label for="option1">Option 1&lt;/label>
  255. &lt;input id="option1" type="radio" name="radio1" value="option1">
  256. &lt;label for="option2">Option 2&lt;/label>
  257. &lt;input id="option2" type="radio" name="radio1" value="option2">
  258. &lt;label for="option3">Option 3&lt;/label>
  259. &lt;input id="option3" type="radio" name="radio1" value="option3">
  260. &lt;/div></pre>
  261. <pre class="language-javascript">
  262. $('.radio1').on('switch-change', function () {
  263. $('.radio1').bootstrapSwitch('toggleRadioState');
  264. });
  265. // or
  266. $('.radio1').on('switch-change', function () {
  267. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck');
  268. });
  269. // or
  270. $('.radio1').on('switch-change', function () {
  271. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck', false);
  272. });</pre>
  273. <h2><a name="radio-javascript-allow-uncheck" class="anchor" href="#radio-javascript-allow-uncheck"><small>javascript (allow radios uncheck)</small></a></h2>
  274. <div class="bs-docs-example">
  275. <div class="form-group">
  276. <label for="option11">Option 1</label>
  277. <input id="option11" type="radio" name="radio2" value="option11" class="radio2">
  278. <label for="option12">Option 2</label>
  279. <input id="option12" type="radio" name="radio2" value="option12" checked="checked" class="radio2">
  280. <label for="option13">Option 3</label>
  281. <input id="option13" type="radio" name="radio2" value="option13" class="radio2">
  282. </div>
  283. </div>
  284. <pre class="language-markup">
  285. &lt;div class="form-group">
  286. &lt;label for="option11">Option 1&lt;/label>
  287. &lt;input id="option11" type="radio" name="radio2" value="option1">
  288. &lt;label for="option12">Option 2&lt;/label>
  289. &lt;input id="option12" type="radio" name="radio2" value="option2" checked="checked">
  290. &lt;label for="option13">Option 3&lt;/label>
  291. &lt;input id="option13" type="radio" name="radio2" value="option3">
  292. &lt;/div></pre>
  293. <pre class="language-javascript">
  294. $('.radio2').on('switch-change', function () {
  295. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  296. });</pre>
  297. <h2><a name="form" class="anchor" href="#form">Form <small>- try to use tab, space and reset button</small></a></h2>
  298. <div class="bs-docs-example">
  299. <form class="clearfix" role="form">
  300. <div class="form-group">
  301. <label class="control-label" for="inputEmail">Email</label>
  302. <input type="text" id="inputEmail" placeholder="Email" class="form-control">
  303. </div>
  304. <div class="form-group">
  305. <label class="control-label" for="notification1">Notification 1</label>
  306. <input id="notification1" type="checkbox">
  307. </div>
  308. <div class="form-group">
  309. <label class="control-label" for="notification2">Notification 2</label>
  310. <input id="notification2" type="checkbox">
  311. </div>
  312. <div class="form-actions">
  313. <button type="reset" class="btn btn-default btn-warning">Reset</button>
  314. </div>
  315. </form>
  316. <div ></div>
  317. </div>
  318. <pre class="language-markup">
  319. &lt;form class="form-horizontal">
  320. &lt;div class="form-group">
  321. &lt;label class="control-label" for="inputEmail">Email&lt;/label>
  322. &lt;input type="text" id="inputEmail" placeholder="Email">
  323. &lt;/div>
  324. &lt;div class="form-group">
  325. &lt;label class="control-label" for="notification1">Notification 1&lt;/label>
  326. &lt;input id="notification1" type="checkbox">
  327. &lt;/div>
  328. &lt;div class="form-group">
  329. &lt;label class="control-label" for="notification2">Notification 2&lt;/label>
  330. &lt;input id="notification2" type="checkbox">
  331. &lt;/div>
  332. &lt;div class="form-actions">
  333. &lt;button type="reset" class="btn btn-inverse">Reset&lt;/button>
  334. &lt;/div>
  335. &lt;/form></pre>
  336. <h2><a name="modal" class="anchor" href="#modal">Modal</a></h2>
  337. <div class="bs-docs-example">
  338. <a href="#myModal" role="button" class="btn btn-default" data-toggle="modal">Modal</a>
  339. </div>
  340. <pre class="language-markup">
  341. &lt;a href="#myModal" role="button" class="btn btn-default" data-toggle="modal">Modal&lt;/a>
  342. &lt;div class="modal-body">
  343. &lt;input type="checkbox" checked>
  344. &lt;/div></pre>
  345. <footer class="footer">
  346. <p>&copy; by <a href="http://larentis.eu" target="_blank">Mattia Larentis</a> (<a href="https://twitter.com/SpiritualGuru">@SpiritualGuru</a>), <a href="http://www.bdmdesign.org/" target="_blank">Peter Stein</a> and <a href="http://www.lostcrew.it/" target="_blank">Emanuele Marchi</a></p>
  347. </footer>
  348. </div>
  349. </div>
  350. </div>
  351. <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
  352. <div class="modal-dialog">
  353. <div class="modal-content">
  354. <div class="modal-header">
  355. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  356. <h3>Modal</h3>
  357. </div>
  358. <div class="modal-body">
  359. <input type="checkbox" checked>
  360. </div>
  361. <div class="modal-footer">
  362. <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
  363. </div>
  364. </div>
  365. </div>
  366. </div>
  367. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  368. <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  369. <script src="../build/js/bootstrap-switch.js"></script>
  370. <script src="vendor/prism.js"></script>
  371. <script src="index.js"></script>
  372. </body>
  373. </html>