Skip to content

Commit

Permalink
version bump to v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelvanrijn committed Aug 22, 2014
1 parent dcf4be6 commit 5b16f4a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ See the [demo page of Mattia Larentis](http://www.bootstrap-switch.org/) for exa

| Version | Notes |
| -------:| ----------------------------------------------------------------------------------- |
| 3.0.2 | Update to v3.0.2 of the bootstrap-switch plugin |
| 3.0.0 | Update to v3.0.0 of the bootstrap-switch plugin |
| 2.0.2 | Fixed issue where bootstrap 2 sass wasn't compiling (issue #7) |
| 2.0.1 | Update to v2.0.1 of the bootstrap-switch plugin |
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap-switch-rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Bootstrap
module Switch
module Rails
VERSION = "3.0.0"
VERSION = "3.0.2"
end
end
end
127 changes: 90 additions & 37 deletions vendor/assets/javascripts/bootstrap-switch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ========================================================================
* bootstrap-switch - v3.0.0
* bootstrap-switch - v3.0.2
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
Expand All @@ -26,27 +26,27 @@
"use strict";
var BootstrapSwitch;
BootstrapSwitch = (function() {
BootstrapSwitch.prototype.name = "bootstrap-switch";

function BootstrapSwitch(element, options) {
if (options == null) {
options = {};
}
this.$element = $(element);
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, options, {
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
state: this.$element.is(":checked"),
size: this.$element.data("size"),
animate: this.$element.data("animate"),
disabled: this.$element.is(":disabled"),
readonly: this.$element.is("[readonly]"),
indeterminate: this.$element.data("indeterminate"),
onColor: this.$element.data("on-color"),
offColor: this.$element.data("off-color"),
onText: this.$element.data("on-text"),
offText: this.$element.data("off-text"),
labelText: this.$element.data("label-text"),
baseClass: this.$element.data("base-class"),
wrapperClass: this.$element.data("wrapper-class")
});
wrapperClass: this.$element.data("wrapper-class"),
radioAllOff: this.$element.data("radio-all-off")
}, options);
this.$wrapper = $("<div>", {
"class": (function(_this) {
return function() {
Expand All @@ -65,6 +65,9 @@
if (_this.options.readonly) {
classes.push("" + _this.options.baseClass + "-readonly");
}
if (_this.options.indeterminate) {
classes.push("" + _this.options.baseClass + "-indeterminate");
}
if (_this.$element.attr("id")) {
classes.push("" + _this.options.baseClass + "-id-" + (_this.$element.attr("id")));
}
Expand All @@ -84,10 +87,12 @@
"class": "" + this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
});
this.$label = $("<label>", {
"for": this.$element.attr("id"),
html: this.options.labelText,
"class": "" + this.options.baseClass + "-label"
});
if (this.options.indeterminate) {
this.$element.prop("indeterminate", true);
}
this.$element.on("init.bootstrapSwitch", (function(_this) {
return function() {
return _this.options.onInit.apply(element, arguments);
Expand All @@ -113,7 +118,10 @@
if (typeof value === "undefined") {
return this.options.state;
}
if (this.options.disabled || this.options.readonly) {
if (this.options.disabled || this.options.readonly || this.options.indeterminate) {
return this.$element;
}
if (this.options.state && !this.options.radioAllOff && this.$element.is(':radio')) {
return this.$element;
}
value = !!value;
Expand All @@ -122,7 +130,7 @@
};

BootstrapSwitch.prototype.toggleState = function(skip) {
if (this.options.disabled || this.options.readonly) {
if (this.options.disabled || this.options.readonly || this.options.indeterminate) {
return this.$element;
}
return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
Expand Down Expand Up @@ -188,6 +196,24 @@
return this.$element;
};

BootstrapSwitch.prototype.indeterminate = function(value) {
if (typeof value === "undefined") {
return this.options.indeterminate;
}
value = !!value;
this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-indeterminate");
this.$element.prop("indeterminate", value);
this.options.indeterminate = value;
return this.$element;
};

BootstrapSwitch.prototype.toggleIndeterminate = function() {
this.$element.prop("indeterminate", !this.options.indeterminate);
this.$wrapper.toggleClass("" + this.options.baseClass + "-indeterminate");
this.options.indeterminate = !this.options.indeterminate;
return this.$element;
};

BootstrapSwitch.prototype.onColor = function(value) {
var color;
color = this.options.onColor;
Expand Down Expand Up @@ -260,6 +286,36 @@
return this.$element;
};

BootstrapSwitch.prototype.radioAllOff = function(value) {
if (typeof value === "undefined") {
return this.options.radioAllOff;
}
this.options.radioAllOff = value;
return this.$element;
};

BootstrapSwitch.prototype.onInit = function(value) {
if (typeof value === "undefined") {
return this.options.onInit;
}
if (!value) {
value = $.fn.bootstrapSwitch.defaults.onInit;
}
this.options.onInit = value;
return this.$element;
};

BootstrapSwitch.prototype.onSwitchChange = function(value) {
if (typeof value === "undefined") {
return this.options.onSwitchChange;
}
if (!value) {
value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
}
this.options.onSwitchChange = value;
return this.$element;
};

BootstrapSwitch.prototype.destroy = function() {
var $form;
$form = this.$element.closest("form");
Expand All @@ -277,7 +333,6 @@
return function(e, skip) {
var checked;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
checked = _this.$element.is(":checked");
if (checked === _this.options.state) {
Expand All @@ -296,38 +351,27 @@
"focus.bootstrapSwitch": (function(_this) {
return function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
};
})(this),
"blur.bootstrapSwitch": (function(_this) {
return function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
};
})(this),
"keydown.bootstrapSwitch": (function(_this) {
return function(e) {
if (!e.which || _this.options.disabled || _this.options.readonly) {
if (!e.which || _this.options.disabled || _this.options.readonly || _this.options.indeterminate) {
return;
}
switch (e.which) {
case 32:
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return _this.toggleState();
case 37:
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return _this.state(false);
case 39:
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
return _this.state(true);
}
Expand Down Expand Up @@ -355,14 +399,19 @@
return this.$label.on({
"mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
return function(e) {
var left, percent, right;
if (!_this.drag) {
var left, pageX, percent, right;
if (!_this.isLabelDragging) {
return;
}
e.preventDefault();
percent = (((e.pageX || e.originalEvent.touches[0].pageX) - _this.$wrapper.offset().left) / _this.$wrapper.width()) * 100;
_this.isLabelDragged = true;
pageX = e.pageX || e.originalEvent.touches[0].pageX;
percent = ((pageX - _this.$wrapper.offset().left) / _this.$wrapper.width()) * 100;
left = 25;
right = 75;
if (_this.options.animate) {
_this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
}
if (percent < left) {
percent = left;
} else if (percent > right) {
Expand All @@ -374,29 +423,31 @@
})(this),
"mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
return function(e) {
if (_this.drag || _this.options.disabled || _this.options.readonly) {
if (_this.isLabelDragging || _this.options.disabled || _this.options.readonly || _this.options.indeterminate) {
return;
}
e.preventDefault();
_this.drag = true;
if (_this.options.animate) {
_this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
}
_this.isLabelDragging = true;
return _this.$element.trigger("focus.bootstrapSwitch");
};
})(this),
"mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
return function(e) {
if (!_this.drag) {
if (!_this.isLabelDragging) {
return;
}
e.preventDefault();
_this.drag = false;
_this.$element.prop("checked", parseInt(_this.$container.css("margin-left"), 10) > -(_this.$container.width() / 6)).trigger("change.bootstrapSwitch");
_this.$container.css("margin-left", "");
if (_this.options.animate) {
return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
if (_this.isLabelDragged) {
_this.isLabelDragged = false;
_this.state(parseInt(_this.$container.css("margin-left"), 10) > -(_this.$container.width() / 6));
if (_this.options.animate) {
_this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
}
_this.$container.css("margin-left", "");
} else {
_this.state(!_this.options.state);
}
return _this.isLabelDragging = false;
};
})(this),
"mouseleave.bootstrapSwitch": (function(_this) {
Expand All @@ -418,7 +469,7 @@
return $form.find("input").filter(function() {
return $(this).data("bootstrap-switch");
}).each(function() {
return $(this).bootstrapSwitch("state", false);
return $(this).bootstrapSwitch("state", this.checked);
});
}, 1);
}).data("bootstrap-switch", true);
Expand Down Expand Up @@ -464,13 +515,15 @@
animate: true,
disabled: false,
readonly: false,
indeterminate: false,
onColor: "primary",
offColor: "default",
onText: "ON",
offText: "OFF",
labelText: "&nbsp;",
baseClass: "bootstrap-switch",
wrapperClass: "wrapper",
radioAllOff: false,
onInit: function() {},
onSwitchChange: function() {}
};
Expand Down
17 changes: 14 additions & 3 deletions vendor/assets/stylesheets/bootstrap2-switch.css.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ========================================================================
* bootstrap-switch - v3.0.0
* bootstrap-switch - v3.0.2
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
Expand Down Expand Up @@ -131,18 +131,25 @@
-moz-border-radius-bottomleft: 4px;
border-bottom-left-radius: 4px;
}
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-container {
margin-left: -25%;
}
.bootstrap-switch.bootstrap-switch-disabled,
.bootstrap-switch.bootstrap-switch-readonly {
.bootstrap-switch.bootstrap-switch-readonly,
.bootstrap-switch.bootstrap-switch-indeterminate {
opacity: 0.5;
filter: alpha(opacity=50);
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label {
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-label {
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-focused {
Expand Down Expand Up @@ -488,3 +495,7 @@
filter: alpha(opacity=0);
z-index: -1;
}
.bootstrap-switch input[type='radio'].form-control,
.bootstrap-switch input[type='checkbox'].form-control {
height: auto;
}
17 changes: 14 additions & 3 deletions vendor/assets/stylesheets/bootstrap3-switch.css.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ========================================================================
* bootstrap-switch - v3.0.0
* bootstrap-switch - v3.0.2
* http://www.bootstrap-switch.org
* ========================================================================
* Copyright 2012-2013 Mattia Larentis
Expand Down Expand Up @@ -89,18 +89,25 @@
border-bottom-left-radius: 3px;
border-top-left-radius: 3px;
}
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-container {
margin-left: -25%;
}
.bootstrap-switch.bootstrap-switch-disabled,
.bootstrap-switch.bootstrap-switch-readonly {
.bootstrap-switch.bootstrap-switch-readonly,
.bootstrap-switch.bootstrap-switch-indeterminate {
opacity: 0.5;
filter: alpha(opacity=50);
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-on,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-off,
.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label {
.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label,
.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-label {
cursor: default !important;
}
.bootstrap-switch.bootstrap-switch-focused {
Expand Down Expand Up @@ -193,3 +200,7 @@
filter: alpha(opacity=0);
z-index: -1;
}
.bootstrap-switch input[type='radio'].form-control,
.bootstrap-switch input[type='checkbox'].form-control {
height: auto;
}

0 comments on commit 5b16f4a

Please sign in to comment.