Quellcode durchsuchen

prevent propagation on sides click, set the correct state after drag from indeterminate state #403

Emanuele Marchi vor 10 Jahren
Ursprung
Commit
44a59425cf

+ 8 - 5
dist/js/bootstrap-switch.js

@@ -145,10 +145,8 @@
         }
         if (this.options.indeterminate) {
           this.indeterminate(false);
-          value = true;
-        } else {
-          value = !!value;
         }
+        value = !!value;
         this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
         return this.$element;
       };
@@ -176,6 +174,7 @@
           this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
         }
         this._width();
+        this._containerPosition();
         this.options.size = value;
         return this.$element;
       };
@@ -532,13 +531,17 @@
 
       BootstrapSwitch.prototype._handleHandlers = function() {
         this.$on.on("click.bootstrapSwitch", (function(_this) {
-          return function(e) {
+          return function(event) {
+            event.preventDefault();
+            event.stopPropagation();
             _this.state(false);
             return _this.$element.trigger("focus.bootstrapSwitch");
           };
         })(this));
         return this.$off.on("click.bootstrapSwitch", (function(_this) {
-          return function(e) {
+          return function(event) {
+            event.preventDefault();
+            event.stopPropagation();
             _this.state(true);
             return _this.$element.trigger("focus.bootstrapSwitch");
           };

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 0
dist/js/bootstrap-switch.min.js


+ 2 - 2
package.json

@@ -64,8 +64,8 @@
   "npmFileMap": [{
     "basePath": "/dist/",
     "files": [
-      "*.js"
-      "bootstrap3/*.css"
+      "*.js",
+      "bootstrap3/*.css",
       "bootstrap2/*.css"
     ]
   }]

+ 12 - 7
src/coffee/bootstrap-switch.coffee

@@ -89,11 +89,9 @@ do ($ = window.jQuery, window) ->
       return @$element  if @options.disabled or @options.readonly
       return @$element  if @options.state and not @options.radioAllOff and @$element.is ":radio"
 
-      if @options.indeterminate
-        @indeterminate false
-        value = true
-      else
-        value = not not value
+      # remove indeterminate
+      @indeterminate false  if @options.indeterminate
+      value = not not value
 
       @$element.prop("checked", value).trigger "change.bootstrapSwitch", skip
       @$element
@@ -113,6 +111,7 @@ do ($ = window.jQuery, window) ->
       @$wrapper.removeClass "#{@options.baseClass}-#{@options.size}" if @options.size?
       @$wrapper.addClass "#{@options.baseClass}-#{value}" if value
       @_width()
+      @_containerPosition()
       @options.size = value
       @$element
 
@@ -396,11 +395,17 @@ do ($ = window.jQuery, window) ->
               @state true
 
     _handleHandlers: ->
-      @$on.on "click.bootstrapSwitch", (e) =>
+      @$on.on "click.bootstrapSwitch", (event) =>
+        event.preventDefault()
+        event.stopPropagation()
+
         @state false
         @$element.trigger "focus.bootstrapSwitch"
 
-      @$off.on "click.bootstrapSwitch", (e) =>
+      @$off.on "click.bootstrapSwitch", (event) =>
+        event.preventDefault()
+        event.stopPropagation()
+
         @state true
         @$element.trigger "focus.bootstrapSwitch"
 

+ 8 - 5
test/bootstrap-switch.js

@@ -145,10 +145,8 @@
         }
         if (this.options.indeterminate) {
           this.indeterminate(false);
-          value = true;
-        } else {
-          value = !!value;
         }
+        value = !!value;
         this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
         return this.$element;
       };
@@ -176,6 +174,7 @@
           this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
         }
         this._width();
+        this._containerPosition();
         this.options.size = value;
         return this.$element;
       };
@@ -532,13 +531,17 @@
 
       BootstrapSwitch.prototype._handleHandlers = function() {
         this.$on.on("click.bootstrapSwitch", (function(_this) {
-          return function(e) {
+          return function(event) {
+            event.preventDefault();
+            event.stopPropagation();
             _this.state(false);
             return _this.$element.trigger("focus.bootstrapSwitch");
           };
         })(this));
         return this.$off.on("click.bootstrapSwitch", (function(_this) {
-          return function(e) {
+          return function(event) {
+            event.preventDefault();
+            event.stopPropagation();
             _this.state(true);
             return _this.$element.trigger("focus.bootstrapSwitch");
           };

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.