/**
* bootstrap-switch - Turn checkboxes and radio buttons into toggle switches.
*
* @version v3.3.4
* @homepage https://bttstrp.github.io/bootstrap-switch
* @author Mattia Larentis <mattia@larentis.eu> (http://larentis.eu)
* @license Apache-2.0
*/
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['jquery'], factory);
} else if (typeof exports !== "undefined") {
factory(require('jquery'));
} else {
var mod = {
exports: {}
};
factory(global.jquery);
global.bootstrapSwitch = mod.exports;
}
})(this, function (_jquery) {
'use strict';
var _jquery2 = _interopRequireDefault(_jquery);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var $ = _jquery2.default || window.jQuery || window.$;
var BootstrapSwitch = function () {
function BootstrapSwitch(element) {
var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, BootstrapSwitch);
this.$element = $(element);
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, this._getElementOptions(), options);
this.prevOptions = {};
this.$wrapper = $('<div>', {
class: function _class() {
var classes = [];
classes.push(_this.options.state ? 'on' : 'off');
if (_this.options.size) {
classes.push(_this.options.size);
}
if (_this.options.disabled) {
classes.push('disabled');
}
if (_this.options.readonly) {
classes.push('readonly');
}
if (_this.options.indeterminate) {
classes.push('indeterminate');
}
if (_this.options.inverse) {
classes.push('inverse');
}
if (_this.$element.attr('id')) {
classes.push('id-' + _this.$element.attr('id'));
}
return classes.map(_this._getClass.bind(_this)).concat([_this.options.baseClass], _this._getClasses(_this.options.wrapperClass)).join(' ');
}
});
this.$container = $('<div>', { class: this._getClass('container') });
this.$on = $('<span>', {
html: this.options.onText,
class: this._getClass('handle-on') + ' ' + this._getClass(this.options.onColor)
});
this.$off = $('<span>', {
html: this.options.offText,
class: this._getClass('handle-off') + ' ' + this._getClass(this.options.offColor)
});
this.$label = $('<span>', {
html: this.options.labelText,
class: this._getClass('label')
});
this.$element.on('init.bootstrapSwitch', this.options.onInit.bind(this, element));
this.$element.on('switchChange.bootstrapSwitch', function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (_this.options.onSwitchChange.apply(element, args) === false) {
if (_this.$element.is(':radio')) {
$('[name="' + _this.$element.attr('name') + '"]').trigger('previousState.bootstrapSwitch', true);
} else {
_this.$element.trigger('previousState.bootstrapSwitch', true);
}
}
});
this.$container = this.$element.wrap(this.$container).parent();
this.$wrapper = this.$container.wrap(this.$wrapper).parent();
this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
if (this.options.indeterminate) {
this.$element.prop('indeterminate', true);
}
this._init();
this._elementHandlers();
this._handleHandlers();
this._labelHandlers();
this._formHandler();
this._externalLabelHandler();
this.$element.trigger('init.bootstrapSwitch', this.options.state);
}
_createClass(BootstrapSwitch, [{
key: 'setPrevOptions',
value: function setPrevOptions() {
this.prevOptions = _extends({}, this.options);
}
}, {
key: 'state',
value: function state(value, skip) {
if (typeof value === 'undefined') {
return this.options.state;
}
if (this.options.disabled || this.options.readonly || this.options.state && !this.options.radioAllOff && this.$element.is(':radio')) {
return this.$element;
}
if (this.$element.is(':radio')) {
$('[name="' + this.$element.attr('name') + '"]').trigger('setPreviousOptions.bootstrapSwitch');
} else {
this.$element.trigger('setPreviousOptions.bootstrapSwitch');
}
if (this.options.indeterminate) {
this.indeterminate(false);
}
this.$element.prop('checked', Boolean(value)).trigger('change.bootstrapSwitch', skip);
return this.$element;
}
}, {
key: 'toggleState',
value: function toggleState(skip) {
if (this.options.disabled || this.options.readonly) {
return this.$element;
}
if (this.options.indeterminate) {
this.indeterminate(false);
return this.state(true);
} else {
return this.$element.prop('checked', !this.options.state).trigger('change.bootstrapSwitch', skip);
}
}
}, {
key: 'size',
value: function size(value) {
if (typeof value === 'undefined') {