index.jade 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. doctype html
  2. html(lang='en')
  3. head
  4. meta(charset='utf-8')
  5. meta(http-equiv='X-UA-Compatible', content='IE=edge')
  6. meta(name='viewport', content='width=device-width, initial-scale=1.0')
  7. meta(name='description', content='Turn checkboxes and radio buttons in toggle switches.')
  8. meta(name='author', content='Mattia Larentis, Emanuele Marchi and Peter Stein')
  9. title Bootstrap Switch · Turn checkboxes and radio buttons in toggle switches
  10. link(href='http://fonts.googleapis.com/css?family=Roboto:400,700', rel='stylesheet')
  11. link(href='docs/lib/css/bootstrap.min.css', rel='stylesheet')
  12. link(href='docs/lib/css/highlight.css', rel='stylesheet')
  13. link(href='dist/css/bootstrap3/bootstrap-switch.css', rel='stylesheet')
  14. link(href='docs/index.css', rel='stylesheet')
  15. script.
  16. var _gaq = _gaq || [];
  17. _gaq.push(['_setAccount', 'UA-43092768-1']);
  18. _gaq.push(['_trackPageview']);
  19. (function () {
  20. var ga = document.createElement('script');
  21. ga.type = 'text/javascript';
  22. ga.async = true;
  23. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  24. var s = document.getElementsByTagName('script')[0];
  25. s.parentNode.insertBefore(ga, s);
  26. })();
  27. body
  28. a(href='https://github.com/nostalgiaz/bootstrap-switch', id='github')
  29. img(src='https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png', alt='Fork me on GitHub')
  30. header.navbar.navbar-default.navbar-fixed-top.top(role='banner')
  31. .container
  32. .navbar-header
  33. button.navbar-toggle(type='button', data-toggle='collapse', data-target='#collapse')
  34. span.sr-only Toggle navigation
  35. span.icon-bar
  36. span.icon-bar
  37. span.icon-bar
  38. a.navbar-brand(href='../') Bootstrap Switch <strong>3</strong>
  39. nav#collapse.collapse.navbar-collapse(role='navigation')
  40. ul.nav.navbar-nav
  41. li.dropdown
  42. a(href='#', data-toggle='dropdown')
  43. | Download
  44. span.caret
  45. ul.dropdown-menu
  46. li: a(href='https://github.com/nostalgiaz/bootstrap-switch/archive/master.zip') 3 (Stable)
  47. li: a(href='https://github.com/nostalgiaz/bootstrap-switch/archive/v2.0.1.zip') 2.0.1 (Legacy)
  48. li: a(href='#new') What's new
  49. li: a(href='#start') Start
  50. li.dropdown
  51. a(href='#', data-toggle='dropdown')
  52. | Documentation
  53. span.caret
  54. ul.dropdown-menu
  55. li.dropdown-header Version 3 (Stable)
  56. li: a(href='#options-3') Options
  57. li: a(href='#methods-3') Methods
  58. li: a(href='#events-3') Events
  59. li.divider
  60. li.dropdown-header Version 2.0.1 (Legacy)
  61. li: a(href='#options-2') Options
  62. li: a(href='#methods-2') Methods
  63. li: a(href='#events-2') Events
  64. li: a(href='https://github.com/nostalgiaz/bootstrap-switch/issues') Bug reports
  65. .container
  66. .header
  67. h2.title Bootstrap Switch <strong>3</strong> <span class="old-version">2.0.1</span>
  68. p.lead Turn checkboxes and radio buttons in toggle switches.
  69. p Select the version to download:
  70. p: input(type='checkbox', name='download-version', checked, data-size='large', data-on-text='3', data-off-text='2.0.1')
  71. p
  72. a(href='https://github.com/nostalgiaz/bootstrap-switch/archive/master.zip', id='download-3', class='btn btn-lg btn-primary') Download 3
  73. a(href='https://github.com/nostalgiaz/bootstrap-switch/archive/v2.0.1.zip', id='download-2' class='btn btn-lg btn-primary') Download 2.0.1
  74. br
  75. br
  76. iframe(src='http://ghbtns.com/github-btn.html?user=nostalgiaz&repo=bootstrap-switch&type=watch&count=true&size=large', allowtransparency='true', frameborder='0', scrolling='0', width='184', height='30')
  77. iframe(src='http://ghbtns.com/github-btn.html?user=nostalgiaz&repo=bootstrap-switch&type=fork&count=true&size=large', allowtransparency='true', frameborder='0', scrolling='0', width='144', height='30')
  78. br
  79. br
  80. br
  81. .alert.alert-info
  82. p
  83. | <strong>Documentation in progress!</strong><br>
  84. | It might not seem, but it's actually a lot of work. The goal is to make it as cleanest, most readable and
  85. | understandable as possible.<br>
  86. | If you feel there is something missing, submit a
  87. | <a href="https://github.com/nostalgiaz/bootstrap-switch/pulls">pull request</a> with your changes. Every
  88. | help is needed. Many thanks.
  89. #new
  90. h1.page-header What's new in version 3
  91. ul
  92. li API redesign for a more intuitive use
  93. li Entire code source rewriting focused on cleanliness and performance
  94. li Initialization options can be passed as JavaScript object or written as <code>data-*</code>
  95. li Plugin constructor publicly available from <code>$.fn.bootstrapSwitch.Constructor</code>
  96. li Plugin instance publicly available calling <code>.data('bootstrap-switch')</code>
  97. li Global overridable defaults options
  98. li Improved flexibility with <code>baseClass</code> and <code>wrapperClass</code> options
  99. li New <code>onInit</code> event
  100. li Event namespacing
  101. li Full Bootstrap 3 support
  102. li A lot of fixed bug, as usual
  103. #start
  104. h1.page-header Getting Started
  105. p Include the dependencies: jQuery, Bootstrap and Bootstrap Switch CSS + Javascript.
  106. pre: code
  107. | [...]
  108. | &lt;link href="bootstrap.css" rel="stylesheet"&gt;
  109. | &lt;link href="bootstrap-switch.css" rel="stylesheet"&gt;
  110. | &lt;script src="jquery.js"&gt;&lt;/script&gt;
  111. | &lt;script src="bootstrap-switch.js"&gt;&lt;/script&gt;
  112. | [...]
  113. p Add your checkbox.
  114. pre: code &lt;input type="checkbox" name="my-checkbox" checked&gt;
  115. p Initialize Bootstrap Switch.
  116. pre: code $("[name='my-checkbox']").bootstrapSwitch();
  117. p Enjoy.
  118. #documentation-3
  119. h1.page-header Documentation <small>Version 3 (Stable)</small>
  120. #options-3
  121. h2.page-header Options
  122. table.table.table-bordered.table-striped.table-responsive
  123. thead
  124. tr
  125. th Name
  126. th Attribute
  127. th Type
  128. th Description
  129. th Values
  130. th Default
  131. tbody
  132. tr
  133. td state
  134. td checked
  135. td Boolean
  136. td The checkbox state
  137. td true, false
  138. td true
  139. tr
  140. td size
  141. td data-size
  142. td String
  143. td The checkbox state
  144. td null, 'mini', 'small', 'normal', 'large'
  145. td null
  146. tr
  147. td animate
  148. td data-animate
  149. td Boolean
  150. td Animate the switch
  151. td true, false
  152. td true
  153. tr
  154. td disabled
  155. td disabled
  156. td Boolean
  157. td Disable state
  158. td true, false
  159. td false
  160. tr
  161. td readonly
  162. td readonly
  163. td Boolean
  164. td Readonly state
  165. td true, false
  166. td false
  167. tr
  168. td indeterminate
  169. td Boolean
  170. td indeterminate state
  171. td true, false
  172. td false
  173. tr
  174. td onColor
  175. td data-on-color
  176. td String
  177. td Color of the left side of the switch
  178. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  179. td 'primary'
  180. tr
  181. td offColor
  182. td data-off-color
  183. td String
  184. td Color of the right side of the switch
  185. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  186. td 'default'
  187. tr
  188. td onText
  189. td data-on-text
  190. td String
  191. td Text of the left side of the switch
  192. td String
  193. td 'ON'
  194. tr
  195. td offText
  196. td data-off-text
  197. td String
  198. td Text of the right side of the switch
  199. td String
  200. td 'OFF'
  201. tr
  202. td labelText
  203. td data-label-text
  204. td String
  205. td Text of the center handle of the switch
  206. td String
  207. td '&amp;nbsp;'
  208. tr
  209. td baseClass
  210. td data-base-class
  211. td String
  212. td Global class prefix
  213. td String
  214. td 'bootstrap-switch'
  215. tr
  216. td wrapperClass
  217. td data-wrapper-class
  218. td String | Array
  219. td Container element class(es)
  220. td String | Array
  221. td 'wrapper'
  222. tr
  223. td onInit
  224. td
  225. td Function
  226. td Callback function to execute on initialization
  227. td Function
  228. td: pre: code.javascript function(event, state) {}
  229. tr
  230. td onSwitchChange
  231. td
  232. td Function
  233. td Callback function to execute on switch state change
  234. td Function
  235. td: pre: code.javascript function(event, state) {}
  236. h3 Global Defaults Overriding
  237. p Follow the jQuery convention to override the default options of the library. For instance:
  238. pre
  239. code
  240. | $.fn.bootstrapSwitch.defaults.size = 'large';
  241. | $.fn.bootstrapSwitch.defaults.onColor = 'success';
  242. #methods-3
  243. h2.page-header Methods
  244. p In Bootstrap Switch, every option is also a method.
  245. p If the second parameter is omitted, the method return the current value.
  246. p You can invoke methods as follows:
  247. pre: code $('input[name="my-checkbox"]').bootstrapSwitch('state', true, true);
  248. h3 Additional Methods
  249. table.table.table-bordered.table-striped.table-responsive
  250. thead
  251. tr
  252. th Name
  253. th Description
  254. tbody
  255. tr
  256. td toggleState
  257. td Toggle the switch state
  258. tr
  259. td toggleDisabled
  260. td Toggle the disabled state
  261. tr
  262. td toggleReadonly
  263. td Toggle the readonly state
  264. tr
  265. td destroy
  266. td Destroy the instance of Bootstrap Switch
  267. h3 Special Behaviours
  268. ul
  269. li The method <code>state</code> can receive an optional third parameter <code>skip</code>. if true, <code>switchChange</code> event is not executed. The default is false.
  270. li The method <code>toggleState</code> can receive an optional second parameter <code>skip</code>. if true, <code>switchChange</code> event is not executed. The default is false.
  271. li The method <code>wrapperClass</code> can accepts a falsy value as second parameter. If so, it resets the class to its default.
  272. #events-3
  273. h2.page-header Events
  274. p
  275. | All the events are namespaced, therefore always append <code>.bootstrapSwitch</code> when you
  276. | attach your handlers.<br>
  277. | You can register to the emitted events as follow:
  278. pre: code
  279. | $('input[name="my-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) {
  280. | console.log(this); // DOM element
  281. | console.log(event); // jQuery event
  282. | console.log(state); // true | false
  283. | });
  284. table.table.table-bordered.table-striped.table-responsive
  285. thead
  286. tr
  287. th Name
  288. th Description
  289. th Parameters
  290. tbody
  291. tr
  292. td init
  293. td Triggered on initialization. 'this' refers to the DOM element.
  294. td
  295. | event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>)
  296. tr
  297. td switchChange
  298. td Triggered on switch state change. 'this' refers to the DOM element.
  299. td
  300. | event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>),
  301. | state (true | false)
  302. #examples-3
  303. h2.page-header Examples
  304. p To be included
  305. //
  306. h3 State
  307. .row
  308. .col-sm-6
  309. input(type='checkbox', id='state-switch' checked)
  310. .col-sm-6
  311. .btn-group.pull-right
  312. button(type='button', id='state-switch-state', class='btn btn-default') Get State
  313. &nbsp;
  314. button(type='button', id='state-switch-on', class='btn btn-default') Set On
  315. &nbsp;
  316. button(type='button', id='state-switch-off', class='btn btn-default') Set Off
  317. &nbsp;
  318. button(type='button', id='state-switch-toggle', class='btn btn-default') Toggle State
  319. #documentation-2
  320. h1.page-header Documentation <small>version 2.0.1 (Legacy)</small>
  321. #options-2
  322. h2.page-header Options
  323. .alert.alert-warning
  324. p
  325. | All the options are accepted only using <code>data-*</code> attributes on the element.<br>
  326. | <code>checked</code>, <code>disabled</code> and <code>readonly</code> are exception to the rule, being
  327. | default HTML input attributes.<br>
  328. | Therefore, there is not any way to specify the options in JavaScript during initialization.
  329. table.table.table-bordered.table-striped.table-responsive
  330. thead
  331. tr
  332. th Name
  333. th Type
  334. th Description
  335. th Values
  336. th Default
  337. tbody
  338. tr
  339. td state
  340. td Boolean
  341. td The checkbox state
  342. td true, false
  343. td 'checked' attribute or true
  344. tr
  345. td size
  346. td String
  347. td The checkbox state
  348. td '', 'mini', 'small', 'normal', 'large'
  349. td ''
  350. tr
  351. td animate
  352. td Boolean
  353. td Animate the switch
  354. td true, false
  355. td true
  356. tr
  357. td disabled
  358. td Boolean
  359. td Disable state
  360. td true, false
  361. td 'disabled' attribute or false
  362. tr
  363. td readonly
  364. td Boolean
  365. td Readonly state
  366. td true, false
  367. td 'readonly' attribute or false
  368. tr
  369. td on
  370. td String
  371. td Color of the left side of the switch
  372. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  373. td null
  374. tr
  375. td off
  376. td String
  377. td Color of the right side of the switch
  378. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  379. td null
  380. tr
  381. td on-label
  382. td String
  383. td Text of the left side of the switch
  384. td String
  385. td 'ON'
  386. tr
  387. td off-label
  388. td String
  389. td Text of the right side of the switch
  390. td String
  391. td 'OFF'
  392. tr
  393. td text-label
  394. td String
  395. td Text of the center handle of the switch
  396. td String
  397. td '&amp;nbsp;'
  398. tr
  399. td label-icon
  400. td String
  401. td Text of the center handle of the switch. Use to include external services icons
  402. td String
  403. td null
  404. #methods-2
  405. h2.page-header Methods
  406. table.table.table-bordered.table-striped.table-responsive
  407. thead
  408. tr
  409. th Name
  410. th Description
  411. th Accepted Values
  412. th Returned Values
  413. tbody
  414. tr
  415. td state
  416. td Get checkbox state
  417. td
  418. td true, false
  419. tr
  420. td setState
  421. td Set checkbox state
  422. td (value: true, false)[, skip: true, <strong>false</strong>]
  423. td jQuery Object (input element)
  424. tr
  425. td toggleState
  426. td Toggle checkbox state
  427. td [skip: true, <strong>false</strong>]
  428. td jQuery Object (input element)
  429. tr
  430. td toggleRadioState
  431. td Toggle radio state
  432. td [skip: true, <strong>false</strong>]
  433. td jQuery Object (input element)
  434. tr
  435. td toggleRadioStateAllowUncheck
  436. td Toggle radio state allowing uncheck of the radio input
  437. td [uncheck: true, <strong>false</strong> | skip: true, <strong>false</strong>]
  438. td jQuery Object (input element)
  439. tr
  440. td setSizeClass
  441. td Set the size of the switch
  442. td '', 'mini', 'small', 'normal', 'large'
  443. td jQuery Object (input element)
  444. tr
  445. td setAnimated
  446. td Animate the switch
  447. td true, false
  448. td jQuery Object (input element)
  449. tr
  450. td isDisabled
  451. td Get disabled state
  452. td
  453. td true, false
  454. tr
  455. td setDisabled
  456. td Set disable state
  457. td true, false
  458. td jQuery Object (input element)
  459. tr
  460. td toggleDisabled
  461. td Toggle disabled state
  462. td
  463. td jQuery Object (input element)
  464. tr
  465. td isReadOnly
  466. td Get Readonly state
  467. td
  468. td true, false
  469. tr
  470. td setReadOnly
  471. td Set Readonly state
  472. td true, false
  473. td jQuery Object (input element)
  474. tr
  475. td toggleReadOnly
  476. td Toggle readonly state
  477. td
  478. td jQuery Object (input element)
  479. tr
  480. td setOnClass
  481. td Color of the left side of the switch
  482. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  483. td jQuery Object (input element)
  484. tr
  485. td setOffClass
  486. td Color of the right side of the switch
  487. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  488. td jQuery Object (input element)
  489. tr
  490. td setOnLabel
  491. td Text of the left side of the switch
  492. td String
  493. td jQuery Object (input element)
  494. tr
  495. td setOffLabel
  496. td Text of the right side of the switch
  497. td String
  498. td jQuery Object (input element)
  499. tr
  500. td setTextLabel
  501. td Text of the center handle of the switch
  502. td String
  503. td null
  504. tr
  505. td setTextIcon
  506. td Text of the center handle of the switch. Use to include external services icons
  507. td String
  508. td null
  509. tr
  510. td destroy
  511. td Destroy the instance of Bootstrap Switch
  512. td
  513. td jQuery Object (input element)
  514. #events-2
  515. h2.page-header Events
  516. p
  517. | The only event triggered it <code>switch-change</code>. It returns two parameters: <code>event</code> and
  518. | <code>data</code>.<br>
  519. | The latter is an object that include <code>el</code> (the input DOM element) and <code>value</code> (the
  520. | new input state)
  521. script(src='docs/lib/js/jquery.min.js')
  522. script(src='docs/lib/js/bootstrap.min.js')
  523. script(src='docs/lib/js/highlight.js')
  524. script(src='dist/js/bootstrap-switch.js')
  525. script(src='docs/index.js')