|
@@ -1,7 +1,7 @@
|
|
|
/**
|
|
|
* bootstrap-switch - Turn checkboxes and radio buttons into toggle switches.
|
|
|
*
|
|
|
- * @version v3.3.5
|
|
|
+ * @version v3.4.0
|
|
|
* @homepage https://bttstrp.github.io/bootstrap-switch
|
|
|
* @author Mattia Larentis <[email protected]> (http://larentis.eu)
|
|
|
* @license MIT
|
|
@@ -79,11 +79,12 @@
|
|
|
inverse = options.inverse;
|
|
|
|
|
|
return [state ? 'on' : 'off', size, disabled ? 'disabled' : undefined, readonly ? 'readonly' : undefined, indeterminate ? 'indeterminate' : undefined, inverse ? 'inverse' : undefined, id ? 'id-' + id : undefined].filter(function (v) {
|
|
|
- return v == null;
|
|
|
+ return v !== undefined;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function prvgetElementOptions() {
|
|
|
+ var valueType = ['text', 'on-off', 'boolean'];
|
|
|
return {
|
|
|
state: this.$element.is(':checked'),
|
|
|
size: this.$element.data('size'),
|
|
@@ -101,7 +102,10 @@
|
|
|
handleWidth: this.$element.data('handle-width'),
|
|
|
labelWidth: this.$element.data('label-width'),
|
|
|
baseClass: this.$element.data('base-class'),
|
|
|
- wrapperClass: this.$element.data('wrapper-class')
|
|
|
+ wrapperClass: this.$element.data('wrapper-class'),
|
|
|
+ hookElement: null,
|
|
|
+ hookNext: this.$element.data('hook-next') === 'true',
|
|
|
+ valueType: valueType.indexOf(this.$element.data('value-type')) >= 0 ? this.$element.data('value-type') : 'on-off'
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -129,7 +133,7 @@
|
|
|
function prvcontainerPosition() {
|
|
|
var _this2 = this;
|
|
|
|
|
|
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.ope;
|
|
|
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.state;
|
|
|
|
|
|
this.$container.css('margin-left', function () {
|
|
|
var values = [0, '-' + _this2.privateHandleWidth + 'px'];
|
|
@@ -345,7 +349,7 @@
|
|
|
function prvgetClasses(classes) {
|
|
|
var _this8 = this;
|
|
|
|
|
|
- if (!$.isArray(classes)) {
|
|
|
+ if (!Array.isArray(classes)) {
|
|
|
return [prvgetClass.call(this, classes)];
|
|
|
}
|
|
|
return classes.map(function (v) {
|
|
@@ -364,6 +368,10 @@
|
|
|
this.$element = $(element);
|
|
|
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, prvgetElementOptions.call(this), options);
|
|
|
this.prevOptions = {};
|
|
|
+ this.options.hookElement = this.options.hookNext ? this.$element.next() : this.options.hookElement;
|
|
|
+ if (this.options.hookElement) {
|
|
|
+ this.setHookValue(this.state());
|
|
|
+ }
|
|
|
this.$wrapper = $('<div>', {
|
|
|
class: function _class() {
|
|
|
return getClasses(_this9.options, _this9.$element.attr('id')).map(function (v) {
|
|
@@ -386,6 +394,9 @@
|
|
|
});
|
|
|
|
|
|
this.$element.on('init.bootstrapSwitch', function () {
|
|
|
+ if (_this9.options.hookElement) {
|
|
|
+ _this9.options.hookElement.attr('disabled', _this9.$element.attr('disabled'));
|
|
|
+ }
|
|
|
return _this9.options.onInit(element);
|
|
|
});
|
|
|
this.$element.on('switchChange.bootstrapSwitch', function () {
|
|
@@ -394,6 +405,9 @@
|
|
|
}
|
|
|
|
|
|
var changeState = _this9.options.onSwitchChange.apply(element, args);
|
|
|
+ if (_this9.options.hookElement) {
|
|
|
+ _this9.setHookValue(args[1]).change();
|
|
|
+ }
|
|
|
if (changeState === false) {
|
|
|
if (_this9.$element.is(':radio')) {
|
|
|
$('[name="' + _this9.$element.attr('name') + '"]').trigger('previousState.bootstrapSwitch', true);
|
|
@@ -508,6 +522,9 @@
|
|
|
value: function toggleDisabled() {
|
|
|
this.options.disabled = !this.options.disabled;
|
|
|
this.$element.prop('disabled', this.options.disabled);
|
|
|
+ if (this.options.hookElement) {
|
|
|
+ this.options.hookElement.prop('disabled', this.options.disabled);
|
|
|
+ }
|
|
|
this.$wrapper.toggleClass(prvgetClass.call(this, 'disabled'));
|
|
|
return this.$element;
|
|
|
}
|
|
@@ -716,6 +733,18 @@
|
|
|
this.$element.unwrap().unwrap().off('.bootstrapSwitch').removeData('bootstrap-switch');
|
|
|
return this.$element;
|
|
|
}
|
|
|
+ }, {
|
|
|
+ key: 'setHookValue',
|
|
|
+ value: function setHookValue(boolean) {
|
|
|
+ if (this.options.valueType === 'on-off') {
|
|
|
+ this.options.hookElement.val(boolean ? 'on' : 'off');
|
|
|
+ } else if (this.options.valueType === 'text') {
|
|
|
+ this.options.hookElement.val(this.options[boolean ? 'onText' : 'offText']);
|
|
|
+ } else {
|
|
|
+ this.options.hookElement.val(boolean);
|
|
|
+ }
|
|
|
+ return this.options.hookElement;
|
|
|
+ }
|
|
|
}]);
|
|
|
|
|
|
return BootstrapSwitch;
|
|
@@ -762,6 +791,9 @@
|
|
|
baseClass: 'bootstrap-switch',
|
|
|
wrapperClass: 'wrapper',
|
|
|
onInit: function onInit() {},
|
|
|
- onSwitchChange: function onSwitchChange() {}
|
|
|
+ onSwitchChange: function onSwitchChange() {},
|
|
|
+ hookElement: null,
|
|
|
+ hookNext: false,
|
|
|
+ valueType: 'on-off' // text|on-off|boolean
|
|
|
};
|
|
|
});
|