bootstrap-switch.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /* ========================================================================
  2. * bootstrap-switch - v3.3.0
  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. }
  145. value = !!value;
  146. this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
  147. return this.$element;
  148. };
  149. BootstrapSwitch.prototype.toggleState = function(skip) {
  150. if (this.options.disabled || this.options.readonly) {
  151. return this.$element;
  152. }
  153. if (this.options.indeterminate) {
  154. this.indeterminate(false);
  155. return this.state(true);
  156. } else {
  157. return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
  158. }
  159. };
  160. BootstrapSwitch.prototype.size = function(value) {
  161. if (typeof value === "undefined") {
  162. return this.options.size;
  163. }
  164. if (this.options.size != null) {
  165. this.$wrapper.removeClass("" + this.options.baseClass + "-" + this.options.size);
  166. }
  167. if (value) {
  168. this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
  169. }
  170. this._width();
  171. this._containerPosition();
  172. this.options.size = value;
  173. return this.$element;
  174. };
  175. BootstrapSwitch.prototype.animate = function(value) {
  176. if (typeof value === "undefined") {
  177. return this.options.animate;
  178. }
  179. value = !!value;
  180. if (value === this.options.animate) {
  181. return this.$element;
  182. }
  183. return this.toggleAnimate();
  184. };
  185. BootstrapSwitch.prototype.toggleAnimate = function() {
  186. this.options.animate = !this.options.animate;
  187. this.$wrapper.toggleClass("" + this.options.baseClass + "-animate");
  188. return this.$element;
  189. };
  190. BootstrapSwitch.prototype.disabled = function(value) {
  191. if (typeof value === "undefined") {
  192. return this.options.disabled;
  193. }
  194. value = !!value;
  195. if (value === this.options.disabled) {
  196. return this.$element;
  197. }
  198. return this.toggleDisabled();
  199. };
  200. BootstrapSwitch.prototype.toggleDisabled = function() {
  201. this.options.disabled = !this.options.disabled;
  202. this.$element.prop("disabled", this.options.disabled);
  203. this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
  204. return this.$element;
  205. };
  206. BootstrapSwitch.prototype.readonly = function(value) {
  207. if (typeof value === "undefined") {
  208. return this.options.readonly;
  209. }
  210. value = !!value;
  211. if (value === this.options.readonly) {
  212. return this.$element;
  213. }
  214. return this.toggleReadonly();
  215. };
  216. BootstrapSwitch.prototype.toggleReadonly = function() {
  217. this.options.readonly = !this.options.readonly;
  218. this.$element.prop("readonly", this.options.readonly);
  219. this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
  220. return this.$element;
  221. };
  222. BootstrapSwitch.prototype.indeterminate = function(value) {
  223. if (typeof value === "undefined") {
  224. return this.options.indeterminate;
  225. }
  226. value = !!value;
  227. if (value === this.options.indeterminate) {
  228. return this.$element;
  229. }
  230. return this.toggleIndeterminate();
  231. };
  232. BootstrapSwitch.prototype.toggleIndeterminate = function() {
  233. this.options.indeterminate = !this.options.indeterminate;
  234. this.$element.prop("indeterminate", this.options.indeterminate);
  235. this.$wrapper.toggleClass("" + this.options.baseClass + "-indeterminate");
  236. this._containerPosition();
  237. return this.$element;
  238. };
  239. BootstrapSwitch.prototype.inverse = function(value) {
  240. if (typeof value === "undefined") {
  241. return this.options.inverse;
  242. }
  243. value = !!value;
  244. if (value === this.options.inverse) {
  245. return this.$element;
  246. }
  247. return this.toggleInverse();
  248. };
  249. BootstrapSwitch.prototype.toggleInverse = function() {
  250. var $off, $on;
  251. this.$wrapper.toggleClass("" + this.options.baseClass + "-inverse");
  252. $on = this.$on.clone(true);
  253. $off = this.$off.clone(true);
  254. this.$on.replaceWith($off);
  255. this.$off.replaceWith($on);
  256. this.$on = $off;
  257. this.$off = $on;
  258. this.options.inverse = !this.options.inverse;
  259. return this.$element;
  260. };
  261. BootstrapSwitch.prototype.onColor = function(value) {
  262. var color;
  263. color = this.options.onColor;
  264. if (typeof value === "undefined") {
  265. return color;
  266. }
  267. if (color != null) {
  268. this.$on.removeClass("" + this.options.baseClass + "-" + color);
  269. }
  270. this.$on.addClass("" + this.options.baseClass + "-" + value);
  271. this.options.onColor = value;
  272. return this.$element;
  273. };
  274. BootstrapSwitch.prototype.offColor = function(value) {
  275. var color;
  276. color = this.options.offColor;
  277. if (typeof value === "undefined") {
  278. return color;
  279. }
  280. if (color != null) {
  281. this.$off.removeClass("" + this.options.baseClass + "-" + color);
  282. }
  283. this.$off.addClass("" + this.options.baseClass + "-" + value);
  284. this.options.offColor = value;
  285. return this.$element;
  286. };
  287. BootstrapSwitch.prototype.onText = function(value) {
  288. if (typeof value === "undefined") {
  289. return this.options.onText;
  290. }
  291. this.$on.html(value);
  292. this._width();
  293. this._containerPosition();
  294. this.options.onText = value;
  295. return this.$element;
  296. };
  297. BootstrapSwitch.prototype.offText = function(value) {
  298. if (typeof value === "undefined") {
  299. return this.options.offText;
  300. }
  301. this.$off.html(value);
  302. this._width();
  303. this._containerPosition();
  304. this.options.offText = value;
  305. return this.$element;
  306. };
  307. BootstrapSwitch.prototype.labelText = function(value) {
  308. if (typeof value === "undefined") {
  309. return this.options.labelText;
  310. }
  311. this.$label.html(value);
  312. this._width();
  313. this.options.labelText = value;
  314. return this.$element;
  315. };
  316. BootstrapSwitch.prototype.handleWidth = function(value) {
  317. if (typeof value === "undefined") {
  318. return this.options.handleWidth;
  319. }
  320. this.options.handleWidth = value;
  321. this._width();
  322. this._containerPosition();
  323. return this.$element;
  324. };
  325. BootstrapSwitch.prototype.labelWidth = function(value) {
  326. if (typeof value === "undefined") {
  327. return this.options.labelWidth;
  328. }
  329. this.options.labelWidth = value;
  330. this._width();
  331. this._containerPosition();
  332. return this.$element;
  333. };
  334. BootstrapSwitch.prototype.baseClass = function(value) {
  335. return this.options.baseClass;
  336. };
  337. BootstrapSwitch.prototype.wrapperClass = function(value) {
  338. if (typeof value === "undefined") {
  339. return this.options.wrapperClass;
  340. }
  341. if (!value) {
  342. value = $.fn.bootstrapSwitch.defaults.wrapperClass;
  343. }
  344. this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
  345. this.$wrapper.addClass(this._getClasses(value).join(" "));
  346. this.options.wrapperClass = value;
  347. return this.$element;
  348. };
  349. BootstrapSwitch.prototype.radioAllOff = function(value) {
  350. if (typeof value === "undefined") {
  351. return this.options.radioAllOff;
  352. }
  353. value = !!value;
  354. if (value === this.options.radioAllOff) {
  355. return this.$element;
  356. }
  357. this.options.radioAllOff = value;
  358. return this.$element;
  359. };
  360. BootstrapSwitch.prototype.onInit = function(value) {
  361. if (typeof value === "undefined") {
  362. return this.options.onInit;
  363. }
  364. if (!value) {
  365. value = $.fn.bootstrapSwitch.defaults.onInit;
  366. }
  367. this.options.onInit = value;
  368. return this.$element;
  369. };
  370. BootstrapSwitch.prototype.onSwitchChange = function(value) {
  371. if (typeof value === "undefined") {
  372. return this.options.onSwitchChange;
  373. }
  374. if (!value) {
  375. value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
  376. }
  377. this.options.onSwitchChange = value;
  378. return this.$element;
  379. };
  380. BootstrapSwitch.prototype.destroy = function() {
  381. var $form;
  382. $form = this.$element.closest("form");
  383. if ($form.length) {
  384. $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
  385. }
  386. this.$container.children().not(this.$element).remove();
  387. this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
  388. return this.$element;
  389. };
  390. BootstrapSwitch.prototype._width = function() {
  391. var $handles, handleWidth;
  392. $handles = this.$on.add(this.$off);
  393. $handles.add(this.$label).css("width", "");
  394. handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
  395. $handles.width(handleWidth);
  396. this.$label.width((function(_this) {
  397. return function(index, width) {
  398. if (_this.options.labelWidth !== "auto") {
  399. return _this.options.labelWidth;
  400. }
  401. if (width < handleWidth) {
  402. return handleWidth;
  403. } else {
  404. return width;
  405. }
  406. };
  407. })(this));
  408. this._handleWidth = this.$on.outerWidth();
  409. this._labelWidth = this.$label.outerWidth();
  410. this.$container.width((this._handleWidth * 2) + this._labelWidth);
  411. return this.$wrapper.width(this._handleWidth + this._labelWidth);
  412. };
  413. BootstrapSwitch.prototype._containerPosition = function(state, callback) {
  414. if (state == null) {
  415. state = this.options.state;
  416. }
  417. this.$container.css("margin-left", (function(_this) {
  418. return function() {
  419. var values;
  420. values = [0, "-" + _this._handleWidth + "px"];
  421. if (_this.options.indeterminate) {
  422. return "-" + (_this._handleWidth / 2) + "px";
  423. }
  424. if (state) {
  425. if (_this.options.inverse) {
  426. return values[1];
  427. } else {
  428. return values[0];
  429. }
  430. } else {
  431. if (_this.options.inverse) {
  432. return values[0];
  433. } else {
  434. return values[1];
  435. }
  436. }
  437. };
  438. })(this));
  439. if (!callback) {
  440. return;
  441. }
  442. return setTimeout(function() {
  443. return callback();
  444. }, 50);
  445. };
  446. BootstrapSwitch.prototype._elementHandlers = function() {
  447. return this.$element.on({
  448. "change.bootstrapSwitch": (function(_this) {
  449. return function(e, skip) {
  450. var state;
  451. e.preventDefault();
  452. e.stopImmediatePropagation();
  453. state = _this.$element.is(":checked");
  454. _this._containerPosition(state);
  455. if (state === _this.options.state) {
  456. return;
  457. }
  458. _this.options.state = state;
  459. _this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
  460. if (!skip) {
  461. if (_this.$element.is(":radio")) {
  462. $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
  463. }
  464. return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
  465. }
  466. };
  467. })(this),
  468. "focus.bootstrapSwitch": (function(_this) {
  469. return function(e) {
  470. e.preventDefault();
  471. return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
  472. };
  473. })(this),
  474. "blur.bootstrapSwitch": (function(_this) {
  475. return function(e) {
  476. e.preventDefault();
  477. return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
  478. };
  479. })(this),
  480. "keydown.bootstrapSwitch": (function(_this) {
  481. return function(e) {
  482. if (!e.which || _this.options.disabled || _this.options.readonly) {
  483. return;
  484. }
  485. switch (e.which) {
  486. case 37:
  487. e.preventDefault();
  488. e.stopImmediatePropagation();
  489. return _this.state(false);
  490. case 39:
  491. e.preventDefault();
  492. e.stopImmediatePropagation();
  493. return _this.state(true);
  494. }
  495. };
  496. })(this)
  497. });
  498. };
  499. BootstrapSwitch.prototype._handleHandlers = function() {
  500. this.$on.on("click.bootstrapSwitch", (function(_this) {
  501. return function(event) {
  502. event.preventDefault();
  503. event.stopPropagation();
  504. _this.state(false);
  505. return _this.$element.trigger("focus.bootstrapSwitch");
  506. };
  507. })(this));
  508. return this.$off.on("click.bootstrapSwitch", (function(_this) {
  509. return function(event) {
  510. event.preventDefault();
  511. event.stopPropagation();
  512. _this.state(true);
  513. return _this.$element.trigger("focus.bootstrapSwitch");
  514. };
  515. })(this));
  516. };
  517. BootstrapSwitch.prototype._labelHandlers = function() {
  518. return this.$label.on({
  519. "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
  520. return function(e) {
  521. if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
  522. return;
  523. }
  524. e.preventDefault();
  525. e.stopPropagation();
  526. _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
  527. if (_this.options.animate) {
  528. _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
  529. }
  530. return _this.$element.trigger("focus.bootstrapSwitch");
  531. };
  532. })(this),
  533. "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
  534. return function(e) {
  535. var difference;
  536. if (_this._dragStart == null) {
  537. return;
  538. }
  539. e.preventDefault();
  540. difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
  541. if (difference < -_this._handleWidth || difference > 0) {
  542. return;
  543. }
  544. _this._dragEnd = difference;
  545. return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
  546. };
  547. })(this),
  548. "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
  549. return function(e) {
  550. var state;
  551. if (!_this._dragStart) {
  552. return;
  553. }
  554. e.preventDefault();
  555. if (_this.options.animate) {
  556. _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
  557. }
  558. if (_this._dragEnd) {
  559. state = _this._dragEnd > -(_this._handleWidth / 2);
  560. _this._dragEnd = false;
  561. _this.state(_this.options.inverse ? !state : state);
  562. } else {
  563. _this.state(!_this.options.state);
  564. }
  565. return _this._dragStart = false;
  566. };
  567. })(this),
  568. "mouseleave.bootstrapSwitch": (function(_this) {
  569. return function(e) {
  570. return _this.$label.trigger("mouseup.bootstrapSwitch");
  571. };
  572. })(this)
  573. });
  574. };
  575. BootstrapSwitch.prototype._externalLabelHandler = function() {
  576. var $externalLabel;
  577. $externalLabel = this.$element.closest("label");
  578. return $externalLabel.on("click", (function(_this) {
  579. return function(event) {
  580. event.preventDefault();
  581. event.stopImmediatePropagation();
  582. if (event.target === $externalLabel[0]) {
  583. return _this.toggleState();
  584. }
  585. };
  586. })(this));
  587. };
  588. BootstrapSwitch.prototype._formHandler = function() {
  589. var $form;
  590. $form = this.$element.closest("form");
  591. if ($form.data("bootstrap-switch")) {
  592. return;
  593. }
  594. return $form.on("reset.bootstrapSwitch", function() {
  595. return window.setTimeout(function() {
  596. return $form.find("input").filter(function() {
  597. return $(this).data("bootstrap-switch");
  598. }).each(function() {
  599. return $(this).bootstrapSwitch("state", this.checked);
  600. });
  601. }, 1);
  602. }).data("bootstrap-switch", true);
  603. };
  604. BootstrapSwitch.prototype._getClasses = function(classes) {
  605. var c, cls, _i, _len;
  606. if (!$.isArray(classes)) {
  607. return ["" + this.options.baseClass + "-" + classes];
  608. }
  609. cls = [];
  610. for (_i = 0, _len = classes.length; _i < _len; _i++) {
  611. c = classes[_i];
  612. cls.push("" + this.options.baseClass + "-" + c);
  613. }
  614. return cls;
  615. };
  616. return BootstrapSwitch;
  617. })();
  618. $.fn.bootstrapSwitch = function() {
  619. var args, option, ret;
  620. option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  621. ret = this;
  622. this.each(function() {
  623. var $this, data;
  624. $this = $(this);
  625. data = $this.data("bootstrap-switch");
  626. if (!data) {
  627. $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
  628. }
  629. if (typeof option === "string") {
  630. return ret = data[option].apply(data, args);
  631. }
  632. });
  633. return ret;
  634. };
  635. $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
  636. return $.fn.bootstrapSwitch.defaults = {
  637. state: true,
  638. size: null,
  639. animate: true,
  640. disabled: false,
  641. readonly: false,
  642. indeterminate: false,
  643. inverse: false,
  644. radioAllOff: false,
  645. onColor: "primary",
  646. offColor: "default",
  647. onText: "ON",
  648. offText: "OFF",
  649. labelText: "&nbsp;",
  650. handleWidth: "auto",
  651. labelWidth: "auto",
  652. baseClass: "bootstrap-switch",
  653. wrapperClass: "wrapper",
  654. onInit: function() {},
  655. onSwitchChange: function() {}
  656. };
  657. })(window.jQuery, window);
  658. }).call(this);