Преглед на файлове

Update to V1.3.1

Update to V1.3.1
BdMdesigN преди 12 години
родител
ревизия
fbfe7d2a55
променени са 1 файла, в които са добавени 26 реда и са изтрити 20 реда
  1. 26 20
      static/js/bootstrapSwitch.js

+ 26 - 20
static/js/bootstrapSwitch.js

@@ -1,11 +1,16 @@
 /* ============================================================
  * bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
  * http://www.larentis.eu/switch/
+ * 
+ * bootstrapSwitch v1.3.1 by Stein, Peter @BdMdesigN
+ * 
+ * enhanced by BdMdesigN
+ * http://www.bdmdesign.org
  * ============================================================
  * Licensed under the Apache License, Version 2.0
  * http://www.apache.org/licenses/LICENSE-2.0
  * ============================================================ */
-
+ 
 !function ($) {
   "use strict";
 
@@ -70,7 +75,7 @@
               $label.html('<i class="icon icon-' + icon + '"></i>');
             }
 
-            $div = $element.find(':checkbox').wrap($('<div>')).parent().data('animated', false);
+            $div = $element.find('input[type=radio],input[type=checkbox]').wrap($('<div>')).parent().data('animated', false);
 
             if ($element.data('animated') !== false)
               $div.addClass('switch-animate').data('animated', true);
@@ -81,10 +86,10 @@
               .append($switchRight);
 
             $element.find('>div').addClass(
-              $element.find('input').is(':checked') ? 'switch-on' : 'switch-off'
+              $element.find('input[type=radio],input[type=checkbox]').is(':checked') ? 'switch-on' : 'switch-off'
             );
 
-            if ($element.find('input').is(':disabled'))
+            if ($element.find('input[type=radio],input[type=checkbox]').is(':disabled'))
               $(this).addClass('deactivate');
 
             var changeStatus = function ($this) {
@@ -107,7 +112,7 @@
               changeStatus($(this));
             });
 
-            $element.find('input').on('change', function (e, skipOnChange) {
+            $element.find('input[type=radio],input[type=checkbox]').on('change', function (e, skipOnChange) {
               var $this = $(this)
                 , $element = $this.parent()
                 , thisState = $this.is(':checked')
@@ -165,7 +170,7 @@
                 $this.on('click touchend', function (e) {
                   var $this = $(this)
                     , $target = $(e.target)
-                    , $myCheckBox = $target.siblings('input');
+                    , $myRadioCheckBox = $target.siblings('input[type=radio],input[type=checkbox]');
 
                   e.stopImmediatePropagation();
                   e.preventDefault();
@@ -173,16 +178,17 @@
                   $this.unbind('mouseleave');
 
                   if (moving)
-                    $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
-                  else $myCheckBox.prop("checked", !$myCheckBox.is(":checked"));
+                    $myRadioCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
+                  else
+                    $myRadioCheckBox.prop("checked", !$myRadioCheckBox.is(":checked"));
 
                   moving = false;
-                  $myCheckBox.trigger('change');
+                  $myRadioCheckBox.trigger('change');
                 });
 
                 $this.on('mouseleave', function (e) {
                   var $this = $(this)
-                    , $myCheckBox = $this.siblings('input');
+                    , $myInputBox = $this.siblings('input[type=radio],input[type=checkbox]');
 
                   e.preventDefault();
                   e.stopImmediatePropagation();
@@ -190,7 +196,7 @@
                   $this.unbind('mouseleave');
                   $this.trigger('mouseup');
 
-                  $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
+                  $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
                 });
 
                 $this.on('mouseup', function (e) {
@@ -216,27 +222,27 @@
         else $(this).addClass('deactivate');
       },
       toggleState: function (skipOnChange) {
-        var $input = $(this).find('input:checkbox');
+        var $input = $(this).find('input[type=radio],input[type=checkbox]');
         $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
       },
       setState: function (value, skipOnChange) {
-        $(this).find('input:checkbox').prop('checked', value).trigger('change', skipOnChange);
+        $(this).find('input[type=radio],input[type=checkbox]').prop('checked', value).trigger('change', skipOnChange);
       },
       status: function () {
-        return $(this).find('input:checkbox').is(':checked');
+        return $(this).find('input[type=radio],input[type=checkbox]').is(':checked');
       },
       destroy: function () {
         var $div = $(this).find('div')
-          , $checkbox;
+          , $inputbox;
 
-        $div.find(':not(input:checkbox)').remove();
+        $div.find(':not(input:radio),:not(input:checkbox').remove();
 
-        $checkbox = $div.children();
-        $checkbox.unwrap().unwrap();
+        $inputbox = $div.children();
+        $inputbox.unwrap().unwrap();
 
-        $checkbox.unbind('change');
+        $inputbox.unbind('change');
 
-        return $checkbox;
+        return $inputbox;
       }
     };