index.jade 20 KB

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