index.html 35 KB

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