bootstrap-switch.js 25 KB

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