Bläddra i källkod

fix deactivate issue, thanks @5im0n

Mattia Larentis 12 år sedan
förälder
incheckning
cb14b60334
2 ändrade filer med 16 tillägg och 5 borttagningar
  1. 2 1
      examples/index.html
  2. 14 4
      static/js/bootstrap-switch.js

+ 2 - 1
examples/index.html

@@ -278,8 +278,9 @@ $('#create-switch').wrap('<div class="switch" />').parent().bootstrapSwitch()
         <h3>Disabled <small>javascript</small></h3>
 
         <div class="bs-docs-example">
+            <label for="disable-switch-input">amazing label</label>
             <div id="disable-switch" class="switch">
-                <input type="checkbox" checked />
+                <input id="disable-switch-input" type="checkbox" checked />
             </div>
             <br>
             <br>

+ 14 - 4
static/js/bootstrap-switch.js

@@ -205,15 +205,25 @@
         );
       },
       toggleActivation: function () {
-        $(this).toggleClass('deactivate');
+        var $this = $(this);
+
+        $this.toggleClass('deactivate');
+        $this.find('input:checkbox').attr('disabled', $this.is('.deactivate'));
       },
       isActive: function () {
         return !$(this).hasClass('deactivate');
       },
       setActive: function (active) {
-        if (active)
-          $(this).removeClass('deactivate');
-        else $(this).addClass('deactivate');
+        var $this = $(this);
+
+        if (active) {
+          $this.removeClass('deactivate');
+          $this.find('input:checkbox').attr('disabled', false);
+        }
+        else {
+          $this.addClass('deactivate');
+          $this.find('input:checkbox').attr('disabled', true);
+        }
       },
       toggleState: function (skipOnChange) {
         var $input = $(this).find('input:checkbox');