瀏覽代碼

fixed uncheck error

Fixed uncheck error:
if site is loading and no radio is clicked/changed the checked radio can unchecked. With the fix this problem is solved now.

Clean up Methods: toggleRadioState & toggleRadioStateAllowUncheck
Stein, Peter 12 年之前
父節點
當前提交
05a6382fcd
共有 1 個文件被更改,包括 3 次插入11 次删除
  1. 3 11
      static/js/bootstrap-switch.js

+ 3 - 11
static/js/bootstrap-switch.js

@@ -151,7 +151,7 @@
 
               if ($this.closest('.has-switch').is('.deactivate')) {
                 $this.unbind('click');
-              } else if ($this.closest('.has-switch').is('.radio-no-uncheck')) {
+              } else if ( $this.closest('.switch-on').parent().is('.radio-no-uncheck') ) {
                 $this.unbind('click');
               } else {
                 $this.on('mousemove touchmove', function (e) {
@@ -253,23 +253,15 @@
         $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
       },
       toggleRadioState: function (skipOnChange) {
-        var $this = $(this)
-          , $radioinput = $this.find(':radio');
-          if ($radioinput.is(':checked'))
-          $radioinput.closest('.switch-on').parent().addClass('radio-no-uncheck');
-
+        var $radioinput = $(this).find(':radio');
           $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
       },
       toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
-        var $this = $(this)
-          , $radioinput = $this.find(':radio');
+        var $radioinput = $(this).find(':radio');
         if (uncheck) {
           $radioinput.not(':checked').trigger('change', skipOnChange);
         }
         else {
-          if ($radioinput.is(':checked'))
-          $radioinput.closest('.switch-on').parent().addClass('radio-no-uncheck');
-
           $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
         }
       },