index.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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>
  299. <div class="row-fluid">
  300. <h2 class="span8 offset2">
  301. <a name="html-text" class="anchor" href="#html-text">HTML text</a>
  302. </h2>
  303. </div>
  304. <div class="row-fluid">
  305. <div class="span8 offset2">
  306. <div class="bs-docs-example">
  307. <div class="make-switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
  308. <input type="checkbox" checked>
  309. </div>
  310. </div>
  311. <pre class="prettyprint linenums">
  312. &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>">
  313. &lt;input type="checkbox" checked />
  314. &lt;/div></pre>
  315. </div>
  316. </div>
  317. <div class="row-fluid">
  318. <h2 class="span8 offset2">
  319. <a name="html-text-label-icon" class="anchor" href="#html-text-label-icon">HTML text Label Icon</a>
  320. </h2>
  321. </div>
  322. <div class="row-fluid">
  323. <div class="span8 offset2">
  324. <div class="bs-docs-example">
  325. <h5>Standard</h5>
  326. <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>">
  327. <input type="checkbox" checked>
  328. </div>
  329. <h5>Font Awesome</h5>
  330. <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>">
  331. <input type="checkbox" checked>
  332. </div>
  333. <h5>Flat UI</h5>
  334. <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>">
  335. <input type="checkbox" checked>
  336. </div>
  337. </div>
  338. <!--<h3>Standard</h3>-->
  339. <pre class="prettyprint linenums">
  340. &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>">
  341. &lt;input type="checkbox" checked>
  342. &lt;/div>
  343. &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>">
  344. &lt;input type="checkbox" checked>
  345. &lt;/div>
  346. &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>">
  347. &lt;input type="checkbox" checked>
  348. &lt;/div></pre>
  349. <pre class="prettyprint linenums">
  350. $('#label-icon-switch').bootstrapSwitch('setIconLabel', 'icon-remove');</pre>
  351. </div>
  352. </div>
  353. <div class="row-fluid">
  354. <h2 class="span8 offset2">
  355. <a name="event-handler-javascript" class="anchor" href="#event-handler-javascript">Event handler <small>javascript</small></a>
  356. </h2>
  357. </div>
  358. <div class="row-fluid">
  359. <div class="span8 offset2">
  360. <div class="bs-docs-example">
  361. <div id="mySwitch" class="make-switch">
  362. <input type="checkbox" checked>
  363. </div>
  364. </div>
  365. <pre class="prettyprint linenums">
  366. $('#mySwitch').on('switch-change', function (e, data) {
  367. var $el = $(data.el)
  368. , value = data.value;
  369. console.log(e, $el, value);
  370. });</pre>
  371. </div>
  372. </div>
  373. <div class="row-fluid">
  374. <h2 class="span8 offset2">
  375. <a name="label-event-handler-javascript" class="anchor" href="#label-event-handler-javascript">Label Event handler <small>javascript</small></a>
  376. </h2>
  377. </div>
  378. <div class="row-fluid">
  379. <div class="span8 offset2">
  380. <div class="bs-docs-example">
  381. <h5>Label 1</h5>
  382. <label id="label-toggle-switch">Click on this Text to change the switch state</label>
  383. <div class="label-toggle-switch make-switch">
  384. <input type="checkbox" checked>
  385. </div>
  386. <h5>Label 2</h5>
  387. <div id="label2-toggle-switch">
  388. <label class="label-change-switch">Click on this Text to change the switch state
  389. <div class="label2-toggle-switch make-switch">
  390. <input type="checkbox" checked>
  391. </div>
  392. </label>
  393. </div>
  394. </div>
  395. <pre class="prettyprint linenums">
  396. &lt;label id="label-toggle-switch">Click on this Text to change the switch state&lt;/label>
  397. &lt;div class="label-toggle-switch make-switch">
  398. &lt;input type="checkbox" checked />
  399. &lt;/div>
  400. &lt;script>
  401. $('#label-toggle-switch').on('click', function(e, data) {
  402. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  403. });
  404. $('.label-toggle-switch').on('switch-change', function (e, data) {
  405. alert(data.value);
  406. });
  407. &lt;/script>
  408. &lt;div id="label2-toggle-switch">
  409. &lt;label class="label-change-switch">Click on this Text to change the switch state
  410. &lt;div class="label2-toggle-switch make-switch">
  411. &lt;input type="checkbox" checked />
  412. &lt;/div>
  413. &lt;/label>
  414. &lt;/div>
  415. &lt;script>
  416. $('#label2-toggle-switch').on('switch-change', function(e, data) {
  417. alert(data.value);
  418. });
  419. &lt;/script></pre>
  420. </div>
  421. </div>
  422. <div class="row-fluid">
  423. <h2 class="span8 offset2">
  424. <a name="toggle-state" class="anchor" href="#toggle-state">Toggle State <small>javascript</small></a>
  425. </h2>
  426. </div>
  427. <div class="row-fluid">
  428. <div class="span8 offset2">
  429. <div class="bs-docs-example">
  430. <div id="toggle-state-switch" class="make-switch">
  431. <input type="checkbox" checked>
  432. </div>
  433. <br />
  434. <br />
  435. <div id="toggle-state-switch-button-status" class="btny">Status!</div>
  436. <div id="toggle-state-switch-button-on" class="btn">ON!</div>
  437. <div id="toggle-state-switch-button" class="btn">Toggle me!</div>
  438. <div id="toggle-state-switch-button-off" class="btn">OFF!</div>
  439. </div>
  440. <pre class="prettyprint linenums">
  441. $('#toggle-state-switch').bootstrapSwitch('status'); // true || false
  442. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  443. $('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false</pre>
  444. </div>
  445. </div>
  446. <div class="row-fluid">
  447. <h2 class="span8 offset2">
  448. <a name="destroy" class="anchor" href="#destroy">Destroy <small>javascript</small></a>
  449. </h2>
  450. </div>
  451. <div class="row-fluid">
  452. <div class="span8 offset2">
  453. <div class="bs-docs-example">
  454. <div id="destroy-switch" class="make-switch">
  455. <input type="checkbox" checked>
  456. </div>
  457. <br />
  458. <br />
  459. <button id="btn-destroy-switch" class="btn">Destroy me!</button>
  460. </div>
  461. <pre class="prettyprint linenums">
  462. $('#destroy-switch').bootstrapSwitch('destroy');</pre>
  463. </div>
  464. </div>
  465. <div class="row-fluid">
  466. <h2 class="span8 offset2">
  467. <a name="create" class="anchor" href="#create">Create <small>javascript</small></a>
  468. </h2>
  469. </div>
  470. <div class="row-fluid">
  471. <div class="span8 offset2">
  472. <div class="bs-docs-example">
  473. <input id="create-switch" type="checkbox" checked>
  474. <br />
  475. <br />
  476. <div id="btn-create" class="btn">Create</div>
  477. </div>
  478. <pre class="prettyprint linenums">
  479. $('#create-switch').wrap('&lt;div class="make-switch" />').parent().bootstrapSwitch();</pre>
  480. </div>
  481. </div>
  482. <div class="row-fluid">
  483. <h2 class="span8 offset2">
  484. <a name="disabled-javascript" class="anchor" href="#disabled-javascript">Disabled <small>javascript</small></a>
  485. </h2>
  486. </div>
  487. <div class="row-fluid">
  488. <div class="span8 offset2">
  489. <div class="bs-docs-example">
  490. <label for="disable-switch-input">amazing label</label>
  491. <div id="disable-switch" class="make-switch">
  492. <input id="disable-switch-input" type="checkbox" checked>
  493. </div>
  494. <br />
  495. <br />
  496. <button id="btn-is-active-switch" class="btn">Is active?</button>
  497. <button id="btn-toggle-activation-switch" class="btn">Toggle activation!</button>
  498. <button id="btn-disable-switch" class="btn">Disable!</button>
  499. <button id="btn-activate-switch" class="btn">Activate!</button>
  500. </div>
  501. <pre class="prettyprint linenums">
  502. $('#disable-switch').bootstrapSwitch('isActive');
  503. $('#disable-switch').bootstrapSwitch('toggleActivation');
  504. $('#disable-switch').bootstrapSwitch('setActive', false); // true || false</pre>
  505. </div>
  506. </div>
  507. <div class="row-fluid">
  508. <h2 class="span8 offset2">
  509. <a name="radio-javascript" class="anchor" href="#radio-javascript">Radio <small>javascript</small></a>
  510. </h2>
  511. </div>
  512. <div class="row-fluid">
  513. <div class="span8 offset2">
  514. <div class="bs-docs-example">
  515. <div class="control-group">
  516. <div class="controls">
  517. <label for="option1">Option 1</label>
  518. <div class="make-switch radio1 radio-no-uncheck">
  519. <input id="option1" type="radio" name="radio1" value="option1">
  520. </div>
  521. <label for="option2">Option 2</label>
  522. <div class="make-switch radio1 radio-no-uncheck">
  523. <input id="option2" type="radio" name="radio1" value="option2">
  524. </div>
  525. <label for="option3">Option 3</label>
  526. <div class="make-switch radio1 radio-no-uncheck">
  527. <input id="option3" type="radio" name="radio1" value="option3">
  528. </div>
  529. </div>
  530. </div>
  531. </div>
  532. <pre class="prettyprint linenums">
  533. &lt;div class="control-group">
  534. &lt;div class="controls">
  535. &lt;label for="option1">Option 1&lt;/label>
  536. &lt;div class="make-switch radio1 radio-no-uncheck">
  537. &lt;input id="option1" type="radio" name="radio1" value="option1">
  538. &lt;/div>
  539. &lt;label for="option2">Option 2&lt;/label>
  540. &lt;div class="make-switch radio1 radio-no-uncheck">
  541. &lt;input id="option2" type="radio" name="radio1" value="option2">
  542. &lt;/div>
  543. &lt;label for="option3">Option 3&lt;/label>
  544. &lt;div class="make-switch radio1 radio-no-uncheck">
  545. &lt;input id="option3" type="radio" name="radio1" value="option3">
  546. &lt;/div>
  547. &lt;/div>
  548. &lt;/div>
  549. &lt;script>
  550. $('.radio1').on('switch-change', function () {
  551. $('.radio1').bootstrapSwitch('toggleRadioState');
  552. });
  553. // or
  554. $('.radio1').on('switch-change', function () {
  555. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck');
  556. });
  557. // or
  558. $('.radio1').on('switch-change', function () {
  559. $('.radio1').bootstrapSwitch('toggleRadioStateAllowUncheck', false);
  560. });
  561. &lt;/script></pre>
  562. </div>
  563. </div>
  564. <div class="row-fluid">
  565. <h2 class="span8 offset2">
  566. <a name="radio-javascript-allow-uncheck" class="anchor" href="#radio-javascript-allow-uncheck">Radio <small>javascript (allow radios uncheck)</small></a>
  567. </h2>
  568. </div>
  569. <div class="row-fluid">
  570. <div class="span8 offset2">
  571. <div class="bs-docs-example">
  572. <div class="control-group">
  573. <div class="controls">
  574. <label for="option11">Option 1</label>
  575. <div class="make-switch radio2">
  576. <input id="option11" type="radio" name="radio2" value="option11">
  577. </div>
  578. <label for="option12">Option 2</label>
  579. <div class="make-switch radio2">
  580. <input id="option12" type="radio" name="radio2" value="option12" checked="checked">
  581. </div>
  582. <label for="option13">Option 3</label>
  583. <div class="make-switch radio2">
  584. <input id="option13" type="radio" name="radio2" value="option13">
  585. </div>
  586. </div>
  587. </div>
  588. </div>
  589. <pre class="prettyprint linenums">
  590. &lt;div class="control-group">
  591. &lt;div class="controls">
  592. &lt;label for="option11">Option 1&lt;/label>
  593. &lt;div class="make-switch radio2">
  594. &lt;input id="option11" type="radio" name="radio2" value="option1">
  595. &lt;/div>
  596. &lt;label for="option12">Option 2&lt;/label>
  597. &lt;div class="make-switch radio2">
  598. &lt;input id="option12" type="radio" name="radio2" value="option2" checked="checked">
  599. &lt;/div>
  600. &lt;label for="option13">Option 3&lt;/label>
  601. &lt;div class="make-switch radio2">
  602. &lt;input id="option13" type="radio" name="radio2" value="option3">
  603. &lt;/div>
  604. &lt;/div>
  605. &lt;/div>
  606. &lt;script>
  607. $('.radio2').on('switch-change', function () {
  608. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  609. });
  610. &lt;/script></pre>
  611. </div>
  612. </div>
  613. <div class="row-fluid">
  614. <h2 class="span8 offset2">
  615. <a name="form" class="anchor" href="#form">Form <small>- try to use tab, space and reset button</small></a>
  616. </h2>
  617. </div>
  618. <div class="row-fluid">
  619. <div class="span8 offset2">
  620. <div class="bs-docs-example">
  621. <form class="form-horizontal span8 offset2">
  622. <div class="control-group">
  623. <label class="control-label" for="inputEmail">Email</label>
  624. <div class="controls">
  625. <input type="text" id="inputEmail" placeholder="Email">
  626. </div>
  627. </div>
  628. <div class="control-group">
  629. <label class="control-label" for="notification1">Notification 1</label>
  630. <div class="controls">
  631. <div class="make-switch" tabindex="0">
  632. <input id="notification1" type="checkbox">
  633. </div>
  634. </div>
  635. </div>
  636. <div class="control-group">
  637. <label class="control-label" for="notification2">Notification 2</label>
  638. <div class="controls">
  639. <div class="make-switch" tabindex="0">
  640. <input id="notification2" type="checkbox">
  641. </div>
  642. </div>
  643. </div>
  644. <div class="form-actions">
  645. <button type="reset" class="btn btn-inverse">Reset</button>
  646. </div>
  647. </form>
  648. <div class="clearfix"></div>
  649. </div>
  650. <pre class="prettyprint linenums">
  651. &lt;form class="form-horizontal">
  652. &lt;div class="control-group">
  653. &lt;label class="control-label" for="inputEmail">Email&lt;/label>
  654. &lt;div class="controls">
  655. &lt;input type="text" id="inputEmail" placeholder="Email">
  656. &lt;/div>
  657. &lt;/div>
  658. &lt;div class="control-group">
  659. &lt;label class="control-label" for="notification1">Notification 1&lt;/label>
  660. &lt;div class="controls">
  661. &lt;div class="make-switch" tabindex="0">
  662. &lt;input id="notification1" type="checkbox">
  663. &lt;/div>
  664. &lt;/div>
  665. &lt;/div>
  666. &lt;div class="control-group">
  667. &lt;label class="control-label" for="notification2">Notification 2&lt;/label>
  668. &lt;div class="controls">
  669. &lt;div class="make-switch" tabindex="0">
  670. &lt;input id="notification2" type="checkbox">
  671. &lt;/div>
  672. &lt;/div>
  673. &lt;/div>
  674. &lt;div class="form-actions">
  675. &lt;button type="reset" class="btn btn-inverse">Reset&lt;/button>
  676. &lt;/div>
  677. &lt;/form></pre>
  678. </div>
  679. </div>
  680. <div class="row-fluid">
  681. <h2 class="span8 offset2">
  682. <a name="modal" class="anchor" href="#modal">Modal</a>
  683. </h2>
  684. </div>
  685. <!-- MODAL -->
  686. <div class="row-fluid">
  687. <div class="span8 offset2">
  688. <div class="bs-docs-example">
  689. <a href="#myModal" role="button" class="btn" data-toggle="modal">Modal</a>
  690. </div>
  691. <pre class="prettyprint linenums">
  692. &lt;a href="#myModal" role="button" class="btn" data-toggle="modal">Modal&lt;/a>
  693. &lt;div class="modal-body">
  694. &lt;div class="make-switch">
  695. &lt;input type="checkbox" checked>
  696. &lt;/div>
  697. &lt;/div></pre>
  698. </div>
  699. </div>
  700. </div>
  701. <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  702. <div class="modal-header">
  703. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  704. <h3>Modal</h3>
  705. </div>
  706. <div class="modal-body">
  707. <div class="make-switch">
  708. <input type="checkbox" checked>
  709. </div>
  710. </div>
  711. <div class="modal-footer">
  712. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  713. </div>
  714. </div>
  715. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  716. <script>
  717. $(document).ready(function() {
  718. window.prettyPrint && prettyPrint();
  719. $('#mySwitch').on('switch-change', function (e, data) {
  720. var $el = $(data.el)
  721. , value = data.value;
  722. console.log(e, $el, value);
  723. });
  724. // DIMENSION
  725. $('#btn-size-regular-switch').on('click', function () {
  726. $('#dimension-switch').bootstrapSwitch('setSizeClass', '');
  727. });
  728. $('#btn-size-mini-switch').on('click', function () {
  729. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-mini');
  730. });
  731. $('#btn-size-small-switch').on('click', function () {
  732. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-small');
  733. });
  734. $('#btn-size-large-switch').on('click', function () {
  735. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-large');
  736. });
  737. // STATE
  738. $('#toggle-state-switch-button').on('click', function () {
  739. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  740. });
  741. $('#toggle-state-switch-button-on').on('click', function () {
  742. $('#toggle-state-switch').bootstrapSwitch('setState', true);
  743. });
  744. $('#toggle-state-switch-button-off').on('click', function () {
  745. $('#toggle-state-switch').bootstrapSwitch('setState', false);
  746. });
  747. $('#toggle-state-switch-button-status').on('click', function () {
  748. alert($('#toggle-state-switch').bootstrapSwitch('status'));
  749. });
  750. // DESTROY
  751. $('#btn-destroy-switch').on('click', function () {
  752. $('#destroy-switch').bootstrapSwitch('destroy');
  753. $(this).remove();
  754. });
  755. // CREATE
  756. $('#btn-create').on('click', function () {
  757. $('#create-switch').wrap('<div class="make-switch" />').parent().bootstrapSwitch();
  758. $(this).remove()
  759. });
  760. // ACTIVATION
  761. $('#btn-is-active-switch').on('click', function () {
  762. alert($('#disable-switch').bootstrapSwitch('isActive'));
  763. });
  764. $('#btn-toggle-activation-switch').on('click', function () {
  765. $('#disable-switch').bootstrapSwitch('toggleActivation');
  766. });
  767. $('#btn-disable-switch').on('click', function () {
  768. $('#disable-switch').bootstrapSwitch('setActive', false);
  769. });
  770. $('#btn-activate-switch').on('click', function () {
  771. $('#disable-switch').bootstrapSwitch('setActive', true);
  772. });
  773. // LABEL
  774. $('#btn-label-on-switch').on('click', function() {
  775. $('#label-switch').bootstrapSwitch('setOnLabel', 'I');
  776. });
  777. $('#btn-label-off-switch').on('click', function() {
  778. $('#label-switch').bootstrapSwitch('setOffLabel', 'O');
  779. });
  780. $('#label-toggle-switch').on('click', function(e, data) {
  781. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  782. });
  783. $('.label-toggle-switch').on('switch-change', function(e, data) {
  784. alert(data.value);
  785. });
  786. $('#label2-toggle-switch').on('switch-change', function(e, data) {
  787. alert(data.value);
  788. });
  789. // COLOR
  790. $('#btn-color-on-switch').on('click', function() {
  791. $('#change-color-switch').bootstrapSwitch('setOnClass', 'success');
  792. });
  793. $('#btn-color-off-switch').on('click', function() {
  794. $('#change-color-switch').bootstrapSwitch('setOffClass', 'danger');
  795. });
  796. // ANIMATION
  797. $('#btn-animate-switch').on('click', function() {
  798. $('#animated-switch').bootstrapSwitch('setAnimated', true);
  799. });
  800. $('#btn-dont-animate-switch').on('click', function() {
  801. $('#animated-switch').bootstrapSwitch('setAnimated', false);
  802. });
  803. // RADIO
  804. $('.radio1').on('switch-change', function () {
  805. $('.radio1').bootstrapSwitch('toggleRadioState');
  806. });
  807. $('.radio2').on('switch-change', function () {
  808. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  809. });
  810. });
  811. </script>
  812. <footer>
  813. <div class="container-fluid">
  814. <p style="float:left; padding-top: 5px;">
  815. &copy; by
  816. <a href="http://larentis.eu" target="_blank">Mattia Larentis</a> (<a href="https://twitter.com/SpiritualGuru">@SpiritualGuru</a>)
  817. and
  818. <a href="http://www.bdmdesign.org/" target="_blank">Peter Stein</a>
  819. </p>
  820. </div>
  821. </footer>
  822. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  823. <script src="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.js"></script>
  824. <script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
  825. <script src="../static/js/bootstrap-switch.js"></script>
  826. </body>
  827. </html>