Skip to content

Commit

Permalink
prevent propagation on sides click, set the correct state after drag …
Browse files Browse the repository at this point in the history
…from indeterminate state #403
  • Loading branch information
Emanuele Marchi committed Dec 17, 2014
1 parent 645a69a commit 44a5942
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
13 changes: 8 additions & 5 deletions dist/js/bootstrap-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -176,6 +174,7 @@
this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
}
this._width();
this._containerPosition();
this.options.size = value;
return this.$element;
};
Expand Down Expand Up @@ -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");
};
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap-switch.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
"npmFileMap": [{
"basePath": "/dist/",
"files": [
"*.js"
"bootstrap3/*.css"
"*.js",
"bootstrap3/*.css",
"bootstrap2/*.css"
]
}]
Expand Down
19 changes: 12 additions & 7 deletions src/coffee/bootstrap-switch.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"

Expand Down
13 changes: 8 additions & 5 deletions test/bootstrap-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -176,6 +174,7 @@
this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
}
this._width();
this._containerPosition();
this.options.size = value;
return this.$element;
};
Expand Down Expand Up @@ -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");
};
Expand Down

0 comments on commit 44a5942

Please sign in to comment.