bootstrap-switch.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /* ========================================================================
  2. * bootstrap-switch - v3.2.2
  3. * http://www.bootstrap-switch.org
  4. * ========================================================================
  5. * Copyright 2012-2013 Mattia Larentis
  6. *
  7. * ========================================================================
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. * ========================================================================
  20. */
  21. (function() {
  22. var __slice = [].slice;
  23. (function($, window) {
  24. "use strict";
  25. var BootstrapSwitch;
  26. BootstrapSwitch = (function() {
  27. function BootstrapSwitch(element, options) {
  28. var initInterval;
  29. if (options == null) {
  30. options = {};
  31. }
  32. this.$element = $(element);
  33. this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
  34. state: this.$element.is(":checked"),
  35. size: this.$element.data("size"),
  36. animate: this.$element.data("animate"),
  37. disabled: this.$element.is(":disabled"),
  38. readonly: this.$element.is("[readonly]"),
  39. indeterminate: this.$element.data("indeterminate"),
  40. inverse: this.$element.data("inverse"),
  41. radioAllOff: this.$element.data("radio-all-off"),
  42. onColor: this.$element.data("on-color"),
  43. offColor: this.$element.data("off-color"),
  44. onText: this.$element.data("on-text"),
  45. offText: this.$element.data("off-text"),
  46. labelText: this.$element.data("label-text"),
  47. handleWidth: this.$element.data("handle-width"),
  48. labelWidth: this.$element.data("label-width"),
  49. baseClass: this.$element.data("base-class"),
  50. wrapperClass: this.$element.data("wrapper-class")
  51. }, options);
  52. this.$wrapper = $("<div>", {
  53. "class": (function(_this) {
  54. return function() {
  55. var classes;
  56. classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass));
  57. classes.push(_this.options.state ? "" + _this.options.baseClass + "-on" : "" + _this.options.baseClass + "-off");
  58. if (_this.options.size != null) {
  59. classes.push("" + _this.options.baseClass + "-" + _this.options.size);
  60. }
  61. if (_this.options.disabled) {
  62. classes.push("" + _this.options.baseClass + "-disabled");
  63. }
  64. if (_this.options.readonly) {
  65. classes.push("" + _this.options.baseClass + "-readonly");
  66. }
  67. if (_this.options.indeterminate) {
  68. classes.push("" + _this.options.baseClass + "-indeterminate");
  69. }
  70. if (_this.options.inverse) {
  71. classes.push("" + _this.options.baseClass + "-inverse");
  72. }
  73. if (_this.$element.attr("id")) {
  74. classes.push("" + _this.options.baseClass + "-id-" + (_this.$element.attr("id")));
  75. }
  76. return classes.join(" ");
  77. };
  78. })(this)()
  79. });
  80. this.$container = $("<div>", {
  81. "class": "" + this.options.baseClass + "-container"
  82. });
  83. this.$on = $("<span>", {
  84. html: this.options.onText,
  85. "class": "" + this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor
  86. });
  87. this.$off = $("<span>", {
  88. html: this.options.offText,
  89. "class": "" + this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
  90. });
  91. this.$label = $("<span>", {
  92. html: this.options.labelText,
  93. "class": "" + this.options.baseClass + "-label"
  94. });
  95. this.$element.on("init.bootstrapSwitch", (function(_this) {
  96. return function() {
  97. return _this.options.onInit.apply(element, arguments);
  98. };
  99. })(this));
  100. this.$element.on("switchChange.bootstrapSwitch", (function(_this) {
  101. return function() {
  102. return _this.options.onSwitchChange.apply(element, arguments);
  103. };
  104. })(this));
  105. this.$container = this.$element.wrap(this.$container).parent();
  106. this.$wrapper = this.$container.wrap(this.$wrapper).parent();
  107. this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
  108. if (this.options.indeterminate) {
  109. this.$element.prop("indeterminate", true);
  110. }
  111. initInterval = window.setInterval((function(_this) {
  112. return function() {
  113. if (_this.$wrapper.is(":visible")) {
  114. _this._width();
  115. _this._containerPosition(null, function() {
  116. if (_this.options.animate) {
  117. return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
  118. }
  119. });
  120. return window.clearInterval(initInterval);
  121. }
  122. };
  123. })(this), 50);
  124. this._elementHandlers();
  125. this._handleHandlers();
  126. this._labelHandlers();
  127. this._formHandler();
  128. this._externalLabelHandler();
  129. this.$element.trigger("init.bootstrapSwitch");
  130. }
  131. BootstrapSwitch.prototype._constructor = BootstrapSwitch;
  132. BootstrapSwitch.prototype.state = function(value, skip) {
  133. if (typeof value === "undefined") {
  134. return this.options.state;
  135. }
  136. if (this.options.disabled || this.options.readonly) {
  137. return this.$element;
  138. }
  139. if (this.options.state && !this.options.radioAllOff && this.$element.is(":radio")) {
  140. return this.$element;
  141. }
  142. if (this.options.indeterminate) {
  143. this.indeterminate(false);
  144. value = true;
  145. } else {
  146. value = !!value;
  147. }
  148. this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
  149. return this.$element;
  150. };
  151. BootstrapSwitch.prototype.toggleState = function(skip) {
  152. if (this.options.disabled || this.options.readonly) {
  153. return this.$element;
  154. }
  155. if (this.options.indeterminate) {
  156. this.indeterminate(false);
  157. return this.state(true);
  158. } else {
  159. return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
  160. }
  161. };
  162. BootstrapSwitch.prototype.size = function(value) {
  163. if (typeof value === "undefined") {
  164. return this.options.size;
  165. }
  166. if (this.options.size != null) {
  167. this.$wrapper.removeClass("" + this.options.baseClass + "-" + this.options.size);
  168. }
  169. if (value) {
  170. this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
  171. }
  172. this._width();
  173. this.options.size = value;
  174. return this.$element;
  175. };
  176. BootstrapSwitch.prototype.animate = function(value) {
  177. if (typeof value === "undefined") {
  178. return this.options.animate;
  179. }
  180. value = !!value;
  181. if (value === this.options.animate) {
  182. return this.$element;
  183. }
  184. return this.toggleAnimate();
  185. };
  186. BootstrapSwitch.prototype.toggleAnimate = function() {
  187. this.options.animate = !this.options.animate;
  188. this.$wrapper.toggleClass("" + this.options.baseClass + "-animate");
  189. return this.$element;
  190. };
  191. BootstrapSwitch.prototype.disabled = function(value) {
  192. if (typeof value === "undefined") {
  193. return this.options.disabled;
  194. }
  195. value = !!value;
  196. if (value === this.options.disabled) {
  197. return this.$element;
  198. }
  199. return this.toggleDisabled();
  200. };
  201. BootstrapSwitch.prototype.toggleDisabled = function() {
  202. this.options.disabled = !this.options.disabled;
  203. this.$element.prop("disabled", this.options.disabled);
  204. this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
  205. return this.$element;
  206. };
  207. BootstrapSwitch.prototype.readonly = function(value) {
  208. if (typeof value === "undefined") {
  209. return this.options.readonly;
  210. }
  211. value = !!value;
  212. if (value === this.options.readonly) {
  213. return this.$element;
  214. }
  215. return this.toggleReadonly();
  216. };
  217. BootstrapSwitch.prototype.toggleReadonly = function() {
  218. this.options.readonly = !this.options.readonly;
  219. this.$element.prop("readonly", this.options.readonly);
  220. this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
  221. return this.$element;
  222. };
  223. BootstrapSwitch.prototype.indeterminate = function(value) {
  224. if (typeof value === "undefined") {
  225. return this.options.indeterminate;
  226. }
  227. value = !!value;
  228. if (value === this.options.indeterminate) {
  229. return this.$element;
  230. }
  231. return this.toggleIndeterminate();
  232. };
  233. BootstrapSwitch.prototype.toggleIndeterminate = function() {
  234. this.options.indeterminate = !this.options.indeterminate;
  235. this.$element.prop("indeterminate", this.options.indeterminate);
  236. this.$wrapper.toggleClass("" + this.options.baseClass + "-indeterminate");
  237. this._containerPosition();
  238. return this.$element;
  239. };
  240. BootstrapSwitch.prototype.inverse = function(value) {
  241. if (typeof value === "undefined") {
  242. return this.options.inverse;
  243. }
  244. value = !!value;
  245. if (value === this.options.inverse) {
  246. return this.$element;
  247. }
  248. return this.toggleInverse();
  249. };
  250. BootstrapSwitch.prototype.toggleInverse = function() {
  251. var $off, $on;
  252. this.$wrapper.toggleClass("" + this.options.baseClass + "-inverse");
  253. $on = this.$on.clone(true);
  254. $off = this.$off.clone(true);
  255. this.$on.replaceWith($off);
  256. this.$off.replaceWith($on);
  257. this.$on = $off;
  258. this.$off = $on;
  259. this.options.inverse = !this.options.inverse;
  260. return this.$element;
  261. };
  262. BootstrapSwitch.prototype.onColor = function(value) {
  263. var color;
  264. color = this.options.onColor;
  265. if (typeof value === "undefined") {
  266. return color;
  267. }
  268. if (color != null) {
  269. this.$on.removeClass("" + this.options.baseClass + "-" + color);
  270. }
  271. this.$on.addClass("" + this.options.baseClass + "-" + value);
  272. this.options.onColor = value;
  273. return this.$element;
  274. };
  275. BootstrapSwitch.prototype.offColor = function(value) {
  276. var color;
  277. color = this.options.offColor;
  278. if (typeof value === "undefined") {
  279. return color;
  280. }
  281. if (color != null) {
  282. this.$off.removeClass("" + this.options.baseClass + "-" + color);
  283. }
  284. this.$off.addClass("" + this.options.baseClass + "-" + value);
  285. this.options.offColor = value;
  286. return this.$element;
  287. };
  288. BootstrapSwitch.prototype.onText = function(value) {
  289. if (typeof value === "undefined") {
  290. return this.options.onText;
  291. }
  292. this.$on.html(value);
  293. this._width();
  294. this._containerPosition();
  295. this.options.onText = value;
  296. return this.$element;
  297. };
  298. BootstrapSwitch.prototype.offText = function(value) {
  299. if (typeof value === "undefined") {
  300. return this.options.offText;
  301. }
  302. this.$off.html(value);
  303. this._width();
  304. this._containerPosition();
  305. this.options.offText = value;
  306. return this.$element;
  307. };
  308. BootstrapSwitch.prototype.labelText = function(value) {
  309. if (typeof value === "undefined") {
  310. return this.options.labelText;
  311. }
  312. this.$label.html(value);
  313. this._width();
  314. this.options.labelText = value;
  315. return this.$element;
  316. };
  317. BootstrapSwitch.prototype.handleWidth = function(value) {
  318. if (typeof value === "undefined") {
  319. return this.options.handleWidth;
  320. }
  321. this.options.handleWidth = value;
  322. this._width();
  323. this._containerPosition();
  324. return this.$element;
  325. };
  326. BootstrapSwitch.prototype.labelWidth = function(value) {
  327. if (typeof value === "undefined") {
  328. return this.options.labelWidth;
  329. }
  330. this.options.labelWidth = value;
  331. this._width();
  332. this._containerPosition();
  333. return this.$element;
  334. };
  335. BootstrapSwitch.prototype.baseClass = function(value) {
  336. return this.options.baseClass;
  337. };
  338. BootstrapSwitch.prototype.wrapperClass = function(value) {
  339. if (typeof value === "undefined") {
  340. return this.options.wrapperClass;
  341. }
  342. if (!value) {
  343. value = $.fn.bootstrapSwitch.defaults.wrapperClass;
  344. }
  345. this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
  346. this.$wrapper.addClass(this._getClasses(value).join(" "));
  347. this.options.wrapperClass = value;
  348. return this.$element;
  349. };
  350. BootstrapSwitch.prototype.radioAllOff = function(value) {
  351. if (typeof value === "undefined") {
  352. return this.options.radioAllOff;
  353. }
  354. value = !!value;
  355. if (value === this.options.radioAllOff) {
  356. return this.$element;
  357. }
  358. this.options.radioAllOff = value;
  359. return this.$element;
  360. };
  361. BootstrapSwitch.prototype.onInit = function(value) {
  362. if (typeof value === "undefined") {
  363. return this.options.onInit;
  364. }
  365. if (!value) {
  366. value = $.fn.bootstrapSwitch.defaults.onInit;
  367. }
  368. this.options.onInit = value;
  369. return this.$element;
  370. };
  371. BootstrapSwitch.prototype.onSwitchChange = function(value) {
  372. if (typeof value === "undefined") {
  373. return this.options.onSwitchChange;
  374. }
  375. if (!value) {
  376. value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
  377. }
  378. this.options.onSwitchChange = value;
  379. return this.$element;
  380. };
  381. BootstrapSwitch.prototype.destroy = function() {
  382. var $form;
  383. $form = this.$element.closest("form");
  384. if ($form.length) {
  385. $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
  386. }
  387. this.$container.children().not(this.$element).remove();
  388. this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
  389. return this.$element;
  390. };
  391. BootstrapSwitch.prototype._width = function() {
  392. var $handles, handleWidth;
  393. $handles = this.$on.add(this.$off);
  394. $handles.add(this.$label).css("width", "");
  395. handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
  396. $handles.width(handleWidth);
  397. this.$label.width((function(_this) {
  398. return function(index, width) {
  399. if (_this.options.labelWidth !== "auto") {
  400. return _this.options.labelWidth;
  401. }
  402. if (width < handleWidth) {
  403. return handleWidth;
  404. } else {
  405. return width;
  406. }
  407. };
  408. })(this));
  409. this._handleWidth = this.$on.outerWidth();
  410. this._labelWidth = this.$label.outerWidth();
  411. this.$container.width((this._handleWidth * 2) + this._labelWidth);
  412. return this.$wrapper.width(this._handleWidth + this._labelWidth);
  413. };
  414. BootstrapSwitch.prototype._containerPosition = function(state, callback) {
  415. if (state == null) {
  416. state = this.options.state;
  417. }
  418. this.$container.css("margin-left", (function(_this) {
  419. return function() {
  420. var values;
  421. values = [0, "-" + _this._handleWidth + "px"];
  422. if (_this.options.indeterminate) {
  423. return "-" + (_this._handleWidth / 2) + "px";
  424. }
  425. if (state) {
  426. if (_this.options.inverse) {
  427. return values[1];
  428. } else {
  429. return values[0];
  430. }
  431. } else {
  432. if (_this.options.inverse) {
  433. return values[0];
  434. } else {
  435. return values[1];
  436. }
  437. }
  438. };
  439. })(this));
  440. if (!callback) {
  441. return;
  442. }
  443. return setTimeout(function() {
  444. return callback();
  445. }, 50);
  446. };
  447. BootstrapSwitch.prototype._elementHandlers = function() {
  448. return this.$element.on({
  449. "change.bootstrapSwitch": (function(_this) {
  450. return function(e, skip) {
  451. var state;
  452. e.preventDefault();
  453. e.stopImmediatePropagation();
  454. state = _this.$element.is(":checked");
  455. _this._containerPosition(state);
  456. if (state === _this.options.state) {
  457. return;
  458. }
  459. _this.options.state = state;
  460. _this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
  461. if (!skip) {
  462. if (_this.$element.is(":radio")) {
  463. $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
  464. }
  465. }
  466. return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
  467. };
  468. })(this),
  469. "focus.bootstrapSwitch": (function(_this) {
  470. return function(e) {
  471. e.preventDefault();
  472. return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
  473. };
  474. })(this),
  475. "blur.bootstrapSwitch": (function(_this) {
  476. return function(e) {
  477. e.preventDefault();
  478. return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
  479. };
  480. })(this),
  481. "keydown.bootstrapSwitch": (function(_this) {
  482. return function(e) {
  483. if (!e.which || _this.options.disabled || _this.options.readonly) {
  484. return;
  485. }
  486. switch (e.which) {
  487. case 37:
  488. e.preventDefault();
  489. e.stopImmediatePropagation();
  490. return _this.state(false);
  491. case 39:
  492. e.preventDefault();
  493. e.stopImmediatePropagation();
  494. return _this.state(true);
  495. }
  496. };
  497. })(this)
  498. });
  499. };
  500. BootstrapSwitch.prototype._handleHandlers = function() {
  501. this.$on.on("click.bootstrapSwitch", (function(_this) {
  502. return function(e) {
  503. _this.state(false);
  504. return _this.$element.trigger("focus.bootstrapSwitch");
  505. };
  506. })(this));
  507. return this.$off.on("click.bootstrapSwitch", (function(_this) {
  508. return function(e) {
  509. _this.state(true);
  510. return _this.$element.trigger("focus.bootstrapSwitch");
  511. };
  512. })(this));
  513. };
  514. BootstrapSwitch.prototype._labelHandlers = function() {
  515. return this.$label.on({
  516. "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
  517. return function(e) {
  518. if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
  519. return;
  520. }
  521. e.preventDefault();
  522. e.stopPropagation();
  523. _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
  524. if (_this.options.animate) {
  525. _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
  526. }
  527. return _this.$element.trigger("focus.bootstrapSwitch");
  528. };
  529. })(this),
  530. "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
  531. return function(e) {
  532. var difference;
  533. if (_this._dragStart == null) {
  534. return;
  535. }
  536. e.preventDefault();
  537. difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
  538. if (difference < -_this._handleWidth || difference > 0) {
  539. return;
  540. }
  541. _this._dragEnd = difference;
  542. return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
  543. };
  544. })(this),
  545. "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
  546. return function(e) {
  547. var state;
  548. if (!_this._dragStart) {
  549. return;
  550. }
  551. e.preventDefault();
  552. if (_this.options.animate) {
  553. _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
  554. }
  555. if (_this._dragEnd) {
  556. state = _this._dragEnd > -(_this._handleWidth / 2);
  557. _this._dragEnd = false;
  558. _this.state(_this.options.inverse ? !state : state);
  559. } else {
  560. _this.state(!_this.options.state);
  561. }
  562. return _this._dragStart = false;
  563. };
  564. })(this),
  565. "mouseleave.bootstrapSwitch": (function(_this) {
  566. return function(e) {
  567. return _this.$label.trigger("mouseup.bootstrapSwitch");
  568. };
  569. })(this)
  570. });
  571. };
  572. BootstrapSwitch.prototype._externalLabelHandler = function() {
  573. var $externalLabel;
  574. $externalLabel = this.$element.closest("label");
  575. return $externalLabel.on("click", (function(_this) {
  576. return function(event) {
  577. event.preventDefault();
  578. event.stopImmediatePropagation();
  579. if (event.target === $externalLabel[0]) {
  580. return _this.toggleState();
  581. }
  582. };
  583. })(this));
  584. };
  585. BootstrapSwitch.prototype._formHandler = function() {
  586. var $form;
  587. $form = this.$element.closest("form");
  588. if ($form.data("bootstrap-switch")) {
  589. return;
  590. }
  591. return $form.on("reset.bootstrapSwitch", function() {
  592. return window.setTimeout(function() {
  593. return $form.find("input").filter(function() {
  594. return $(this).data("bootstrap-switch");
  595. }).each(function() {
  596. return $(this).bootstrapSwitch("state", this.checked);
  597. });
  598. }, 1);
  599. }).data("bootstrap-switch", true);
  600. };
  601. BootstrapSwitch.prototype._getClasses = function(classes) {
  602. var c, cls, _i, _len;
  603. if (!$.isArray(classes)) {
  604. return ["" + this.options.baseClass + "-" + classes];
  605. }
  606. cls = [];
  607. for (_i = 0, _len = classes.length; _i < _len; _i++) {
  608. c = classes[_i];
  609. cls.push("" + this.options.baseClass + "-" + c);
  610. }
  611. return cls;
  612. };
  613. return BootstrapSwitch;
  614. })();
  615. $.fn.bootstrapSwitch = function() {
  616. var args, option, ret;
  617. option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  618. ret = this;
  619. this.each(function() {
  620. var $this, data;
  621. $this = $(this);
  622. data = $this.data("bootstrap-switch");
  623. if (!data) {
  624. $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
  625. }
  626. if (typeof option === "string") {
  627. return ret = data[option].apply(data, args);
  628. }
  629. });
  630. return ret;
  631. };
  632. $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
  633. return $.fn.bootstrapSwitch.defaults = {
  634. state: true,
  635. size: null,
  636. animate: true,
  637. disabled: false,
  638. readonly: false,
  639. indeterminate: false,
  640. inverse: false,
  641. radioAllOff: false,
  642. onColor: "primary",
  643. offColor: "default",
  644. onText: "ON",
  645. offText: "OFF",
  646. labelText: "&nbsp;",
  647. handleWidth: "auto",
  648. labelWidth: "auto",
  649. baseClass: "bootstrap-switch",
  650. wrapperClass: "wrapper",
  651. onInit: function() {},
  652. onSwitchChange: function() {}
  653. };
  654. })(window.jQuery, window);
  655. }).call(this);