|
@@ -2,6 +2,19 @@ import jquery from 'jquery';
|
|
|
|
|
|
const $ = jquery || window.jQuery || window.$;
|
|
const $ = jquery || window.jQuery || window.$;
|
|
|
|
|
|
|
|
+function getClasses(options, id) {
|
|
|
|
+ const { state, size, disabled, readonly, indeterminate, inverse } = options;
|
|
|
|
+ return [
|
|
|
|
+ state ? 'on' : 'off',
|
|
|
|
+ size,
|
|
|
|
+ disabled ? 'disabled' : undefined,
|
|
|
|
+ readonly ? 'readonly' : undefined,
|
|
|
|
+ indeterminate ? 'indeterminate' : undefined,
|
|
|
|
+ inverse ? 'inverse' : undefined,
|
|
|
|
+ id ? `id-${id}` : undefined,
|
|
|
|
+ ].filter(v => v == null);
|
|
|
|
+}
|
|
|
|
+
|
|
class BootstrapSwitch {
|
|
class BootstrapSwitch {
|
|
constructor(element, options = {}) {
|
|
constructor(element, options = {}) {
|
|
this.$element = $(element);
|
|
this.$element = $(element);
|
|
@@ -13,32 +26,10 @@ class BootstrapSwitch {
|
|
);
|
|
);
|
|
this.prevOptions = {};
|
|
this.prevOptions = {};
|
|
this.$wrapper = $('<div>', {
|
|
this.$wrapper = $('<div>', {
|
|
- class: () => {
|
|
|
|
- const 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(' ');
|
|
|
|
- },
|
|
|
|
|
|
+ class: () => getClasses(this.options, this.$element.attr('id'))
|
|
|
|
+ .map(this._getClass.bind(this))
|
|
|
|
+ .concat([this.options.baseClass], this._getClasses(this.options.wrapperClass))
|
|
|
|
+ .join(' '),
|
|
});
|
|
});
|
|
this.$container = $('<div>', { class: this._getClass('container') });
|
|
this.$container = $('<div>', { class: this._getClass('container') });
|
|
this.$on = $('<span>', {
|
|
this.$on = $('<span>', {
|