examples.html 40 KB

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