index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. $(function() {
  2. // initialize all the inputs
  3. $('input[type="checkbox"],[type="radio"]').not('#create-switch').bootstrapSwitch();
  4. // dimension
  5. $('#btn-size-regular-switch').on('click', function () {
  6. $('#dimension-switch').bootstrapSwitch('setSizeClass', '');
  7. });
  8. $('#btn-size-mini-switch').on('click', function () {
  9. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-mini');
  10. });
  11. $('#btn-size-small-switch').on('click', function () {
  12. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-small');
  13. });
  14. $('#btn-size-large-switch').on('click', function () {
  15. $('#dimension-switch').bootstrapSwitch('setSizeClass', 'switch-large');
  16. });
  17. // state
  18. $('#toggle-state-switch-button').on('click', function () {
  19. $('#toggle-state-switch').bootstrapSwitch('toggleState');
  20. });
  21. $('#toggle-state-switch-button-on').on('click', function () {
  22. $('#toggle-state-switch').bootstrapSwitch('setState', true);
  23. });
  24. $('#toggle-state-switch-button-off').on('click', function () {
  25. $('#toggle-state-switch').bootstrapSwitch('setState', false);
  26. });
  27. $('#toggle-state-switch-button-state').on('click', function () {
  28. alert($('#toggle-state-switch').bootstrapSwitch('state'));
  29. });
  30. // destroy
  31. $('#btn-destroy-switch').on('click', function () {
  32. $('#destroy-switch').bootstrapSwitch('destroy');
  33. $(this).remove();
  34. });
  35. // CREATE
  36. $('#btn-create').on('click', function () {
  37. $('#create-switch').bootstrapSwitch();
  38. $(this).remove();
  39. });
  40. // activation
  41. var $disable = $('#disable-switch');
  42. $('#btn-disable-is').on('click', function () {
  43. alert($disable.bootstrapSwitch('isDisabled'));
  44. });
  45. $('#btn-disable-toggle').on('click', function () {
  46. $disable.bootstrapSwitch('toggleDisabled');
  47. });
  48. $('#btn-disable-set').on('click', function () {
  49. $disable.bootstrapSwitch('setDisabled', true);
  50. });
  51. $('#btn-disable-remove').on('click', function () {
  52. $disable.bootstrapSwitch('setDisabled', false);
  53. });
  54. // readonly
  55. var $readonly = $('#readonly-switch');
  56. $('#btn-readonly-is').on('click', function () {
  57. alert($readonly.bootstrapSwitch('isReadOnly'));
  58. });
  59. $('#btn-readonly-toggle').on('click', function () {
  60. $readonly.bootstrapSwitch('toggleReadOnly');
  61. });
  62. $('#btn-readonly-set').on('click', function () {
  63. $readonly.bootstrapSwitch('setReadOnly', true);
  64. });
  65. $('#btn-readonly-remove').on('click', function () {
  66. $readonly.bootstrapSwitch('setReadOnly', false);
  67. });
  68. // label
  69. $('#btn-label-on-switch').on('click', function() {
  70. $('#label-switch').bootstrapSwitch('setOnLabel', 'I');
  71. });
  72. $('#btn-label-off-switch').on('click', function() {
  73. $('#label-switch').bootstrapSwitch('setOffLabel', 'O');
  74. });
  75. $('#label-toggle-switch').on('click', function(e, data) {
  76. $('.label-toggle-switch').bootstrapSwitch('toggleState');
  77. });
  78. $('.label-toggle-switch').on('switch-change', function(e, data) {
  79. alert(data.value);
  80. });
  81. // event handler
  82. $('#switch-change').on('switch-change', function (e, data) {
  83. var $element = $(data.el),
  84. value = data.value;
  85. console.log(e, $element, value);
  86. });
  87. // color
  88. $('#btn-color-on-switch').on('click', function() {
  89. $('#change-color-switch').bootstrapSwitch('setOnClass', 'success');
  90. });
  91. $('#btn-color-off-switch').on('click', function() {
  92. $('#change-color-switch').bootstrapSwitch('setOffClass', 'danger');
  93. });
  94. // animation
  95. $('#btn-animate-switch').on('click', function() {
  96. $('#animated-switch').bootstrapSwitch('setAnimated', true);
  97. });
  98. $('#btn-dont-animate-switch').on('click', function() {
  99. $('#animated-switch').bootstrapSwitch('setAnimated', false);
  100. });
  101. // radio
  102. $('.radio1').on('switch-change', function () {
  103. $('.radio1').bootstrapSwitch('toggleRadioState');
  104. });
  105. $('.radio2').on('switch-change', function () {
  106. $('.radio2').bootstrapSwitch('toggleRadioStateAllowUncheck', true);
  107. });
  108. });