Browse Source

add active/disable function

Mattia Larentis 12 năm trước cách đây
mục cha
commit
aaf6329863

+ 3 - 0
README.md

@@ -96,6 +96,9 @@ Methods
 
 
 ``` javascript
 ``` javascript
 $('#mySwitch').bootstrapSwitch('toggleActivation');
 $('#mySwitch').bootstrapSwitch('toggleActivation');
+$('#mySwitch').bootstrapSwitch('isActive');
+$('#mySwitch').bootstrapSwitch('setActive', false);
+$('#mySwitch').bootstrapSwitch('setActive', true);
 $('#mySwitch').bootstrapSwitch('toggleState');
 $('#mySwitch').bootstrapSwitch('toggleState');
 $('#mySwitch').bootstrapSwitch('setState', true);
 $('#mySwitch').bootstrapSwitch('setState', true);
 $('#mySwitch').bootstrapSwitch('status');  // returns true or false
 $('#mySwitch').bootstrapSwitch('status');  // returns true or false

+ 25 - 1
examples/index.html

@@ -218,9 +218,18 @@ $('#destroy-switch').bootstrapSwitch('destroy');
         </div>
         </div>
         <br>
         <br>
         <br>
         <br>
+        <button id="btn-is-active-switch" class="btn">
+            Is active?
+        </button>
+        <button id="btn-toggle-activation-switch" class="btn">
+            Toggle activation!
+        </button>
         <button id="btn-disable-switch" class="btn">
         <button id="btn-disable-switch" class="btn">
             Disable!
             Disable!
         </button>
         </button>
+        <button id="btn-activate-switch" class="btn">
+            Activate!
+        </button>
     </div>
     </div>
     <div class="span8">
     <div class="span8">
 
 
@@ -231,7 +240,10 @@ $('#destroy-switch').bootstrapSwitch('destroy');
 &lt;/div></pre>
 &lt;/div></pre>
         <h4>Js:</h4>
         <h4>Js:</h4>
 <pre class="prettyprint linenums">
 <pre class="prettyprint linenums">
+$('#disable-switch').bootstrapSwitch('isActive');
 $('#disable-switch').bootstrapSwitch('toggleActivation');
 $('#disable-switch').bootstrapSwitch('toggleActivation');
+$('#disable-switch').bootstrapSwitch('setActive', false);
+$('#disable-switch').bootstrapSwitch('setActive', true);
 </pre>
 </pre>
     </div>
     </div>
 </div>
 </div>
@@ -313,9 +325,21 @@ $('#disable-switch').bootstrapSwitch('toggleActivation');
         $(this).remove();
         $(this).remove();
     });
     });
 
 
-    $('#btn-disable-switch').on('click', function () {
+    $('#btn-is-active-switch').on('click', function () {
+        alert($('#disable-switch').bootstrapSwitch('isActive'));
+    });
+
+    $('#btn-toggle-activation-switch').on('click', function () {
         $('#disable-switch').bootstrapSwitch('toggleActivation');
         $('#disable-switch').bootstrapSwitch('toggleActivation');
     });
     });
+
+    $('#btn-disable-switch').on('click', function () {
+        $('#disable-switch').bootstrapSwitch('setActive', false);
+    });
+
+    $('#btn-activate-switch').on('click', function () {
+        $('#disable-switch').bootstrapSwitch('setActive', true);
+    });
 </script>
 </script>
 </body>
 </body>
 </html>
 </html>

+ 9 - 1
static/js/bootstrapSwitch.js

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.0 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.1 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0
@@ -179,6 +179,14 @@
       toggleActivation:function () {
       toggleActivation:function () {
         $(this).toggleClass('deactivate');
         $(this).toggleClass('deactivate');
       },
       },
+      isActive : function() {
+        return !$(this).hasClass('deactivate');
+      },
+      setActive: function (active) {
+        if(active)
+          $(this).removeClass('deactivate');
+        else $(this).addClass('deactivate');
+      },
       toggleState:function (skipOnChange) {
       toggleState:function (skipOnChange) {
         var $input = $(this).find('input:checkbox');
         var $input = $(this).find('input:checkbox');
         $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
         $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);

+ 1 - 1
static/sass/bootstrapSwitch.scss

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.0 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.1 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0

+ 1 - 1
static/stylesheets/bootstrapSwitch.css

@@ -1,5 +1,5 @@
 /* ============================================================
 /* ============================================================
- * bootstrapSwitch v1.0 by Larentis Mattia @spiritualGuru
+ * bootstrapSwitch v1.1 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
  * http://www.larentis.eu/switch/
  * ============================================================
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * Licensed under the Apache License, Version 2.0