bootstrap-switch.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /* ========================================================================
  2. * bootstrap-switch - v3.2.1
  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. if ($.support.transition) {
  440. return this.$container.one("bsTransitionEnd", callback).emulateTransitionEnd(500);
  441. } else {
  442. return callback();
  443. }
  444. };
  445. BootstrapSwitch.prototype._elementHandlers = function() {
  446. return this.$element.on({
  447. "change.bootstrapSwitch": (function(_this) {
  448. return function(e, skip) {
  449. var state;
  450. e.preventDefault();
  451. e.stopImmediatePropagation();
  452. state = _this.$element.is(":checked");
  453. _this._containerPosition(state);
  454. if (state === _this.options.state) {
  455. return;
  456. }
  457. _this.options.state = state;
  458. _this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
  459. if (!skip) {
  460. if (_this.$element.is(":radio")) {
  461. $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
  462. }
  463. return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
  464. }
  465. };
  466. })(this),
  467. "focus.bootstrapSwitch": (function(_this) {
  468. return function(e) {
  469. e.preventDefault();
  470. return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
  471. };
  472. })(this),
  473. "blur.bootstrapSwitch": (function(_this) {
  474. return function(e) {
  475. e.preventDefault();
  476. return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
  477. };
  478. })(this),
  479. "keydown.bootstrapSwitch": (function(_this) {
  480. return function(e) {
  481. if (!e.which || _this.options.disabled || _this.options.readonly) {
  482. return;
  483. }
  484. switch (e.which) {
  485. case 37:
  486. e.preventDefault();
  487. e.stopImmediatePropagation();
  488. return _this.state(false);
  489. case 39:
  490. e.preventDefault();
  491. e.stopImmediatePropagation();
  492. return _this.state(true);
  493. }
  494. };
  495. })(this)
  496. });
  497. };
  498. BootstrapSwitch.prototype._handleHandlers = function() {
  499. this.$on.on("click.bootstrapSwitch", (function(_this) {
  500. return function(e) {
  501. _this.state(false);
  502. return _this.$element.trigger("focus.bootstrapSwitch");
  503. };
  504. })(this));
  505. return this.$off.on("click.bootstrapSwitch", (function(_this) {
  506. return function(e) {
  507. _this.state(true);
  508. return _this.$element.trigger("focus.bootstrapSwitch");
  509. };
  510. })(this));
  511. };
  512. BootstrapSwitch.prototype._labelHandlers = function() {
  513. return this.$label.on({
  514. "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
  515. return function(e) {
  516. if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
  517. return;
  518. }
  519. e.preventDefault();
  520. _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
  521. if (_this.options.animate) {
  522. _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
  523. }
  524. return _this.$element.trigger("focus.bootstrapSwitch");
  525. };
  526. })(this),
  527. "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
  528. return function(e) {
  529. var difference;
  530. if (_this._dragStart == null) {
  531. return;
  532. }
  533. e.preventDefault();
  534. difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
  535. if (difference < -_this._handleWidth || difference > 0) {
  536. return;
  537. }
  538. _this._dragEnd = difference;
  539. return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
  540. };
  541. })(this),
  542. "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
  543. return function(e) {
  544. var state;
  545. if (!_this._dragStart) {
  546. return;
  547. }
  548. e.preventDefault();
  549. if (_this.options.animate) {
  550. _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
  551. }
  552. if (_this._dragEnd) {
  553. state = _this._dragEnd > -(_this._handleWidth / 2);
  554. _this._dragEnd = false;
  555. _this.state(_this.options.inverse ? !state : state);
  556. } else {
  557. _this.state(!_this.options.state);
  558. }
  559. return _this._dragStart = false;
  560. };
  561. })(this),
  562. "mouseleave.bootstrapSwitch": (function(_this) {
  563. return function(e) {
  564. return _this.$label.trigger("mouseup.bootstrapSwitch");
  565. };
  566. })(this)
  567. });
  568. };
  569. BootstrapSwitch.prototype._externalLabelHandler = function() {
  570. var $externalLabel;
  571. $externalLabel = this.$element.closest("label");
  572. return $externalLabel.on("click", (function(_this) {
  573. return function(event) {
  574. event.preventDefault();
  575. event.stopImmediatePropagation();
  576. if (event.target === $externalLabel[0]) {
  577. return _this.toggleState();
  578. }
  579. };
  580. })(this));
  581. };
  582. BootstrapSwitch.prototype._formHandler = function() {
  583. var $form;
  584. $form = this.$element.closest("form");
  585. if ($form.data("bootstrap-switch")) {
  586. return;
  587. }
  588. return $form.on("reset.bootstrapSwitch", function() {
  589. return window.setTimeout(function() {
  590. return $form.find("input").filter(function() {
  591. return $(this).data("bootstrap-switch");
  592. }).each(function() {
  593. return $(this).bootstrapSwitch("state", this.checked);
  594. });
  595. }, 1);
  596. }).data("bootstrap-switch", true);
  597. };
  598. BootstrapSwitch.prototype._getClasses = function(classes) {
  599. var c, cls, _i, _len;
  600. if (!$.isArray(classes)) {
  601. return ["" + this.options.baseClass + "-" + classes];
  602. }
  603. cls = [];
  604. for (_i = 0, _len = classes.length; _i < _len; _i++) {
  605. c = classes[_i];
  606. cls.push("" + this.options.baseClass + "-" + c);
  607. }
  608. return cls;
  609. };
  610. return BootstrapSwitch;
  611. })();
  612. $.fn.bootstrapSwitch = function() {
  613. var args, option, ret;
  614. option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  615. ret = this;
  616. this.each(function() {
  617. var $this, data;
  618. $this = $(this);
  619. data = $this.data("bootstrap-switch");
  620. if (!data) {
  621. $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
  622. }
  623. if (typeof option === "string") {
  624. return ret = data[option].apply(data, args);
  625. }
  626. });
  627. return ret;
  628. };
  629. $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
  630. return $.fn.bootstrapSwitch.defaults = {
  631. state: true,
  632. size: null,
  633. animate: true,
  634. disabled: false,
  635. readonly: false,
  636. indeterminate: false,
  637. inverse: false,
  638. radioAllOff: false,
  639. onColor: "primary",
  640. offColor: "default",
  641. onText: "ON",
  642. offText: "OFF",
  643. labelText: "&nbsp;",
  644. handleWidth: "auto",
  645. labelWidth: "auto",
  646. baseClass: "bootstrap-switch",
  647. wrapperClass: "wrapper",
  648. onInit: function() {},
  649. onSwitchChange: function() {}
  650. };
  651. })(window.jQuery, window);
  652. }).call(this);