index.jade 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 Type
  127. th Description
  128. th Values
  129. th Default
  130. tbody
  131. tr
  132. td state
  133. td Boolean
  134. td The checkbox state
  135. td true, false
  136. td 'checked' attribute or true
  137. tr
  138. td size
  139. td String
  140. td The checkbox state
  141. td null, 'mini', 'small', 'normal', 'large'
  142. td null
  143. tr
  144. td animate
  145. td Boolean
  146. td Animate the switch
  147. td true, false
  148. td true
  149. tr
  150. td disabled
  151. td Boolean
  152. td Disable state
  153. td true, false
  154. td 'disabled' attribute or false
  155. tr
  156. td readonly
  157. td Boolean
  158. td Readonly state
  159. td true, false
  160. td 'readonly' attribute or false
  161. tr
  162. td indeterminate
  163. td Boolean
  164. td indeterminate state
  165. td true, false
  166. td false
  167. tr
  168. td onColor
  169. td String
  170. td Color of the left side of the switch
  171. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  172. td 'primary'
  173. tr
  174. td offColor
  175. td String
  176. td Color of the right side of the switch
  177. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  178. td 'default'
  179. tr
  180. td onText
  181. td String
  182. td Text of the left side of the switch
  183. td String
  184. td 'ON'
  185. tr
  186. td offText
  187. td String
  188. td Text of the right side of the switch
  189. td String
  190. td 'OFF'
  191. tr
  192. td labelText
  193. td String
  194. td Text of the center handle of the switch
  195. td String
  196. td '&amp;nbsp;'
  197. tr
  198. td baseClass
  199. td String
  200. td Global class prefix
  201. td String
  202. td 'bootstrap-switch'
  203. tr
  204. td wrapperClass
  205. td String | Array
  206. td Container element class(es)
  207. td String | Array
  208. td 'wrapper'
  209. tr
  210. td onInit
  211. td Function
  212. td Callback function to execute on initialization
  213. td Function
  214. td: pre: code.javascript function(event, state) {}
  215. tr
  216. td onSwitchChange
  217. td Function
  218. td Callback function to execute on switch state change
  219. td Function
  220. td: pre: code.javascript function(event, state) {}
  221. h3 Global Defaults Overriding
  222. p Follow the jQuery convention to override the default options of the library. For instance:
  223. pre
  224. code
  225. | $.fn.bootstrapSwitch.defaults.size = 'large';
  226. | $.fn.bootstrapSwitch.defaults.onColor = 'success';
  227. #methods-3
  228. h2.page-header Methods
  229. p In Bootstrap Switch, every option is also a method.
  230. p If the second parameter is omitted, the method return the current value.
  231. p You can invoke methods as follows:
  232. pre: code $('input[name="my-checkbox"]').bootstrapSwitch('state', true, true);
  233. h3 Additional Methods
  234. table.table.table-bordered.table-striped.table-responsive
  235. thead
  236. tr
  237. th Name
  238. th Description
  239. tbody
  240. tr
  241. td toggleState
  242. td Toggle the switch state
  243. tr
  244. td toggleDisabled
  245. td Toggle the disabled state
  246. tr
  247. td toggleReadonly
  248. td Toggle the readonly state
  249. tr
  250. td destroy
  251. td Destroy the instance of Bootstrap Switch
  252. h3 Special Behaviours
  253. ul
  254. 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.
  255. 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.
  256. li The method <code>wrapperClass</code> can accepts a falsy value as second parameter. If so, it resets the class to its default.
  257. #events-3
  258. h2.page-header Events
  259. p
  260. | All the events are namespaced, therefore always append <code>.bootstrapSwitch</code> when you
  261. | attach your handlers.<br>
  262. | You can register to the emitted events as follow:
  263. pre: code
  264. | $('input[name="my-checkbox"]').on('switchChange.bootstrapSwitch', function(event, state) {
  265. | console.log(this); // DOM element
  266. | console.log(event); // jQuery event
  267. | console.log(state); // true | false
  268. | });
  269. table.table.table-bordered.table-striped.table-responsive
  270. thead
  271. tr
  272. th Name
  273. th Description
  274. th Parameters
  275. tbody
  276. tr
  277. td init
  278. td Triggered on initialization. 'this' refers to the DOM element.
  279. td
  280. | event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>)
  281. tr
  282. td switchChange
  283. td Triggered on switch state change. 'this' refers to the DOM element.
  284. td
  285. | event (<a href="https://api.jquery.com/category/events/event-object/" target="_blank">jQuery Event object</a>),
  286. | state (true | false)
  287. #examples-3
  288. h2.page-header Examples
  289. p To be included
  290. //
  291. h3 State
  292. .row
  293. .col-sm-6
  294. input(type='checkbox', id='state-switch' checked)
  295. .col-sm-6
  296. .btn-group.pull-right
  297. button(type='button', id='state-switch-state', class='btn btn-default') Get State
  298. &nbsp;
  299. button(type='button', id='state-switch-on', class='btn btn-default') Set On
  300. &nbsp;
  301. button(type='button', id='state-switch-off', class='btn btn-default') Set Off
  302. &nbsp;
  303. button(type='button', id='state-switch-toggle', class='btn btn-default') Toggle State
  304. #documentation-2
  305. h1.page-header Documentation <small>version 2.0.1 (Legacy)</small>
  306. #options-2
  307. h2.page-header Options
  308. .alert.alert-warning
  309. p
  310. | All the options are accepted only using <code>data-*</code> attributes on the input element.<br>
  311. | The exceptions are <code>checked</code>, <code>disabled</code> and <code>readonly</code> which are
  312. | proprietary input attributes.<br>
  313. | There isn't any way to specify the options in JavaScript during initialization.
  314. table.table.table-bordered.table-striped.table-responsive
  315. thead
  316. tr
  317. th Name
  318. th Type
  319. th Description
  320. th Values
  321. th Default
  322. tbody
  323. tr
  324. td state
  325. td Boolean
  326. td The checkbox state
  327. td true, false
  328. td 'checked' attribute or true
  329. tr
  330. td size
  331. td String
  332. td The checkbox state
  333. td '', 'mini', 'small', 'normal', 'large'
  334. td ''
  335. tr
  336. td animate
  337. td Boolean
  338. td Animate the switch
  339. td true, false
  340. td true
  341. tr
  342. td disabled
  343. td Boolean
  344. td Disable state
  345. td true, false
  346. td 'disabled' attribute or false
  347. tr
  348. td readonly
  349. td Boolean
  350. td Readonly state
  351. td true, false
  352. td 'readonly' attribute or false
  353. tr
  354. td on
  355. td String
  356. td Color of the left side of the switch
  357. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  358. td null
  359. tr
  360. td off
  361. td String
  362. td Color of the right side of the switch
  363. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  364. td null
  365. tr
  366. td on-label
  367. td String
  368. td Text of the left side of the switch
  369. td String
  370. td 'ON'
  371. tr
  372. td off-label
  373. td String
  374. td Text of the right side of the switch
  375. td String
  376. td 'OFF'
  377. tr
  378. td text-label
  379. td String
  380. td Text of the center handle of the switch
  381. td String
  382. td '&amp;nbsp;'
  383. tr
  384. td label-icon
  385. td String
  386. td Text of the center handle of the switch. Use to include external services icons
  387. td String
  388. td null
  389. #methods-2
  390. h2.page-header Methods
  391. table.table.table-bordered.table-striped.table-responsive
  392. thead
  393. tr
  394. th Name
  395. th Description
  396. th Accepted Values
  397. th Returned Values
  398. tbody
  399. tr
  400. td state
  401. td Get checkbox state
  402. td
  403. td true, false
  404. tr
  405. td setState
  406. td Set checkbox state
  407. td (value: true, false)[, skip: true, <strong>false</strong>]
  408. td jQuery Object (input element)
  409. tr
  410. td toggleState
  411. td Toggle checkbox state
  412. td [skip: true, <strong>false</strong>]
  413. td jQuery Object (input element)
  414. tr
  415. td toggleRadioState
  416. td Toggle radio state
  417. td [skip: true, <strong>false</strong>]
  418. td jQuery Object (input element)
  419. tr
  420. td toggleRadioStateAllowUncheck
  421. td Toggle radio state allowing uncheck of the radio input
  422. td [uncheck: true, <strong>false</strong> | skip: true, <strong>false</strong>]
  423. td jQuery Object (input element)
  424. tr
  425. td setSizeClass
  426. td Set the size of the switch
  427. td '', 'mini', 'small', 'normal', 'large'
  428. td jQuery Object (input element)
  429. tr
  430. td setAnimated
  431. td Animate the switch
  432. td true, false
  433. td jQuery Object (input element)
  434. tr
  435. td isDisabled
  436. td Get disabled state
  437. td
  438. td true, false
  439. tr
  440. td setDisabled
  441. td Set disable state
  442. td true, false
  443. td jQuery Object (input element)
  444. tr
  445. td toggleDisabled
  446. td Toggle disabled state
  447. td
  448. td jQuery Object (input element)
  449. tr
  450. td isReadOnly
  451. td Get Readonly state
  452. td
  453. td true, false
  454. tr
  455. td setReadOnly
  456. td Set Readonly state
  457. td true, false
  458. td jQuery Object (input element)
  459. tr
  460. td toggleReadOnly
  461. td Toggle readonly state
  462. td
  463. td jQuery Object (input element)
  464. tr
  465. td setOnClass
  466. td Color of the left side of the switch
  467. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  468. td jQuery Object (input element)
  469. tr
  470. td setOffClass
  471. td Color of the right side of the switch
  472. td 'primary', 'info', 'success', 'warning', 'danger', 'default'
  473. td jQuery Object (input element)
  474. tr
  475. td setOnLabel
  476. td Text of the left side of the switch
  477. td String
  478. td jQuery Object (input element)
  479. tr
  480. td setOffLabel
  481. td Text of the right side of the switch
  482. td String
  483. td jQuery Object (input element)
  484. tr
  485. td setTextLabel
  486. td Text of the center handle of the switch
  487. td String
  488. td null
  489. tr
  490. td setTextIcon
  491. td Text of the center handle of the switch. Use to include external services icons
  492. td String
  493. td null
  494. tr
  495. td destroy
  496. td Destroy the instance of Bootstrap Switch
  497. td
  498. td jQuery Object (input element)
  499. #events-2
  500. h2.page-header Events
  501. p
  502. | The only event triggered it <code>switch-change</code>. It returns two parameters: <code>event</code> and
  503. | <code>data</code>.<br>
  504. | The latter is an object that include <code>el</code> (the input DOM element) and <code>value</code> (the
  505. | new input state)
  506. script(src='docs/lib/js/jquery.min.js')
  507. script(src='docs/lib/js/bootstrap.min.js')
  508. script(src='docs/lib/js/highlight.js')
  509. script(src='dist/js/bootstrap-switch.js')
  510. script(src='docs/index.js')