bootstrap-switch.js 25 KB

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