소스 검색

Update to v1.6 and fixed uncheck error

Update to v1.6.
Fixed the "toggleRadioState" uncheck error
Add new function: "toggleRadioStateAllowUncheck"
Function "setActive": change "prop" back to "attr"
Stein, Peter 11 년 전
부모
커밋
e2f097c571
1개의 변경된 파일18개의 추가작업 그리고 6개의 파일을 삭제
  1. 18 6
      static/js/bootstrap-switch.js

+ 18 - 6
static/js/bootstrap-switch.js

@@ -1,5 +1,5 @@
 /* ============================================================
- * bootstrapSwitch v1.5 by Larentis Mattia @SpiritualGuru
+ * bootstrapSwitch v1.6 by Larentis Mattia @SpiritualGuru
  * http://www.larentis.eu/
  * 
  * Enhanced for radiobuttons by Stein, Peter @BdMdesigN
@@ -151,7 +151,9 @@
 
               if ($this.closest('.has-switch').is('.deactivate'))
                 $this.unbind('click');
-              else {
+              } else if ( $this.closest('.switch-on').parent().is('.radio-no-uncheck') ) {
+                $this.unbind('click');
+              } else {
                 $this.on('mousemove touchmove', function (e) {
                   var $element = $(this).closest('.switch')
                     , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
@@ -239,19 +241,29 @@
 
         if (active) {
           $this.removeClass('deactivate');
-          $this.find('input').prop('disabled', false);
+          $this.find('input').removeAttr('disabled');
         }
         else {
           $this.addClass('deactivate');
-          $this.find('input').prop('disabled', true);
+          $this.find('input').attr('disabled', 'disabled');
         }
       },
       toggleState: function (skipOnChange) {
-        var $input = $(this).find('input[type=checkbox]');
+        var $input = $(this).find(':checkbox');
         $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
       },
       toggleRadioState: function (skipOnChange) {
-        $(this).find('input[type=radio]').not(':checked').trigger('change', skipOnChange);
+        var $radioinput = $(this).find(':radio');
+          $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
+      },
+      toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
+        var $radioinput = $(this).find(':radio');
+        if (uncheck) {
+          $radioinput.not(':checked').trigger('change', skipOnChange);
+        }
+        else {
+          $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
+        }
       },
       setState: function (value, skipOnChange) {
         $(this).find('input').prop('checked', value).trigger('change', skipOnChange);