bootstrap-switch.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /* ========================================================================
  2. * bootstrap-switch - v3.1.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. 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._width();
  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. this.options.animate = value;
  176. this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-animate");
  177. return this.$element;
  178. };
  179. BootstrapSwitch.prototype.toggleAnimate = function() {
  180. this.options.animate = !this.options.animate;
  181. this.$wrapper.toggleClass("" + this.options.baseClass + "-animate");
  182. return this.$element;
  183. };
  184. BootstrapSwitch.prototype.disabled = function(value) {
  185. if (typeof value === "undefined") {
  186. return this.options.disabled;
  187. }
  188. value = !!value;
  189. this.options.disabled = value;
  190. this.$element.prop("disabled", value);
  191. this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-disabled");
  192. return this.$element;
  193. };
  194. BootstrapSwitch.prototype.toggleDisabled = function() {
  195. this.options.disabled = !this.options.disabled;
  196. this.$element.prop("disabled", this.options.disabled);
  197. this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
  198. return this.$element;
  199. };
  200. BootstrapSwitch.prototype.readonly = function(value) {
  201. if (typeof value === "undefined") {
  202. return this.options.readonly;
  203. }
  204. value = !!value;
  205. this.options.readonly = value;
  206. this.$element.prop("readonly", value);
  207. this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-readonly");
  208. return this.$element;
  209. };
  210. BootstrapSwitch.prototype.toggleReadonly = function() {
  211. this.options.readonly = !this.options.readonly;
  212. this.$element.prop("readonly", this.options.readonly);
  213. this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
  214. return this.$element;
  215. };
  216. BootstrapSwitch.prototype.indeterminate = function(value) {
  217. if (typeof value === "undefined") {
  218. return this.options.indeterminate;
  219. }
  220. value = !!value;
  221. this.options.indeterminate = value;
  222. this.$element.prop("indeterminate", value);
  223. this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-indeterminate");
  224. this._containerPosition();
  225. return this.$element;
  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. var $off, $on;
  236. if (typeof value === "undefined") {
  237. return this.options.inverse;
  238. }
  239. value = !!value;
  240. this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-inverse");
  241. $on = this.$on.clone(true);
  242. $off = this.$off.clone(true);
  243. this.$on.replaceWith($off);
  244. this.$off.replaceWith($on);
  245. this.$on = $off;
  246. this.$off = $on;
  247. this.options.inverse = value;
  248. return this.$element;
  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. this.options.radioAllOff = value;
  355. return this.$element;
  356. };
  357. BootstrapSwitch.prototype.onInit = function(value) {
  358. if (typeof value === "undefined") {
  359. return this.options.onInit;
  360. }
  361. if (!value) {
  362. value = $.fn.bootstrapSwitch.defaults.onInit;
  363. }
  364. this.options.onInit = value;
  365. return this.$element;
  366. };
  367. BootstrapSwitch.prototype.onSwitchChange = function(value) {
  368. if (typeof value === "undefined") {
  369. return this.options.onSwitchChange;
  370. }
  371. if (!value) {
  372. value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
  373. }
  374. this.options.onSwitchChange = value;
  375. return this.$element;
  376. };
  377. BootstrapSwitch.prototype.destroy = function() {
  378. var $form;
  379. $form = this.$element.closest("form");
  380. if ($form.length) {
  381. $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
  382. }
  383. this.$container.children().not(this.$element).remove();
  384. this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
  385. return this.$element;
  386. };
  387. BootstrapSwitch.prototype._width = function() {
  388. var $handles, handleWidth;
  389. $handles = this.$on.add(this.$off);
  390. $handles.add(this.$label).css("width", "");
  391. handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
  392. $handles.width(handleWidth);
  393. this.$label.width((function(_this) {
  394. return function(index, width) {
  395. if (_this.options.labelWidth !== "auto") {
  396. return _this.options.labelWidth;
  397. }
  398. if (width < handleWidth) {
  399. return handleWidth;
  400. } else {
  401. return width;
  402. }
  403. };
  404. })(this));
  405. this._handleWidth = this.$on.outerWidth();
  406. this._labelWidth = this.$label.outerWidth();
  407. this.$container.width((this._handleWidth * 2) + this._labelWidth);
  408. return this.$wrapper.width(this._handleWidth + this._labelWidth);
  409. };
  410. BootstrapSwitch.prototype._containerPosition = function(state, callback) {
  411. if (state == null) {
  412. state = this.options.state;
  413. }
  414. this.$container.css("margin-left", (function(_this) {
  415. return function() {
  416. var values;
  417. values = [0, "-" + _this._handleWidth + "px"];
  418. if (_this.options.indeterminate) {
  419. return "-" + (_this._handleWidth / 2) + "px";
  420. }
  421. if (state) {
  422. if (_this.options.inverse) {
  423. return values[1];
  424. } else {
  425. return values[0];
  426. }
  427. } else {
  428. if (_this.options.inverse) {
  429. return values[0];
  430. } else {
  431. return values[1];
  432. }
  433. }
  434. };
  435. })(this));
  436. if (!callback) {
  437. return;
  438. }
  439. return this.$container.one($.support.transition.end, callback).emulateTransitionEnd(500);
  440. };
  441. BootstrapSwitch.prototype._elementHandlers = function() {
  442. return this.$element.on({
  443. "change.bootstrapSwitch": (function(_this) {
  444. return function(e, skip) {
  445. var state;
  446. e.preventDefault();
  447. e.stopImmediatePropagation();
  448. state = _this.$element.is(":checked");
  449. _this._containerPosition(state);
  450. if (state === _this.options.state) {
  451. return;
  452. }
  453. _this.options.state = state;
  454. _this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
  455. if (!skip) {
  456. if (_this.$element.is(":radio")) {
  457. $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
  458. }
  459. return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
  460. }
  461. };
  462. })(this),
  463. "focus.bootstrapSwitch": (function(_this) {
  464. return function(e) {
  465. e.preventDefault();
  466. return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
  467. };
  468. })(this),
  469. "blur.bootstrapSwitch": (function(_this) {
  470. return function(e) {
  471. e.preventDefault();
  472. return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
  473. };
  474. })(this),
  475. "keydown.bootstrapSwitch": (function(_this) {
  476. return function(e) {
  477. if (!e.which || _this.options.disabled || _this.options.readonly) {
  478. return;
  479. }
  480. switch (e.which) {
  481. case 37:
  482. e.preventDefault();
  483. e.stopImmediatePropagation();
  484. return _this.state(false);
  485. case 39:
  486. e.preventDefault();
  487. e.stopImmediatePropagation();
  488. return _this.state(true);
  489. }
  490. };
  491. })(this)
  492. });
  493. };
  494. BootstrapSwitch.prototype._handleHandlers = function() {
  495. this.$on.on("click.bootstrapSwitch", (function(_this) {
  496. return function(e) {
  497. _this.state(false);
  498. return _this.$element.trigger("focus.bootstrapSwitch");
  499. };
  500. })(this));
  501. return this.$off.on("click.bootstrapSwitch", (function(_this) {
  502. return function(e) {
  503. _this.state(true);
  504. return _this.$element.trigger("focus.bootstrapSwitch");
  505. };
  506. })(this));
  507. };
  508. BootstrapSwitch.prototype._labelHandlers = function() {
  509. return this.$label.on({
  510. "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
  511. return function(e) {
  512. if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
  513. return;
  514. }
  515. e.preventDefault();
  516. _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
  517. if (_this.options.animate) {
  518. _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
  519. }
  520. return _this.$element.trigger("focus.bootstrapSwitch");
  521. };
  522. })(this),
  523. "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
  524. return function(e) {
  525. var difference;
  526. if (_this._dragStart == null) {
  527. return;
  528. }
  529. e.preventDefault();
  530. difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
  531. if (difference < -_this._handleWidth || difference > 0) {
  532. return;
  533. }
  534. _this._dragEnd = difference;
  535. return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
  536. };
  537. })(this),
  538. "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
  539. return function(e) {
  540. var state;
  541. if (!_this._dragStart) {
  542. return;
  543. }
  544. e.preventDefault();
  545. if (_this.options.animate) {
  546. _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
  547. }
  548. if (_this._dragEnd) {
  549. state = _this._dragEnd > -(_this._handleWidth / 2);
  550. _this._dragEnd = false;
  551. _this.state(_this.options.inverse ? !state : state);
  552. } else {
  553. _this.state(!_this.options.state);
  554. }
  555. return _this._dragStart = false;
  556. };
  557. })(this),
  558. "mouseleave.bootstrapSwitch": (function(_this) {
  559. return function(e) {
  560. return _this.$label.trigger("mouseup.bootstrapSwitch");
  561. };
  562. })(this)
  563. });
  564. };
  565. BootstrapSwitch.prototype._externalLabelHandler = function() {
  566. var $externalLabel;
  567. $externalLabel = this.$element.closest("label");
  568. return $externalLabel.on("click", (function(_this) {
  569. return function(event) {
  570. event.preventDefault();
  571. event.stopImmediatePropagation();
  572. if (event.target === $externalLabel[0]) {
  573. return _this.toggleState();
  574. }
  575. };
  576. })(this));
  577. };
  578. BootstrapSwitch.prototype._formHandler = function() {
  579. var $form;
  580. $form = this.$element.closest("form");
  581. if ($form.data("bootstrap-switch")) {
  582. return;
  583. }
  584. return $form.on("reset.bootstrapSwitch", function() {
  585. return window.setTimeout(function() {
  586. return $form.find("input").filter(function() {
  587. return $(this).data("bootstrap-switch");
  588. }).each(function() {
  589. return $(this).bootstrapSwitch("state", this.checked);
  590. });
  591. }, 1);
  592. }).data("bootstrap-switch", true);
  593. };
  594. BootstrapSwitch.prototype._getClasses = function(classes) {
  595. var c, cls, _i, _len;
  596. if (!$.isArray(classes)) {
  597. return ["" + this.options.baseClass + "-" + classes];
  598. }
  599. cls = [];
  600. for (_i = 0, _len = classes.length; _i < _len; _i++) {
  601. c = classes[_i];
  602. cls.push("" + this.options.baseClass + "-" + c);
  603. }
  604. return cls;
  605. };
  606. return BootstrapSwitch;
  607. })();
  608. $.fn.bootstrapSwitch = function() {
  609. var args, option, ret;
  610. option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  611. ret = this;
  612. this.each(function() {
  613. var $this, data;
  614. $this = $(this);
  615. data = $this.data("bootstrap-switch");
  616. if (!data) {
  617. $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
  618. }
  619. if (typeof option === "string") {
  620. return ret = data[option].apply(data, args);
  621. }
  622. });
  623. return ret;
  624. };
  625. $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
  626. return $.fn.bootstrapSwitch.defaults = {
  627. state: true,
  628. size: null,
  629. animate: true,
  630. disabled: false,
  631. readonly: false,
  632. indeterminate: false,
  633. inverse: false,
  634. radioAllOff: false,
  635. onColor: "primary",
  636. offColor: "default",
  637. onText: "ON",
  638. offText: "OFF",
  639. labelText: "&nbsp;",
  640. handleWidth: "auto",
  641. labelWidth: "auto",
  642. baseClass: "bootstrap-switch",
  643. wrapperClass: "wrapper",
  644. onInit: function() {},
  645. onSwitchChange: function() {}
  646. };
  647. })(window.jQuery, window);
  648. }).call(this);