index.html 35 KB

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