bootstrap-switch.js 25 KB

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