bootstrap-switch.js (26277B)
1 /** 2 * bootstrap-switch - Turn checkboxes and radio buttons into toggle switches. 3 * 4 * @version v3.3.4 5 * @homepage https://bttstrp.github.io/bootstrap-switch 6 * @author Mattia Larentis <mattia@larentis.eu> (http://larentis.eu) 7 * @license Apache-2.0 8 */ 9 10 (function (global, factory) { 11 if (typeof define === "function" && define.amd) { 12 define(['jquery'], factory); 13 } else if (typeof exports !== "undefined") { 14 factory(require('jquery')); 15 } else { 16 var mod = { 17 exports: {} 18 }; 19 factory(global.jquery); 20 global.bootstrapSwitch = mod.exports; 21 } 22 })(this, function (_jquery) { 23 'use strict'; 24 25 var _jquery2 = _interopRequireDefault(_jquery); 26 27 function _interopRequireDefault(obj) { 28 return obj && obj.__esModule ? obj : { 29 default: obj 30 }; 31 } 32 33 var _extends = Object.assign || function (target) { 34 for (var i = 1; i < arguments.length; i++) { 35 var source = arguments[i]; 36 37 for (var key in source) { 38 if (Object.prototype.hasOwnProperty.call(source, key)) { 39 target[key] = source[key]; 40 } 41 } 42 } 43 44 return target; 45 }; 46 47 function _classCallCheck(instance, Constructor) { 48 if (!(instance instanceof Constructor)) { 49 throw new TypeError("Cannot call a class as a function"); 50 } 51 } 52 53 var _createClass = function () { 54 function defineProperties(target, props) { 55 for (var i = 0; i < props.length; i++) { 56 var descriptor = props[i]; 57 descriptor.enumerable = descriptor.enumerable || false; 58 descriptor.configurable = true; 59 if ("value" in descriptor) descriptor.writable = true; 60 Object.defineProperty(target, descriptor.key, descriptor); 61 } 62 } 63 64 return function (Constructor, protoProps, staticProps) { 65 if (protoProps) defineProperties(Constructor.prototype, protoProps); 66 if (staticProps) defineProperties(Constructor, staticProps); 67 return Constructor; 68 }; 69 }(); 70 71 var $ = _jquery2.default || window.jQuery || window.$; 72 73 var BootstrapSwitch = function () { 74 function BootstrapSwitch(element) { 75 var _this = this; 76 77 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 78 79 _classCallCheck(this, BootstrapSwitch); 80 81 this.$element = $(element); 82 this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, this._getElementOptions(), options); 83 this.prevOptions = {}; 84 this.$wrapper = $('<div>', { 85 class: function _class() { 86 var classes = []; 87 classes.push(_this.options.state ? 'on' : 'off'); 88 if (_this.options.size) { 89 classes.push(_this.options.size); 90 } 91 if (_this.options.disabled) { 92 classes.push('disabled'); 93 } 94 if (_this.options.readonly) { 95 classes.push('readonly'); 96 } 97 if (_this.options.indeterminate) { 98 classes.push('indeterminate'); 99 } 100 if (_this.options.inverse) { 101 classes.push('inverse'); 102 } 103 if (_this.$element.attr('id')) { 104 classes.push('id-' + _this.$element.attr('id')); 105 } 106 return classes.map(_this._getClass.bind(_this)).concat([_this.options.baseClass], _this._getClasses(_this.options.wrapperClass)).join(' '); 107 } 108 }); 109 this.$container = $('<div>', { class: this._getClass('container') }); 110 this.$on = $('<span>', { 111 html: this.options.onText, 112 class: this._getClass('handle-on') + ' ' + this._getClass(this.options.onColor) 113 }); 114 this.$off = $('<span>', { 115 html: this.options.offText, 116 class: this._getClass('handle-off') + ' ' + this._getClass(this.options.offColor) 117 }); 118 this.$label = $('<span>', { 119 html: this.options.labelText, 120 class: this._getClass('label') 121 }); 122 123 this.$element.on('init.bootstrapSwitch', this.options.onInit.bind(this, element)); 124 this.$element.on('switchChange.bootstrapSwitch', function () { 125 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 126 args[_key] = arguments[_key]; 127 } 128 129 if (_this.options.onSwitchChange.apply(element, args) === false) { 130 if (_this.$element.is(':radio')) { 131 $('[name="' + _this.$element.attr('name') + '"]').trigger('previousState.bootstrapSwitch', true); 132 } else { 133 _this.$element.trigger('previousState.bootstrapSwitch', true); 134 } 135 } 136 }); 137 138 this.$container = this.$element.wrap(this.$container).parent(); 139 this.$wrapper = this.$container.wrap(this.$wrapper).parent(); 140 this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off); 141 142 if (this.options.indeterminate) { 143 this.$element.prop('indeterminate', true); 144 } 145 146 this._init(); 147 this._elementHandlers(); 148 this._handleHandlers(); 149 this._labelHandlers(); 150 this._formHandler(); 151 this._externalLabelHandler(); 152 this.$element.trigger('init.bootstrapSwitch', this.options.state); 153 } 154 155 _createClass(BootstrapSwitch, [{ 156 key: 'setPrevOptions', 157 value: function setPrevOptions() { 158 this.prevOptions = _extends({}, this.options); 159 } 160 }, { 161 key: 'state', 162 value: function state(value, skip) { 163 if (typeof value === 'undefined') { 164 return this.options.state; 165 } 166 if (this.options.disabled || this.options.readonly || this.options.state && !this.options.radioAllOff && this.$element.is(':radio')) { 167 return this.$element; 168 } 169 if (this.$element.is(':radio')) { 170 $('[name="' + this.$element.attr('name') + '"]').trigger('setPreviousOptions.bootstrapSwitch'); 171 } else { 172 this.$element.trigger('setPreviousOptions.bootstrapSwitch'); 173 } 174 if (this.options.indeterminate) { 175 this.indeterminate(false); 176 } 177 this.$element.prop('checked', Boolean(value)).trigger('change.bootstrapSwitch', skip); 178 return this.$element; 179 } 180 }, { 181 key: 'toggleState', 182 value: function toggleState(skip) { 183 if (this.options.disabled || this.options.readonly) { 184 return this.$element; 185 } 186 if (this.options.indeterminate) { 187 this.indeterminate(false); 188 return this.state(true); 189 } else { 190 return this.$element.prop('checked', !this.options.state).trigger('change.bootstrapSwitch', skip); 191 } 192 } 193 }, { 194 key: 'size', 195 value: function size(value) { 196 if (typeof value === 'undefined') { 197 return this.options.size; 198 } 199 if (this.options.size != null) { 200 this.$wrapper.removeClass(this._getClass(this.options.size)); 201 } 202 if (value) { 203 this.$wrapper.addClass(this._getClass(value)); 204 } 205 this._width(); 206 this._containerPosition(); 207 this.options.size = value; 208 return this.$element; 209 } 210 }, { 211 key: 'animate', 212 value: function animate(value) { 213 if (typeof value === 'undefined') { 214 return this.options.animate; 215 } 216 if (this.options.animate === Boolean(value)) { 217 return this.$element; 218 } 219 return this.toggleAnimate(); 220 } 221 }, { 222 key: 'toggleAnimate', 223 value: function toggleAnimate() { 224 this.options.animate = !this.options.animate; 225 this.$wrapper.toggleClass(this._getClass('animate')); 226 return this.$element; 227 } 228 }, { 229 key: 'disabled', 230 value: function disabled(value) { 231 if (typeof value === 'undefined') { 232 return this.options.disabled; 233 } 234 if (this.options.disabled === Boolean(value)) { 235 return this.$element; 236 } 237 return this.toggleDisabled(); 238 } 239 }, { 240 key: 'toggleDisabled', 241 value: function toggleDisabled() { 242 this.options.disabled = !this.options.disabled; 243 this.$element.prop('disabled', this.options.disabled); 244 this.$wrapper.toggleClass(this._getClass('disabled')); 245 return this.$element; 246 } 247 }, { 248 key: 'readonly', 249 value: function readonly(value) { 250 if (typeof value === 'undefined') { 251 return this.options.readonly; 252 } 253 if (this.options.readonly === Boolean(value)) { 254 return this.$element; 255 } 256 return this.toggleReadonly(); 257 } 258 }, { 259 key: 'toggleReadonly', 260 value: function toggleReadonly() { 261 this.options.readonly = !this.options.readonly; 262 this.$element.prop('readonly', this.options.readonly); 263 this.$wrapper.toggleClass(this._getClass('readonly')); 264 return this.$element; 265 } 266 }, { 267 key: 'indeterminate', 268 value: function indeterminate(value) { 269 if (typeof value === 'undefined') { 270 return this.options.indeterminate; 271 } 272 if (this.options.indeterminate === Boolean(value)) { 273 return this.$element; 274 } 275 return this.toggleIndeterminate(); 276 } 277 }, { 278 key: 'toggleIndeterminate', 279 value: function toggleIndeterminate() { 280 this.options.indeterminate = !this.options.indeterminate; 281 this.$element.prop('indeterminate', this.options.indeterminate); 282 this.$wrapper.toggleClass(this._getClass('indeterminate')); 283 this._containerPosition(); 284 return this.$element; 285 } 286 }, { 287 key: 'inverse', 288 value: function inverse(value) { 289 if (typeof value === 'undefined') { 290 return this.options.inverse; 291 } 292 if (this.options.inverse === Boolean(value)) { 293 return this.$element; 294 } 295 return this.toggleInverse(); 296 } 297 }, { 298 key: 'toggleInverse', 299 value: function toggleInverse() { 300 this.$wrapper.toggleClass(this._getClass('inverse')); 301 var $on = this.$on.clone(true); 302 var $off = this.$off.clone(true); 303 this.$on.replaceWith($off); 304 this.$off.replaceWith($on); 305 this.$on = $off; 306 this.$off = $on; 307 this.options.inverse = !this.options.inverse; 308 return this.$element; 309 } 310 }, { 311 key: 'onColor', 312 value: function onColor(value) { 313 if (typeof value === 'undefined') { 314 return this.options.onColor; 315 } 316 if (this.options.onColor) { 317 this.$on.removeClass(this._getClass(this.options.onColor)); 318 } 319 this.$on.addClass(this._getClass(value)); 320 this.options.onColor = value; 321 return this.$element; 322 } 323 }, { 324 key: 'offColor', 325 value: function offColor(value) { 326 if (typeof value === 'undefined') { 327 return this.options.offColor; 328 } 329 if (this.options.offColor) { 330 this.$off.removeClass(this._getClass(this.options.offColor)); 331 } 332 this.$off.addClass(this._getClass(value)); 333 this.options.offColor = value; 334 return this.$element; 335 } 336 }, { 337 key: 'onText', 338 value: function onText(value) { 339 if (typeof value === 'undefined') { 340 return this.options.onText; 341 } 342 this.$on.html(value); 343 this._width(); 344 this._containerPosition(); 345 this.options.onText = value; 346 return this.$element; 347 } 348 }, { 349 key: 'offText', 350 value: function offText(value) { 351 if (typeof value === 'undefined') { 352 return this.options.offText; 353 } 354 this.$off.html(value); 355 this._width(); 356 this._containerPosition(); 357 this.options.offText = value; 358 return this.$element; 359 } 360 }, { 361 key: 'labelText', 362 value: function labelText(value) { 363 if (typeof value === 'undefined') { 364 return this.options.labelText; 365 } 366 this.$label.html(value); 367 this._width(); 368 this.options.labelText = value; 369 return this.$element; 370 } 371 }, { 372 key: 'handleWidth', 373 value: function handleWidth(value) { 374 if (typeof value === 'undefined') { 375 return this.options.handleWidth; 376 } 377 this.options.handleWidth = value; 378 this._width(); 379 this._containerPosition(); 380 return this.$element; 381 } 382 }, { 383 key: 'labelWidth', 384 value: function labelWidth(value) { 385 if (typeof value === 'undefined') { 386 return this.options.labelWidth; 387 } 388 this.options.labelWidth = value; 389 this._width(); 390 this._containerPosition(); 391 return this.$element; 392 } 393 }, { 394 key: 'baseClass', 395 value: function baseClass(value) { 396 return this.options.baseClass; 397 } 398 }, { 399 key: 'wrapperClass', 400 value: function wrapperClass(value) { 401 if (typeof value === 'undefined') { 402 return this.options.wrapperClass; 403 } 404 if (!value) { 405 value = $.fn.bootstrapSwitch.defaults.wrapperClass; 406 } 407 this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(' ')); 408 this.$wrapper.addClass(this._getClasses(value).join(' ')); 409 this.options.wrapperClass = value; 410 return this.$element; 411 } 412 }, { 413 key: 'radioAllOff', 414 value: function radioAllOff(value) { 415 if (typeof value === 'undefined') { 416 return this.options.radioAllOff; 417 } 418 var val = Boolean(value); 419 if (this.options.radioAllOff === val) { 420 return this.$element; 421 } 422 this.options.radioAllOff = val; 423 return this.$element; 424 } 425 }, { 426 key: 'onInit', 427 value: function onInit(value) { 428 if (typeof value === 'undefined') { 429 return this.options.onInit; 430 } 431 if (!value) { 432 value = $.fn.bootstrapSwitch.defaults.onInit; 433 } 434 this.options.onInit = value; 435 return this.$element; 436 } 437 }, { 438 key: 'onSwitchChange', 439 value: function onSwitchChange(value) { 440 if (typeof value === 'undefined') { 441 return this.options.onSwitchChange; 442 } 443 if (!value) { 444 value = $.fn.bootstrapSwitch.defaults.onSwitchChange; 445 } 446 this.options.onSwitchChange = value; 447 return this.$element; 448 } 449 }, { 450 key: 'destroy', 451 value: function destroy() { 452 var $form = this.$element.closest('form'); 453 if ($form.length) { 454 $form.off('reset.bootstrapSwitch').removeData('bootstrap-switch'); 455 } 456 this.$container.children().not(this.$element).remove(); 457 this.$element.unwrap().unwrap().off('.bootstrapSwitch').removeData('bootstrap-switch'); 458 return this.$element; 459 } 460 }, { 461 key: '_getElementOptions', 462 value: function _getElementOptions() { 463 return { 464 state: this.$element.is(':checked'), 465 size: this.$element.data('size'), 466 animate: this.$element.data('animate'), 467 disabled: this.$element.is(':disabled'), 468 readonly: this.$element.is('[readonly]'), 469 indeterminate: this.$element.data('indeterminate'), 470 inverse: this.$element.data('inverse'), 471 radioAllOff: this.$element.data('radio-all-off'), 472 onColor: this.$element.data('on-color'), 473 offColor: this.$element.data('off-color'), 474 onText: this.$element.data('on-text'), 475 offText: this.$element.data('off-text'), 476 labelText: this.$element.data('label-text'), 477 handleWidth: this.$element.data('handle-width'), 478 labelWidth: this.$element.data('label-width'), 479 baseClass: this.$element.data('base-class'), 480 wrapperClass: this.$element.data('wrapper-class') 481 }; 482 } 483 }, { 484 key: '_width', 485 value: function _width() { 486 var _this2 = this; 487 488 var $handles = this.$on.add(this.$off).add(this.$label).css('width', ''); 489 var handleWidth = this.options.handleWidth === 'auto' ? Math.round(Math.max(this.$on.width(), this.$off.width())) : this.options.handleWidth; 490 $handles.width(handleWidth); 491 this.$label.width(function (index, width) { 492 if (_this2.options.labelWidth !== 'auto') { 493 return _this2.options.labelWidth; 494 } 495 if (width < handleWidth) { 496 return handleWidth; 497 } 498 return width; 499 }); 500 this._handleWidth = this.$on.outerWidth(); 501 this._labelWidth = this.$label.outerWidth(); 502 this.$container.width(this._handleWidth * 2 + this._labelWidth); 503 return this.$wrapper.width(this._handleWidth + this._labelWidth); 504 } 505 }, { 506 key: '_containerPosition', 507 value: function _containerPosition() { 508 var _this3 = this; 509 510 var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.state; 511 var callback = arguments[1]; 512 513 this.$container.css('margin-left', function () { 514 var values = [0, '-' + _this3._handleWidth + 'px']; 515 if (_this3.options.indeterminate) { 516 return '-' + _this3._handleWidth / 2 + 'px'; 517 } 518 if (state) { 519 if (_this3.options.inverse) { 520 return values[1]; 521 } else { 522 return values[0]; 523 } 524 } else { 525 if (_this3.options.inverse) { 526 return values[0]; 527 } else { 528 return values[1]; 529 } 530 } 531 }); 532 } 533 }, { 534 key: '_init', 535 value: function _init() { 536 var _this4 = this; 537 538 var init = function init() { 539 _this4.setPrevOptions(); 540 _this4._width(); 541 _this4._containerPosition(); 542 setTimeout(function () { 543 if (_this4.options.animate) { 544 return _this4.$wrapper.addClass(_this4._getClass('animate')); 545 } 546 }, 50); 547 }; 548 if (this.$wrapper.is(':visible')) { 549 init(); 550 return; 551 } 552 var initInterval = window.setInterval(function () { 553 if (_this4.$wrapper.is(':visible')) { 554 init(); 555 return window.clearInterval(initInterval); 556 } 557 }, 50); 558 } 559 }, { 560 key: '_elementHandlers', 561 value: function _elementHandlers() { 562 var _this5 = this; 563 564 return this.$element.on({ 565 'setPreviousOptions.bootstrapSwitch': this.setPrevOptions.bind(this), 566 567 'previousState.bootstrapSwitch': function previousStateBootstrapSwitch() { 568 _this5.options = _this5.prevOptions; 569 if (_this5.options.indeterminate) { 570 _this5.$wrapper.addClass(_this5._getClass('indeterminate')); 571 } 572 _this5.$element.prop('checked', _this5.options.state).trigger('change.bootstrapSwitch', true); 573 }, 574 575 'change.bootstrapSwitch': function changeBootstrapSwitch(event, skip) { 576 event.preventDefault(); 577 event.stopImmediatePropagation(); 578 var state = _this5.$element.is(':checked'); 579 _this5._containerPosition(state); 580 if (state === _this5.options.state) { 581 return; 582 } 583 _this5.options.state = state; 584 _this5.$wrapper.toggleClass(_this5._getClass('off')).toggleClass(_this5._getClass('on')); 585 if (!skip) { 586 if (_this5.$element.is(':radio')) { 587 $('[name="' + _this5.$element.attr('name') + '"]').not(_this5.$element).prop('checked', false).trigger('change.bootstrapSwitch', true); 588 } 589 _this5.$element.trigger('switchChange.bootstrapSwitch', [state]); 590 } 591 }, 592 593 'focus.bootstrapSwitch': function focusBootstrapSwitch(event) { 594 event.preventDefault(); 595 _this5.$wrapper.addClass(_this5._getClass('focused')); 596 }, 597 598 'blur.bootstrapSwitch': function blurBootstrapSwitch(event) { 599 event.preventDefault(); 600 _this5.$wrapper.removeClass(_this5._getClass('focused')); 601 }, 602 603 'keydown.bootstrapSwitch': function keydownBootstrapSwitch(event) { 604 if (!event.which || _this5.options.disabled || _this5.options.readonly) { 605 return; 606 } 607 if (event.which === 37 || event.which === 39) { 608 event.preventDefault(); 609 event.stopImmediatePropagation(); 610 _this5.state(event.which === 39); 611 } 612 } 613 }); 614 } 615 }, { 616 key: '_handleHandlers', 617 value: function _handleHandlers() { 618 var _this6 = this; 619 620 this.$on.on('click.bootstrapSwitch', function (event) { 621 event.preventDefault(); 622 event.stopPropagation(); 623 _this6.state(false); 624 return _this6.$element.trigger('focus.bootstrapSwitch'); 625 }); 626 return this.$off.on('click.bootstrapSwitch', function (event) { 627 event.preventDefault(); 628 event.stopPropagation(); 629 _this6.state(true); 630 return _this6.$element.trigger('focus.bootstrapSwitch'); 631 }); 632 } 633 }, { 634 key: '_labelHandlers', 635 value: function _labelHandlers() { 636 var _this7 = this; 637 638 var handlers = { 639 click: function click(event) { 640 event.stopPropagation(); 641 }, 642 643 644 'mousedown.bootstrapSwitch touchstart.bootstrapSwitch': function mousedownBootstrapSwitchTouchstartBootstrapSwitch(event) { 645 if (_this7._dragStart || _this7.options.disabled || _this7.options.readonly) { 646 return; 647 } 648 event.preventDefault(); 649 event.stopPropagation(); 650 _this7._dragStart = (event.pageX || event.originalEvent.touches[0].pageX) - parseInt(_this7.$container.css('margin-left'), 10); 651 if (_this7.options.animate) { 652 _this7.$wrapper.removeClass(_this7._getClass('animate')); 653 } 654 _this7.$element.trigger('focus.bootstrapSwitch'); 655 }, 656 657 'mousemove.bootstrapSwitch touchmove.bootstrapSwitch': function mousemoveBootstrapSwitchTouchmoveBootstrapSwitch(event) { 658 if (_this7._dragStart == null) { 659 return; 660 } 661 var difference = (event.pageX || event.originalEvent.touches[0].pageX) - _this7._dragStart; 662 event.preventDefault(); 663 if (difference < -_this7._handleWidth || difference > 0) { 664 return; 665 } 666 _this7._dragEnd = difference; 667 _this7.$container.css('margin-left', _this7._dragEnd + 'px'); 668 }, 669 670 'mouseup.bootstrapSwitch touchend.bootstrapSwitch': function mouseupBootstrapSwitchTouchendBootstrapSwitch(event) { 671 if (!_this7._dragStart) { 672 return; 673 } 674 event.preventDefault(); 675 if (_this7.options.animate) { 676 _this7.$wrapper.addClass(_this7._getClass('animate')); 677 } 678 if (_this7._dragEnd) { 679 var state = _this7._dragEnd > -(_this7._handleWidth / 2); 680 _this7._dragEnd = false; 681 _this7.state(_this7.options.inverse ? !state : state); 682 } else { 683 _this7.state(!_this7.options.state); 684 } 685 _this7._dragStart = false; 686 }, 687 688 'mouseleave.bootstrapSwitch': function mouseleaveBootstrapSwitch() { 689 _this7.$label.trigger('mouseup.bootstrapSwitch'); 690 } 691 }; 692 this.$label.on(handlers); 693 } 694 }, { 695 key: '_externalLabelHandler', 696 value: function _externalLabelHandler() { 697 var _this8 = this; 698 699 var $externalLabel = this.$element.closest('label'); 700 $externalLabel.on('click', function (event) { 701 event.preventDefault(); 702 event.stopImmediatePropagation(); 703 if (event.target === $externalLabel[0]) { 704 _this8.toggleState(); 705 } 706 }); 707 } 708 }, { 709 key: '_formHandler', 710 value: function _formHandler() { 711 var $form = this.$element.closest('form'); 712 if ($form.data('bootstrap-switch')) { 713 return; 714 } 715 $form.on('reset.bootstrapSwitch', function () { 716 window.setTimeout(function () { 717 $form.find('input').filter(function () { 718 return $(this).data('bootstrap-switch'); 719 }).each(function () { 720 return $(this).bootstrapSwitch('state', this.checked); 721 }); 722 }, 1); 723 }).data('bootstrap-switch', true); 724 } 725 }, { 726 key: '_getClass', 727 value: function _getClass(name) { 728 return this.options.baseClass + '-' + name; 729 } 730 }, { 731 key: '_getClasses', 732 value: function _getClasses(classes) { 733 if (!$.isArray(classes)) { 734 return [this._getClass(classes)]; 735 } 736 return classes.map(this._getClass.bind(this)); 737 } 738 }]); 739 740 return BootstrapSwitch; 741 }(); 742 743 $.fn.bootstrapSwitch = function (option) { 744 for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { 745 args[_key2 - 1] = arguments[_key2]; 746 } 747 748 function reducer(ret, next) { 749 var $this = $(next); 750 var existingData = $this.data('bootstrap-switch'); 751 var data = existingData || new BootstrapSwitch(next, option); 752 if (!existingData) { 753 $this.data('bootstrap-switch', data); 754 } 755 if (typeof option === 'string') { 756 return data[option].apply(data, args); 757 } 758 return ret; 759 } 760 return Array.prototype.reduce.call(this, reducer, this); 761 }; 762 $.fn.bootstrapSwitch.Constructor = BootstrapSwitch; 763 $.fn.bootstrapSwitch.defaults = { 764 state: true, 765 size: null, 766 animate: true, 767 disabled: false, 768 readonly: false, 769 indeterminate: false, 770 inverse: false, 771 radioAllOff: false, 772 onColor: 'primary', 773 offColor: 'default', 774 onText: 'ON', 775 offText: 'OFF', 776 labelText: ' ', 777 handleWidth: 'auto', 778 labelWidth: 'auto', 779 baseClass: 'bootstrap-switch', 780 wrapperClass: 'wrapper', 781 onInit: function onInit() {}, 782 onSwitchChange: function onSwitchChange() {} 783 }; 784 });