index.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/html">
  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 name="subauthor" content="Peter Stein">
  9. <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
  10. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" />
  11. <link rel="stylesheet" href="../static/stylesheets/bootstrap-switch.css" />
  12. <link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.css" />
  13. <link rel="stylesheet" href="http://getbootstrap.com/2.3.2/assets/css/docs.css" />
  14. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css">
  15. <link rel="stylesheet" href="http://bdmdesign.github.io/bootstrap-switch/static/stylesheets/flat-ui-fonts.css">
  16. <style type="text/css">
  17. body {
  18. padding-top: 60px;
  19. padding-bottom: 40px;
  20. }
  21. .span4, h1, h4 {
  22. text-align: center;
  23. }
  24. h1 {
  25. font-size: 4em;
  26. }
  27. h4 {
  28. font-weight: 200;
  29. }
  30. h1 {
  31. margin-bottom: 20px;
  32. }
  33. h3 {
  34. margin-top: 20px;
  35. }
  36. </style>
  37. <script>
  38. var _gaq = _gaq || [];
  39. _gaq.push(['_setAccount', 'UA-43092768-1']);
  40. _gaq.push(['_trackPageview']);
  41. (function () {
  42. var ga = document.createElement('script');
  43. ga.type = 'text/javascript';
  44. ga.async = true;
  45. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  46. var s = document.getElementsByTagName('script')[0];
  47. s.parentNode.insertBefore(ga, s);
  48. })();
  49. </script>
  50. </head>
  51. <body>
  52. <a href="https://github.com/nostalgiaz/bootstrap-switch">
  53. <img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub">
  54. </a>
  55. <div class="container">
  56. <div class="row-fluid">
  57. <div class="span8 offset2">
  58. <h1>Bootstrap switch</h1>
  59. <h4>
  60. by
  61. <a href="http://larentis.eu" target="_blank">Mattia Larentis</a> (<a href="https://twitter.com/spiritualguru">@SpiritualGuru</a>)
  62. and
  63. <a href="http://www.bdmdesign.org/" target="_blank">Peter Stein</a>
  64. </h4>
  65. <br>
  66. </div>
  67. </div>
  68. <div class="row-fluid">
  69. <div class="span8 offset2" style="text-align: center;">
  70. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&repo=bootstrap-switch&type=watch&count=true"
  71. allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  72. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&repo=bootstrap-switch&type=fork&count=true"
  73. allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  74. <iframe src="http://ghbtns.com/github-btn.html?user=nostalgiaz&type=follow&count=true"
  75. allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  76. <iframe src="http://ghbtns.com/github-btn.html?user=BdMdesigN&type=follow&count=true"
  77. allowtransparency="true" frameborder="0" scrolling="0" width="170" height="30"></iframe>
  78. </div>
  79. </div>
  80. <div class="row-fluid">
  81. <h2 class="span8 offset2">
  82. <a name="size" class="anchor" href="#size">Size</a>
  83. </h2>
  84. </div>
  85. <div class="row-fluid">
  86. <div class="span8 offset2">
  87. <div class="bs-docs-example">
  88. <div class="make-switch switch-large">
  89. <input type="checkbox" checked>
  90. </div>
  91. <div class="make-switch">
  92. <input type="checkbox" checked>
  93. </div>
  94. <div class="make-switch switch-small">
  95. <input type="checkbox" checked>
  96. </div>
  97. <div class="make-switch switch-mini">
  98. <input type="checkbox" checked>
  99. </div>
  100. <br>
  101. <br>
  102. <span>Dimensions can be changed too:</span>
  103. <div id="dimension-switch" class="make-switch">
  104. <input type="checkbox" checked>
  105. </div>
  106. <br />
  107. <br />
  108. <button id="btn-size-large-switch" class="btn">Large</button>
  109. <button id="btn-size-regular-switch" class="btn">Regular</button>
  110. <button id="btn-size-small-switch" class="btn">Small</button>
  111. <button id="btn-size-mini-switch" class="btn">Mini</button>
  112. </div>
  113. <pre class="prettyprint linenums">
  114. &lt;div class="make-switch switch-large">
  115. &lt;input type="checkbox" checked>
  116. &lt;/div>
  117. &lt;div class="make-switch">
  118. &lt;input type="checkbox" checked>
  119. &lt;/div>
  120. &lt;div class="make-switch switch-small">
  121. &lt;input type="checkbox" checked>
  122. &lt;/div>
  123. &lt;div class="make-switch switch-mini">
  124. &lt;input type="checkbox" checked>
  125. &lt;/div>
  126. &lt;div id="dimension-switch" class="make-switch">
  127. &lt;input type="checkbox" checked>
  128. &lt;/div></pre>
  129. <pre class="prettyprint linenums">
  130. // Resets to the regular style
  131. $('#dimension-switch').bootstrapSwitch('setSizeClass', '');
  132. // Sets a mini switch
  133. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-mini');
  134. // Sets a small switch
  135. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-small');
  136. // Sets a large switch
  137. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-large');</pre>
  138. </div>
  139. </div>
  140. <div class="row-fluid">
  141. <h2 class="span8 offset2">
  142. <a name="colors" class="anchor" href="#colors">Colors</a>
  143. </h2>
  144. </div>
  145. <div class="row-fluid">
  146. <div class="span8 offset2">
  147. <div class="bs-docs-example">
  148. <div class="make-switch" data-on="primary" data-off="info">
  149. <input type="checkbox" checked>
  150. </div>
  151. <div class="make-switch" data-on="info" data-off="success">
  152. <input type="checkbox" checked>
  153. </div>
  154. <div class="make-switch" data-on="success" data-off="warning">
  155. <input type="checkbox" checked>
  156. </div>
  157. <div class="make-switch" data-on="warning" data-off="danger">
  158. <input type="checkbox" checked>
  159. </div>
  160. <div class="make-switch" data-on="danger" data-off="default">
  161. <input type="checkbox" checked>
  162. </div>
  163. <div class="make-switch" data-on="default" data-off="primary">
  164. <input type="checkbox" checked>
  165. </div>
  166. <br />
  167. <br />
  168. <span>Colors can be changed too:</span>
  169. <div id="change-color-switch" class="make-switch" data-on="default" data-off="primary">
  170. <input type="checkbox" checked>
  171. </div>
  172. <br />
  173. <br />
  174. <button id="btn-color-on-switch" class="btn btn-success">
  175. Change "On" color
  176. </button>
  177. <button id="btn-color-off-switch" class="btn btn-danger">
  178. Change "Off" color
  179. </button>
  180. </div>
  181. <pre class="prettyprint linenums">
  182. &lt;div class="make-switch" data-on="primary" data-off="info">
  183. &lt;input type="checkbox" checked>
  184. &lt;/div>
  185. &lt;div class="make-switch" data-on="info" data-off="success">
  186. &lt;input type="checkbox" checked>
  187. &lt;/div>
  188. &lt;div class="make-switch" data-on="success" data-off="warning">
  189. &lt;input type="checkbox" checked>
  190. &lt;/div>
  191. &lt;div class="make-switch" data-on="warning" data-off="danger">
  192. &lt;input type="checkbox" checked>
  193. &lt;/div>
  194. &lt;div class="make-switch" data-on="danger" data-off="default">
  195. &lt;input type="checkbox" checked>
  196. &lt;/div>
  197. &lt;div class="make-switch" data-on="default" data-off="primary">
  198. &lt;input type="checkbox" checked>
  199. &lt;/div>
  200. &lt;div id="change-color-switch" class="make-switch" data-on="default" data-off="primary">
  201. &lt;input type="checkbox" checked>
  202. &lt;/div></pre>
  203. <pre class="prettyprint linenums">
  204. $('#change-color-switch').bootstrapSwitch('setOnClass', 'success');
  205. $('#change-color-switch').bootstrapSwitch('setOffClass', 'danger');</pre>
  206. </div>
  207. </div>
  208. <div class="row-fluid">
  209. <h2 class="span8 offset2">
  210. <a name="animation" class="anchor" href="#animation">Animation <small>javascript</small></a>
  211. </h2>
  212. </div>
  213. <div class="row-fluid">
  214. <div class="span8 offset2">
  215. <div class="bs-docs-example">
  216. <div id="animated-switch" class="make-switch" data-animated="false">
  217. <input type="checkbox" checked>
  218. </div>
  219. <br />
  220. <br />
  221. <button id="btn-animate-switch" class="btn">Animate</button>
  222. <button id="btn-dont-animate-switch" class="btn">Don't animate</button>
  223. </div>
  224. <pre class="prettyprint linenums">
  225. &lt;div id="animated-switch" class="make-switch" data-animated="false">
  226. &lt;input type="checkbox" checked>
  227. &lt;/div></pre>
  228. <pre class="prettyprint linenums">
  229. // Enables animation for the selected item
  230. $('#animated-switch').bootstrapSwitch('setAnimated', true);
  231. // Disables animation for the selected item
  232. $('#animated-switch').bootstrapSwitch('setAnimated', false);</pre>
  233. </div>
  234. </div>
  235. <div class="row-fluid">
  236. <h2 class="span8 offset2">
  237. <a name="disabled" class="anchor" href="#disabled">Disabled</a>
  238. </h2>
  239. </div>
  240. <div class="row-fluid">
  241. <div class="span8 offset2">
  242. <div class="bs-docs-example">
  243. <div class="make-switch">
  244. <input type="checkbox" checked disabled>
  245. </div>
  246. </div>
  247. <pre class="prettyprint linenums">
  248. &lt;div class="make-switch">
  249. &lt;input type="checkbox" checked disabled>
  250. &lt;/div></pre>
  251. </div>
  252. </div>
  253. <div class="row-fluid">
  254. <h2 class="span8 offset2">
  255. <a name="text" class="anchor" href="#text">Text</a>
  256. </h2>
  257. </div>
  258. <div class="row-fluid">
  259. <div class="span8 offset2">
  260. <div class="bs-docs-example">
  261. <div id="label-switch" class="make-switch" data-on-label="SI" data-off-label="NO">
  262. <input type="checkbox" checked>
  263. </div>
  264. <br />
  265. <br />
  266. <button id="btn-label-on-switch" class="btn">Change "On" label</button>
  267. <button id="btn-label-off-switch" class="btn">Change "Off" label</button>
  268. </div>
  269. <pre class="prettyprint linenums">
  270. &lt;div id="label-switch" class="make-switch" data-on-label="SI" data-off-label="NO">
  271. &lt;input type="checkbox" checked>
  272. &lt;/div></pre>
  273. <pre class="prettyprint linenums">
  274. $('#label-switch').bootstrapSwitch('setOnLabel', 'I');
  275. $('#label-switch').bootstrapSwitch('setOffLabel', 'O');</pre>
  276. </div>
  277. </div>
  278. <div class="row-fluid">
  279. <h2 class="span8 offset2">
  280. <a name="label-text" class="anchor" href="#label-text">Label Text</a>
  281. </h2>
  282. </div>
  283. <div class="row-fluid">
  284. <div class="span8 offset2">
  285. <div class="bs-docs-example">
  286. <div class="make-switch" data-text-label="TV">
  287. <input type="checkbox" checked>
  288. </div>
  289. </div>
  290. <pre class="prettyprint linenums">
  291. &lt;div class="make-switch" data-text-label="TV">
  292. &lt;input type="checkbox" checked>
  293. &lt;/div></pre>
  294. <pre class="prettyprint linenums">
  295. $('#label-text-switch').bootstrapSwitch('setTextLabel', 'Radio');</pre>
  296. </div>
  297. </div>
  298. <div class="row-fluid">
  299. <h2 class="span8 offset2">
  300. <a name="html-text" class="anchor" href="#html-text">HTML text</a>
  301. </h2>
  302. </div>
  303. <div class="row-fluid">
  304. <div class="span8 offset2">
  305. <div class="bs-docs-example">
  306. <div class="make-switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
  307. <input type="checkbox" checked>
  308. </div>
  309. </div>
  310. <pre class="prettyprint linenums">
  311. &lt;div class="make-switch" data-on-label="&lt;i class='icon-ok icon-white'>&lt;/i>" data-off-label="&lt;i class='icon-remove'>&lt;/i>">
  312. &lt;input type="checkbox" checked />
  313. &lt;/div></pre>
  314. </div>
  315. </div>
  316. <div class="row-fluid">
  317. <h2 class="span8 offset2">
  318. <a name="html-text-label-icon" class="anchor" href="#html-text-label-icon">HTML text Label Icon</a>
  319. </h2>
  320. </div>
  321. <div class="row-fluid">
  322. <div class="span8 offset2">
  323. <div class="bs-docs-example">
  324. <h5>Standard</h5>
  325. <div class="make-switch 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>">
  326. <input type="checkbox" checked>
  327. </div>
  328. <h5>Font Awesome</h5>
  329. <div class="make-switch 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>">
  330. <input type="checkbox" checked>
  331. </div>
  332. <h5>Flat UI</h5>
  333. <div class="make-switch switch-large" data-label-icon="fui-video" data-on-label="<i class='fui-check icon-white'></i>" data-off-label="<i class='fui-cross'></i>">
  334. <input type="checkbox" checked>
  335. </div>
  336. </div>
  337. <!--<h3>Standard</h3>-->
  338. <pre class="prettyprint linenums">
  339. &lt;div class="make-switch 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>">
  340. &lt;input type="checkbox" checked>
  341. &lt;/div>
  342. &lt;div class="make-switch 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>">
  343. &lt;input type="checkbox" checked>
  344. &lt;/div>
  345. &lt;div class="make-switch" 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>">
  346. &lt;input type="checkbox" checked>
  347. &lt;/div></pre>
  348. <pre class="prettyprint linenums">
  349. $('#label-icon-switch').bootstrapSwitch('setIconLabel', 'icon-remove');</pre>
  350. </div>
  351. </div>
  352. <div class="row-fluid">
  353. <h2 class="span8 offset2">
  354. <a name="event-handler-javascript" class="anchor" href="#event-handler-javascript">Event handler <small>javascript</small></a>
  355. </h2>
  356. </div>
  357. <div class="row-fluid">
  358. <div class="span8 offset2">
  359. <div class="bs-docs-example">
  360. <div id="mySwitch" class="make-switch">
  361. <input type="checkbox" checked>
  362. </div>
  363. </div>
  364. <pre class="prettyprint linenums">
  365. $('#mySwitch').on('switch-change', function (e, data) {
  366. var $el = $(data.el)
  367. , value = data.value;
  368. console.log(e, $el, value);
  369. });</pre>
  370. </div>
  371. </div>
  372. <div class="row-fluid">
  373. <h2 class="span8 offset2">
  374. <a name="label-event-handler-javascript" class="anchor" href="#label-event-handler-javascript">Label Event handler <small>javascript</small></a>
  375. </h2>
  376. </div>
  377. <div class="row-fluid">
  378. <div class="span8 offset2">
  379. <div class="bs-docs-example">
  380. <h5>Label 1</h5>
  381. <label id="label-toggle-switch">Click on this Text to change the switch state</label>
  382. <div class="label-toggle-switch make-switch">
  383. <input type="checkbox" checked>
  384. </div>
  385. <h5>Label 2</h5>
  386. <div id="label2-toggle-switch">
  387. <label class="label-change-switch">Click on this Text to change the switch state
  388. <div class="label2-toggle-switch make-switch">
  389. <input type="checkbox" checked>
  390. </div>
  391. </label>
  392. </div>
  393. </div>
  394. <pre class="prettyprint linenums">
  395. &lt;label id="label-toggle-switch">Click on this Text to change the switch state&lt;/label>
  396. &lt;div class="label-toggle-switch make-switch">
  397. &lt;input type="checkbox" checked />
  398. &lt;/div>
  399. &lt;script>
  400. $('#label-toggle-switch').on('click', function(e, data) {
  401. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  402. });
  403. $('.label-toggle-switch').on('switch-change', function (e, data) {
  404. alert(data.value);
  405. });
  406. &lt;/script>
  407. &lt;div id="label2-toggle-switch">
  408. &lt;label class="label-change-switch">Click on this Text to change the switch state
  409. &lt;div class="label2-toggle-switch make-switch">
  410. &lt;input type="checkbox" checked />
  411. &lt;/div>
  412. &lt;/label>
  413. &lt;/div>
  414. &lt;script>
  415. $('#label2-toggle-switch').on('switch-change', function(e, data) {
  416. alert(data.value);
  417. });
  418. &lt;/script></pre>
  419. </div>
  420. </div>
  421. <div class="row-fluid">
  422. <h2 class="span8 offset2">
  423. <a name="toggle-state" class="anchor" href="#toggle-state">Toggle State <small>javascript</small></a>
  424. </h2>
  425. </div>
  426. <div class="row-fluid">
  427. <div class="span8 offset2">
  428. <div class="bs-docs-example">
  429. <div id="toggle-state-switch" class="make-switch">
  430. <input type="checkbox" checked>
  431. </div>
  432. <br />
  433. <br />
  434. <div id="toggle-state-switch-button-status" class="btny">Status!</div>
  435. <div id="toggle-state-switch-button-on" class="btn">ON!</div>
  436. <div id="toggle-state-switch-button" class="btn">Toggle me!</div>
  437. <div id="toggle-state-switch-button-off" class="btn">OFF!</div>
  438. </div>
  439. <pre class="prettyprint linenums">
  440. $('#toggle-state-switch').bootstrapSwitch('status'); // true || false
  441. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  442. $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</pre>
  443. </div>
  444. </div>
  445. <div class="row-fluid">
  446. <h2 class="span8 offset2">
  447. <a name="destroy" class="anchor" href="#destroy">Destroy <small>javascript</small></a>
  448. </h2>
  449. </div>
  450. <div class="row-fluid">
  451. <div class="span8 offset2">
  452. <div class="bs-docs-example">
  453. <div id="destroy-switch" class="make-switch">
  454. <input type="checkbox" checked>
  455. </div>
  456. <br />
  457. <br />
  458. <button id="btn-destroy-switch" class="btn">Destroy me!</button>
  459. </div>
  460. <pre class="prettyprint linenums">
  461. $('#destroy-switch').bootstrapSwitch('destroy');</pre>
  462. </div>
  463. </div>
  464. <div class="row-fluid">
  465. <h2 class="span8 offset2">
  466. <a name="create" class="anchor" href="#create">Create <small>javascript</small></a>
  467. </h2>
  468. </div>
  469. <div class="row-fluid">
  470. <div class="span8 offset2">
  471. <div class="bs-docs-example">
  472. <input id="create-switch" type="checkbox" checked>
  473. <br />
  474. <br />
  475. <div id="btn-create" class="btn">Create</div>
  476. </div>
  477. <pre class="prettyprint linenums">
  478. $('#create-switch').wrap('&lt;div class="make-switch" />').parent().bootstrapSwitch();</pre>
  479. </div>
  480. </div>
  481. <div class="row-fluid">
  482. <h2 class="span8 offset2">
  483. <a name="disabled-javascript" class="anchor" href="#disabled-javascript">Disabled <small>javascript</small></a>
  484. </h2>
  485. </div>
  486. <div class="row-fluid">
  487. <div class="span8 offset2">
  488. <div class="bs-docs-example">
  489. <label for="disable-switch-input">amazing label</label>
  490. <div id="disable-switch" class="make-switch">
  491. <input id="disable-switch-input" type="checkbox" checked>
  492. </div>
  493. <br />
  494. <br />
  495. <button id="btn-is-active-switch" class="btn">Is active?</button>
  496. <button id="btn-toggle-activation-switch" class="btn">Toggle activation!</button>
  497. <button id="btn-disable-switch" class="btn">Disable!</button>
  498. <button id="btn-activate-switch" class="btn">Activate!</button>
  499. </div>
  500. <pre class="prettyprint linenums">
  501. $('#disable-switch').bootstrapSwitch('isActive');
  502. $('#disable-switch').bootstrapSwitch('toggleActivation');
  503. $('#disable-switch').bootstrapSwitch('setActive', false); // true || false</pre>
  504. </div>
  505. </div>
  506. <div class="row-fluid">
  507. <h2 class="span8 offset2">
  508. <a name="radio-javascript" class="anchor" href="#radio-javascript">Radio <small>javascript</small></a>
  509. </h2>
  510. </div>
  511. <div class="row-fluid">
  512. <div class="span8 offset2">
  513. <div class="bs-docs-example">
  514. <div class="control-group">
  515. <div class="controls">
  516. <label for="option1">Option 1</label>
  517. <div class="make-switch radio1 radio-no-uncheck">
  518. <input id="option1" type="radio" name="radio1" value="option1">
  519. </div>
  520. <label for="option2">Option 2</label>
  521. <div class="make-switch radio1 radio-no-uncheck">
  522. <input id="option2" type="radio" name="radio1" value="option2">
  523. </div>
  524. <label for="option3">Option 3</label>
  525. <div class="make-switch radio1 radio-no-uncheck">
  526. <input id="option3" type="radio" name="radio1" value="option3">
  527. </div>
  528. </div>
  529. </div>
  530. </div>
  531. <pre class="prettyprint linenums">
  532. &lt;div class="control-group">
  533. &lt;div class="controls">
  534. &lt;label for="option1">Option 1&lt;/label>
  535. &lt;div class="make-switch radio1 radio-no-uncheck">
  536. &lt;input id="option1" type="radio" name="radio1" value="option1">
  537. &lt;/div>
  538. &lt;label for="option2">Option 2&lt;/label>
  539. &lt;div class="make-switch radio1 radio-no-uncheck">
  540. &lt;input id="option2" type="radio" name="radio1" value="option2">
  541. &lt;/div>
  542. &lt;label for="option3">Option 3&lt;/label>
  543. &lt;div class="make-switch radio1 radio-no-uncheck">
  544. &lt;input id="option3" type="radio" name="radio1" value="option3">
  545. &lt;/div>
  546. &lt;/div>
  547. &lt;/div>
  548. &lt;script>
  549. $('.radio1').on('switch-change', function () {
  550. $('.radio1').bootstrapSwitch('toggleRadioState');
  551. });
  552. // or
  553. $('.radio1').on('switch-change', function () {
  554. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck');
  555. });
  556. // or
  557. $('.radio1').on('switch-change', function () {
  558. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck', false);
  559. });
  560. &lt;/script></pre>
  561. </div>
  562. </div>
  563. <div class="row-fluid">
  564. <h2 class="span8 offset2">
  565. <a name="radio-javascript-allow-uncheck" class="anchor" href="#radio-javascript-allow-uncheck">Radio <small>javascript (allow radios uncheck)</small></a>
  566. </h2>
  567. </div>
  568. <div class="row-fluid">
  569. <div class="span8 offset2">
  570. <div class="bs-docs-example">
  571. <div class="control-group">
  572. <div class="controls">
  573. <label for="option11">Option 1</label>
  574. <div class="make-switch radio2">
  575. <input id="option11" type="radio" name="radio2" value="option11">
  576. </div>
  577. <label for="option12">Option 2</label>
  578. <div class="make-switch radio2">
  579. <input id="option12" type="radio" name="radio2" value="option12" checked="checked">
  580. </div>
  581. <label for="option13">Option 3</label>
  582. <div class="make-switch radio2">
  583. <input id="option13" type="radio" name="radio2" value="option13">
  584. </div>
  585. </div>
  586. </div>
  587. </div>
  588. <pre class="prettyprint linenums">
  589. &lt;div class="control-group">
  590. &lt;div class="controls">
  591. &lt;label for="option11">Option 1&lt;/label>
  592. &lt;div class="make-switch radio2">
  593. &lt;input id="option11" type="radio" name="radio2" value="option1">
  594. &lt;/div>
  595. &lt;label for="option12">Option 2&lt;/label>
  596. &lt;div class="make-switch radio2">
  597. &lt;input id="option12" type="radio" name="radio2" value="option2" checked="checked">
  598. &lt;/div>
  599. &lt;label for="option13">Option 3&lt;/label>
  600. &lt;div class="make-switch radio2">
  601. &lt;input id="option13" type="radio" name="radio2" value="option3">
  602. &lt;/div>
  603. &lt;/div>
  604. &lt;/div>
  605. &lt;script>
  606. $('.radio2').on('switch-change', function () {
  607. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  608. });
  609. &lt;/script></pre>
  610. </div>
  611. </div>
  612. <div class="row-fluid">
  613. <h2 class="span8 offset2">
  614. <a name="form" class="anchor" href="#form">Form <small>- try to use tab, space and reset button</small></a>
  615. </h2>
  616. </div>
  617. <div class="row-fluid">
  618. <div class="span8 offset2">
  619. <div class="bs-docs-example">
  620. <form class="form-horizontal span8 offset2">
  621. <div class="control-group">
  622. <label class="control-label" for="inputEmail">Email</label>
  623. <div class="controls">
  624. <input type="text" id="inputEmail" placeholder="Email">
  625. </div>
  626. </div>
  627. <div class="control-group">
  628. <label class="control-label" for="notification1">Notification 1</label>
  629. <div class="controls">
  630. <div class="make-switch" tabindex="0">
  631. <input id="notification1" type="checkbox">
  632. </div>
  633. </div>
  634. </div>
  635. <div class="control-group">
  636. <label class="control-label" for="notification2">Notification 2</label>
  637. <div class="controls">
  638. <div class="make-switch" tabindex="0">
  639. <input id="notification2" type="checkbox">
  640. </div>
  641. </div>
  642. </div>
  643. <div class="form-actions">
  644. <button type="reset" class="btn btn-inverse">Reset</button>
  645. </div>
  646. </form>
  647. <div class="clearfix"></div>
  648. </div>
  649. <pre class="prettyprint linenums">
  650. &lt;form class="form-horizontal">
  651. &lt;div class="control-group">
  652. &lt;label class="control-label" for="inputEmail">Email&lt;/label>
  653. &lt;div class="controls">
  654. &lt;input type="text" id="inputEmail" placeholder="Email">
  655. &lt;/div>
  656. &lt;/div>
  657. &lt;div class="control-group">
  658. &lt;label class="control-label" for="notification1">Notification 1&lt;/label>
  659. &lt;div class="controls">
  660. &lt;div class="make-switch" tabindex="0">
  661. &lt;input id="notification1" type="checkbox">
  662. &lt;/div>
  663. &lt;/div>
  664. &lt;/div>
  665. &lt;div class="control-group">
  666. &lt;label class="control-label" for="notification2">Notification 2&lt;/label>
  667. &lt;div class="controls">
  668. &lt;div class="make-switch" tabindex="0">
  669. &lt;input id="notification2" type="checkbox">
  670. &lt;/div>
  671. &lt;/div>
  672. &lt;/div>
  673. &lt;div class="form-actions">
  674. &lt;button type="reset" class="btn btn-inverse">Reset&lt;/button>
  675. &lt;/div>
  676. &lt;/form></pre>
  677. </div>
  678. </div>
  679. <div class="row-fluid">
  680. <h2 class="span8 offset2">
  681. <a name="modal" class="anchor" href="#modal">Modal</a>
  682. </h2>
  683. </div>
  684. <!-- MODAL -->
  685. <div class="row-fluid">
  686. <div class="span8 offset2">
  687. <div class="bs-docs-example">
  688. <a href="#myModal" role="button" class="btn" data-toggle="modal">Modal</a>
  689. </div>
  690. <pre class="prettyprint linenums">
  691. &lt;a href="#myModal" role="button" class="btn" data-toggle="modal">Modal&lt;/a>
  692. &lt;div class="modal-body">
  693. &lt;div class="make-switch">
  694. &lt;input type="checkbox" checked>
  695. &lt;/div>
  696. &lt;/div></pre>
  697. </div>
  698. </div>
  699. </div>
  700. <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  701. <div class="modal-header">
  702. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  703. <h3>Modal</h3>
  704. </div>
  705. <div class="modal-body">
  706. <div class="make-switch">
  707. <input type="checkbox" checked>
  708. </div>
  709. </div>
  710. <div class="modal-footer">
  711. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  712. </div>
  713. </div>
  714. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  715. <script>
  716. $(document).ready(function() {
  717. window.prettyPrint && prettyPrint();
  718. $('#mySwitch').on('switch-change', function (e, data) {
  719. var $el = $(data.el)
  720. , value = data.value;
  721. console.log(e, $el, value);
  722. });
  723. // DIMENSION
  724. $('#btn-size-regular-switch').on('click', function () {
  725. $('#dimension-switch').bootstrapSwitch('setSizeClass', '');
  726. });
  727. $('#btn-size-mini-switch').on('click', function () {
  728. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-mini');
  729. });
  730. $('#btn-size-small-switch').on('click', function () {
  731. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-small');
  732. });
  733. $('#btn-size-large-switch').on('click', function () {
  734. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-large');
  735. });
  736. // STATE
  737. $('#toggle-state-switch-button').on('click', function () {
  738. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  739. });
  740. $('#toggle-state-switch-button-on').on('click', function () {
  741. $('#toggle-state-switch').bootstrapSwitch('setState', true);
  742. });
  743. $('#toggle-state-switch-button-off').on('click', function () {
  744. $('#toggle-state-switch').bootstrapSwitch('setState', false);
  745. });
  746. $('#toggle-state-switch-button-status').on('click', function () {
  747. alert($('#toggle-state-switch').bootstrapSwitch('status'));
  748. });
  749. // DESTROY
  750. $('#btn-destroy-switch').on('click', function () {
  751. $('#destroy-switch').bootstrapSwitch('destroy');
  752. $(this).remove();
  753. });
  754. // CREATE
  755. $('#btn-create').on('click', function () {
  756. $('#create-switch').wrap('<div class="make-switch" />').parent().bootstrapSwitch();
  757. $(this).remove()
  758. });
  759. // ACTIVATION
  760. $('#btn-is-active-switch').on('click', function () {
  761. alert($('#disable-switch').bootstrapSwitch('isActive'));
  762. });
  763. $('#btn-toggle-activation-switch').on('click', function () {
  764. $('#disable-switch').bootstrapSwitch('toggleActivation');
  765. });
  766. $('#btn-disable-switch').on('click', function () {
  767. $('#disable-switch').bootstrapSwitch('setActive', false);
  768. });
  769. $('#btn-activate-switch').on('click', function () {
  770. $('#disable-switch').bootstrapSwitch('setActive', true);
  771. });
  772. // LABEL
  773. $('#btn-label-on-switch').on('click', function() {
  774. $('#label-switch').bootstrapSwitch('setOnLabel', 'I');
  775. });
  776. $('#btn-label-off-switch').on('click', function() {
  777. $('#label-switch').bootstrapSwitch('setOffLabel', 'O');
  778. });
  779. $('#label-toggle-switch').on('click', function(e, data) {
  780. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  781. });
  782. $('.label-toggle-switch').on('switch-change', function(e, data) {
  783. alert(data.value);
  784. });
  785. $('#label2-toggle-switch').on('switch-change', function(e, data) {
  786. alert(data.value);
  787. });
  788. // COLOR
  789. $('#btn-color-on-switch').on('click', function() {
  790. $('#change-color-switch').bootstrapSwitch('setOnClass', 'success');
  791. });
  792. $('#btn-color-off-switch').on('click', function() {
  793. $('#change-color-switch').bootstrapSwitch('setOffClass', 'danger');
  794. });
  795. // ANIMATION
  796. $('#btn-animate-switch').on('click', function() {
  797. $('#animated-switch').bootstrapSwitch('setAnimated', true);
  798. });
  799. $('#btn-dont-animate-switch').on('click', function() {
  800. $('#animated-switch').bootstrapSwitch('setAnimated', false);
  801. });
  802. // RADIO
  803. $('.radio1').on('switch-change', function () {
  804. $('.radio1').bootstrapSwitch('toggleRadioState');
  805. });
  806. $('.radio2').on('switch-change', function () {
  807. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  808. });
  809. });
  810. </script>
  811. <footer>
  812. <div class="container-fluid">
  813. <p style="float:left; padding-top: 5px;">
  814. &copy; by
  815. <a href="http://larentis.eu" target="_blank">Mattia Larentis</a> (<a href="https://twitter.com/SpiritualGuru">@SpiritualGuru</a>)
  816. and
  817. <a href="http://www.bdmdesign.org/" target="_blank">Peter Stein</a>
  818. </p>
  819. </div>
  820. </footer>
  821. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  822. <script src="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.js"></script>
  823. <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  824. <script src="../static/js/bootstrap-switch.js"></script>
  825. </body>
  826. </html>