You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

744 lines
26 KiB

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