bootstrap-switch-rails 3.3.3 → 3.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0c84877b65502441acf166449408c135d5a69cc8
4
- data.tar.gz: ce751ae157f0be37d7a550ac5df8d635bbec7ef9
2
+ SHA256:
3
+ metadata.gz: 779d0e2012b1caec540bfed6d18523ddda4bc97fc924894f4456f1a5bc94ef32
4
+ data.tar.gz: 56fd08e4635c807c4c2e0e5e749cb33b5195d7a9f15306cfef1a3146c13fa124
5
5
  SHA512:
6
- metadata.gz: 27d148453266afb175faff83c2fc113aa20220749552093443e2da20a1eb2d5f6754dac88440bce01d10c1eafef04374b074a27cc54111b90eba9bb0fde80c40
7
- data.tar.gz: f048ea3b2f3f7aa4af40ad6f016c0ff7bce55ecae1e33a004c03d24264b5775f61f4e5d5487feec69b95bd76b4eb4cec770e02e0325acc7cc6831ab9ae512ed1
6
+ metadata.gz: 9b47fdb160c4a30bb66753410e77db031d74e928caf8b572cdc5210b177b88fdd446d517925995ba7b40cccd240f8e425cc0be1f831eda55ba687b9d187c609b
7
+ data.tar.gz: 8ea6f6489f7de98ef02d71d269b9bea98c09835fadc114e82fced44c679a6877eff6e07a9fcd2a9f26cd760c7d8a152ee0e8f317401e5c30faeb94b691d2b05e
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # bootstrap-switch-rails [![Gem Version](https://badge.fury.io/rb/bootstrap-switch-rails.png)](http://badge.fury.io/rb/bootstrap-switch-rails)
2
2
 
3
- bootstrap-switch-rails provides the [bootstrap-switch](http://www.bootstrap-switch.org/)
3
+ bootstrap-switch-rails provides the [bootstrap-switch](http://bootstrapswitch.site/)
4
4
  plugin as a Rails engine to use it within the asset pipeline.
5
5
 
6
6
  ## Installation
@@ -46,11 +46,11 @@ or in any `SASS` file, include the following:
46
46
 
47
47
  ## Examples
48
48
 
49
- See the [demo page of Mattia Larentis](http://www.bootstrap-switch.org/) for examples how to use the plugin
49
+ See the [demo page](http://bootstrapswitch.site/examples.html) for examples how to use the plugin
50
50
 
51
51
  ## License
52
52
 
53
- * The [bootstrap-switch](http://www.bootstrap-switch.org/) plugin is licensed under the
53
+ * The [bootstrap-switch](http://bootstrapswitch.site/) plugin is licensed under the
54
54
  [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
55
55
  * The [bootstrap-switch-rails](https://github.com/manuelvanrijn/bootstrap-switch-rails) project is
56
56
  licensed under the [MIT License](http://opensource.org/licenses/mit-license.html)
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "bootstrap-switch-rails"
8
8
  spec.version = Bootstrap::Switch::Rails::VERSION
9
9
  spec.authors = ["Manuel van Rijn"]
10
- spec.email = ["manuel@manuelles.nl"]
10
+ spec.email = ["manuel@manuelvanrijn.nl"]
11
11
  spec.description = %q{A small gem for putting bootstrap-switch into the Rails asset pipeline}
12
12
  spec.summary = %q{an asset gemification of the bootstrap-switch plugin}
13
13
  spec.homepage = "https://github.com/manuelvanrijn/bootstrap-switch-rails"
@@ -1,7 +1,7 @@
1
1
  module Bootstrap
2
2
  module Switch
3
3
  module Rails
4
- VERSION = "3.3.3"
4
+ VERSION = "3.3.4"
5
5
  end
6
6
  end
7
7
  end
@@ -1,8 +1,8 @@
1
1
  #!/bin/sh
2
2
 
3
3
  # Checkout vendor repo
4
- echo "Cloning nostalgiaz/bootstrap-switch github repo into tmp_vendor"
5
- git clone https://github.com/nostalgiaz/bootstrap-switch.git tmp_vendor
4
+ echo "Cloning Bttstrp/bootstrap-switch github repo into tmp_vendor"
5
+ git clone https://github.com/Bttstrp/bootstrap-switch.git tmp_vendor
6
6
 
7
7
  # Copy files
8
8
  echo "Copying bootstrap-switch.js"
@@ -1,710 +1,766 @@
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
-
22
- (function() {
23
- var __slice = [].slice;
24
-
25
- (function($, window) {
26
- "use strict";
27
- var BootstrapSwitch;
28
- BootstrapSwitch = (function() {
29
- function BootstrapSwitch(element, options) {
30
- if (options == null) {
31
- options = {};
32
- }
33
- this.$element = $(element);
34
- this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
35
- state: this.$element.is(":checked"),
36
- size: this.$element.data("size"),
37
- animate: this.$element.data("animate"),
38
- disabled: this.$element.is(":disabled"),
39
- readonly: this.$element.is("[readonly]"),
40
- indeterminate: this.$element.data("indeterminate"),
41
- inverse: this.$element.data("inverse"),
42
- radioAllOff: this.$element.data("radio-all-off"),
43
- onColor: this.$element.data("on-color"),
44
- offColor: this.$element.data("off-color"),
45
- onText: this.$element.data("on-text"),
46
- offText: this.$element.data("off-text"),
47
- labelText: this.$element.data("label-text"),
48
- handleWidth: this.$element.data("handle-width"),
49
- labelWidth: this.$element.data("label-width"),
50
- baseClass: this.$element.data("base-class"),
51
- wrapperClass: this.$element.data("wrapper-class")
52
- }, options);
53
- this.$wrapper = $("<div>", {
54
- "class": (function(_this) {
55
- return function() {
56
- var classes;
57
- classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass));
58
- classes.push(_this.options.state ? "" + _this.options.baseClass + "-on" : "" + _this.options.baseClass + "-off");
59
- if (_this.options.size != null) {
60
- classes.push("" + _this.options.baseClass + "-" + _this.options.size);
61
- }
62
- if (_this.options.disabled) {
63
- classes.push("" + _this.options.baseClass + "-disabled");
64
- }
65
- if (_this.options.readonly) {
66
- classes.push("" + _this.options.baseClass + "-readonly");
67
- }
68
- if (_this.options.indeterminate) {
69
- classes.push("" + _this.options.baseClass + "-indeterminate");
70
- }
71
- if (_this.options.inverse) {
72
- classes.push("" + _this.options.baseClass + "-inverse");
73
- }
74
- if (_this.$element.attr("id")) {
75
- classes.push("" + _this.options.baseClass + "-id-" + (_this.$element.attr("id")));
76
- }
77
- return classes.join(" ");
78
- };
79
- })(this)()
80
- });
81
- this.$container = $("<div>", {
82
- "class": "" + this.options.baseClass + "-container"
83
- });
84
- this.$on = $("<span>", {
85
- html: this.options.onText,
86
- "class": "" + this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor
87
- });
88
- this.$off = $("<span>", {
89
- html: this.options.offText,
90
- "class": "" + this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
91
- });
92
- this.$label = $("<span>", {
93
- html: this.options.labelText,
94
- "class": "" + this.options.baseClass + "-label"
95
- });
96
- this.$element.on("init.bootstrapSwitch", (function(_this) {
97
- return function() {
98
- return _this.options.onInit.apply(element, arguments);
99
- };
100
- })(this));
101
- this.$element.on("switchChange.bootstrapSwitch", (function(_this) {
102
- return function() {
103
- return _this.options.onSwitchChange.apply(element, arguments);
104
- };
105
- })(this));
106
- this.$container = this.$element.wrap(this.$container).parent();
107
- this.$wrapper = this.$container.wrap(this.$wrapper).parent();
108
- this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
109
- if (this.options.indeterminate) {
110
- this.$element.prop("indeterminate", true);
1
+ /**
2
+ * bootstrap-switch - Turn checkboxes and radio buttons into toggle switches.
3
+ *
4
+ * @version v3.3.4
5
+ * @homepage https://bttstrp.github.io/bootstrap-switch
6
+ * @author Mattia Larentis <mattia@larentis.eu> (http://larentis.eu)
7
+ * @license Apache-2.0
8
+ */
9
+
10
+ (function (global, factory) {
11
+ if (typeof define === "function" && define.amd) {
12
+ define(['jquery'], factory);
13
+ } else if (typeof exports !== "undefined") {
14
+ factory(require('jquery'));
15
+ } else {
16
+ var mod = {
17
+ exports: {}
18
+ };
19
+ factory(global.jquery);
20
+ global.bootstrapSwitch = mod.exports;
21
+ }
22
+ })(this, function (_jquery) {
23
+ 'use strict';
24
+
25
+ var _jquery2 = _interopRequireDefault(_jquery);
26
+
27
+ function _interopRequireDefault(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+
33
+ var _extends = Object.assign || function (target) {
34
+ for (var i = 1; i < arguments.length; i++) {
35
+ var source = arguments[i];
36
+
37
+ for (var key in source) {
38
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
39
+ target[key] = source[key];
40
+ }
41
+ }
42
+ }
43
+
44
+ return target;
45
+ };
46
+
47
+ function _classCallCheck(instance, Constructor) {
48
+ if (!(instance instanceof Constructor)) {
49
+ throw new TypeError("Cannot call a class as a function");
50
+ }
51
+ }
52
+
53
+ var _createClass = function () {
54
+ function defineProperties(target, props) {
55
+ for (var i = 0; i < props.length; i++) {
56
+ var descriptor = props[i];
57
+ descriptor.enumerable = descriptor.enumerable || false;
58
+ descriptor.configurable = true;
59
+ if ("value" in descriptor) descriptor.writable = true;
60
+ Object.defineProperty(target, descriptor.key, descriptor);
61
+ }
62
+ }
63
+
64
+ return function (Constructor, protoProps, staticProps) {
65
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
66
+ if (staticProps) defineProperties(Constructor, staticProps);
67
+ return Constructor;
68
+ };
69
+ }();
70
+
71
+ var $ = _jquery2.default || window.jQuery || window.$;
72
+
73
+ function getClasses(options, id) {
74
+ var state = options.state,
75
+ size = options.size,
76
+ disabled = options.disabled,
77
+ readonly = options.readonly,
78
+ indeterminate = options.indeterminate,
79
+ inverse = options.inverse;
80
+
81
+ return [state ? 'on' : 'off', size, disabled ? 'disabled' : undefined, readonly ? 'readonly' : undefined, indeterminate ? 'indeterminate' : undefined, inverse ? 'inverse' : undefined, id ? 'id-' + id : undefined].filter(function (v) {
82
+ return v == null;
83
+ });
84
+ }
85
+
86
+ function prvgetElementOptions() {
87
+ return {
88
+ state: this.$element.is(':checked'),
89
+ size: this.$element.data('size'),
90
+ animate: this.$element.data('animate'),
91
+ disabled: this.$element.is(':disabled'),
92
+ readonly: this.$element.is('[readonly]'),
93
+ indeterminate: this.$element.data('indeterminate'),
94
+ inverse: this.$element.data('inverse'),
95
+ radioAllOff: this.$element.data('radio-all-off'),
96
+ onColor: this.$element.data('on-color'),
97
+ offColor: this.$element.data('off-color'),
98
+ onText: this.$element.data('on-text'),
99
+ offText: this.$element.data('off-text'),
100
+ labelText: this.$element.data('label-text'),
101
+ handleWidth: this.$element.data('handle-width'),
102
+ labelWidth: this.$element.data('label-width'),
103
+ baseClass: this.$element.data('base-class'),
104
+ wrapperClass: this.$element.data('wrapper-class')
105
+ };
106
+ }
107
+
108
+ function prvwidth() {
109
+ var _this = this;
110
+
111
+ var $handles = this.$on.add(this.$off).add(this.$label).css('width', '');
112
+ var handleWidth = this.options.handleWidth === 'auto' ? Math.round(Math.max(this.$on.width(), this.$off.width())) : this.options.handleWidth;
113
+ $handles.width(handleWidth);
114
+ this.$label.width(function (index, width) {
115
+ if (_this.options.labelWidth !== 'auto') {
116
+ return _this.options.labelWidth;
117
+ }
118
+ if (width < handleWidth) {
119
+ return handleWidth;
120
+ }
121
+ return width;
122
+ });
123
+ this.privateHandleWidth = this.$on.outerWidth();
124
+ this.privateLabelWidth = this.$label.outerWidth();
125
+ this.$container.width(this.privateHandleWidth * 2 + this.privateLabelWidth);
126
+ return this.$wrapper.width(this.privateHandleWidth + this.privateLabelWidth);
127
+ }
128
+
129
+ function prvcontainerPosition() {
130
+ var _this2 = this;
131
+
132
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.ope;
133
+
134
+ this.$container.css('margin-left', function () {
135
+ var values = [0, '-' + _this2.privateHandleWidth + 'px'];
136
+ if (_this2.options.indeterminate) {
137
+ return '-' + _this2.privateHandleWidth / 2 + 'px';
138
+ }
139
+ if (state) {
140
+ if (_this2.options.inverse) {
141
+ return values[1];
142
+ }
143
+ return values[0];
144
+ }
145
+ if (_this2.options.inverse) {
146
+ return values[0];
147
+ }
148
+ return values[1];
149
+ });
150
+ }
151
+
152
+ function prvgetClass(name) {
153
+ return this.options.baseClass + '-' + name;
154
+ }
155
+
156
+ function prvinit() {
157
+ var _this3 = this;
158
+
159
+ var init = function init() {
160
+ _this3.setPrevOptions();
161
+ prvwidth.call(_this3);
162
+ prvcontainerPosition.call(_this3);
163
+ setTimeout(function () {
164
+ return _this3.options.animate && _this3.$wrapper.addClass(prvgetClass.call(_this3, 'animate'));
165
+ }, 50);
166
+ };
167
+ if (this.$wrapper.is(':visible')) {
168
+ init();
169
+ return;
170
+ }
171
+ var initInterval = window.setInterval(function () {
172
+ return _this3.$wrapper.is(':visible') && (init() || true) && window.clearInterval(initInterval);
173
+ }, 50);
174
+ }
175
+
176
+ function prvelementHandlers() {
177
+ var _this4 = this;
178
+
179
+ return this.$element.on({
180
+ 'setPreviousOptions.bootstrapSwitch': function setPreviousOptionsBootstrapSwitch() {
181
+ return _this4.setPrevOptions();
182
+ },
183
+
184
+ 'previousState.bootstrapSwitch': function previousStateBootstrapSwitch() {
185
+ _this4.options = _this4.prevOptions;
186
+ if (_this4.options.indeterminate) {
187
+ _this4.$wrapper.addClass(prvgetClass.call(_this4, 'indeterminate'));
188
+ }
189
+ _this4.$element.prop('checked', _this4.options.state).trigger('change.bootstrapSwitch', true);
190
+ },
191
+
192
+ 'change.bootstrapSwitch': function changeBootstrapSwitch(event, skip) {
193
+ event.preventDefault();
194
+ event.stopImmediatePropagation();
195
+ var state = _this4.$element.is(':checked');
196
+ prvcontainerPosition.call(_this4, state);
197
+ if (state === _this4.options.state) {
198
+ return;
199
+ }
200
+ _this4.options.state = state;
201
+ _this4.$wrapper.toggleClass(prvgetClass.call(_this4, 'off')).toggleClass(prvgetClass.call(_this4, 'on'));
202
+ if (!skip) {
203
+ if (_this4.$element.is(':radio')) {
204
+ $('[name="' + _this4.$element.attr('name') + '"]').not(_this4.$element).prop('checked', false).trigger('change.bootstrapSwitch', true);
205
+ }
206
+ _this4.$element.trigger('switchChange.bootstrapSwitch', [state]);
207
+ }
208
+ },
209
+
210
+ 'focus.bootstrapSwitch': function focusBootstrapSwitch(event) {
211
+ event.preventDefault();
212
+ _this4.$wrapper.addClass(prvgetClass.call(_this4, 'focused'));
213
+ },
214
+
215
+ 'blur.bootstrapSwitch': function blurBootstrapSwitch(event) {
216
+ event.preventDefault();
217
+ _this4.$wrapper.removeClass(prvgetClass.call(_this4, 'focused'));
218
+ },
219
+
220
+ 'keydown.bootstrapSwitch': function keydownBootstrapSwitch(event) {
221
+ if (!event.which || _this4.options.disabled || _this4.options.readonly) {
222
+ return;
223
+ }
224
+ if (event.which === 37 || event.which === 39) {
225
+ event.preventDefault();
226
+ event.stopImmediatePropagation();
227
+ _this4.state(event.which === 39);
228
+ }
229
+ }
230
+ });
231
+ }
232
+
233
+ function prvhandleHandlers() {
234
+ var _this5 = this;
235
+
236
+ this.$on.on('click.bootstrapSwitch', function (event) {
237
+ event.preventDefault();
238
+ event.stopPropagation();
239
+ _this5.state(false);
240
+ return _this5.$element.trigger('focus.bootstrapSwitch');
241
+ });
242
+ return this.$off.on('click.bootstrapSwitch', function (event) {
243
+ event.preventDefault();
244
+ event.stopPropagation();
245
+ _this5.state(true);
246
+ return _this5.$element.trigger('focus.bootstrapSwitch');
247
+ });
248
+ }
249
+
250
+ function prvlabelHandlers() {
251
+ var _this6 = this;
252
+
253
+ var dragStart = void 0;
254
+ var dragEnd = void 0;
255
+ var handlers = {
256
+ click: function click(event) {
257
+ event.stopPropagation();
258
+ },
259
+
260
+
261
+ 'mousedown.bootstrapSwitch touchstart.bootstrapSwitch': function mousedownBootstrapSwitchTouchstartBootstrapSwitch(event) {
262
+ if (dragStart || _this6.options.disabled || _this6.options.readonly) {
263
+ return;
111
264
  }
112
- this._init();
113
- this._elementHandlers();
114
- this._handleHandlers();
115
- this._labelHandlers();
116
- this._formHandler();
117
- this._externalLabelHandler();
118
- this.$element.trigger("init.bootstrapSwitch");
265
+ event.preventDefault();
266
+ event.stopPropagation();
267
+ dragStart = (event.pageX || event.originalEvent.touches[0].pageX) - parseInt(_this6.$container.css('margin-left'), 10);
268
+ if (_this6.options.animate) {
269
+ _this6.$wrapper.removeClass(prvgetClass.call(_this6, 'animate'));
270
+ }
271
+ _this6.$element.trigger('focus.bootstrapSwitch');
272
+ },
273
+
274
+ 'mousemove.bootstrapSwitch touchmove.bootstrapSwitch': function mousemoveBootstrapSwitchTouchmoveBootstrapSwitch(event) {
275
+ if (dragStart == null) {
276
+ return;
277
+ }
278
+ var difference = (event.pageX || event.originalEvent.touches[0].pageX) - dragStart;
279
+ event.preventDefault();
280
+ if (difference < -_this6.privateHandleWidth || difference > 0) {
281
+ return;
282
+ }
283
+ dragEnd = difference;
284
+ _this6.$container.css('margin-left', dragEnd + 'px');
285
+ },
286
+
287
+ 'mouseup.bootstrapSwitch touchend.bootstrapSwitch': function mouseupBootstrapSwitchTouchendBootstrapSwitch(event) {
288
+ if (!dragStart) {
289
+ return;
290
+ }
291
+ event.preventDefault();
292
+ if (_this6.options.animate) {
293
+ _this6.$wrapper.addClass(prvgetClass.call(_this6, 'animate'));
294
+ }
295
+ if (dragEnd) {
296
+ var state = dragEnd > -(_this6.privateHandleWidth / 2);
297
+ dragEnd = false;
298
+ _this6.state(_this6.options.inverse ? !state : state);
299
+ } else {
300
+ _this6.state(!_this6.options.state);
301
+ }
302
+ dragStart = false;
303
+ },
304
+
305
+ 'mouseleave.bootstrapSwitch': function mouseleaveBootstrapSwitch() {
306
+ _this6.$label.trigger('mouseup.bootstrapSwitch');
119
307
  }
308
+ };
309
+ this.$label.on(handlers);
310
+ }
311
+
312
+ function prvexternalLabelHandler() {
313
+ var _this7 = this;
314
+
315
+ var $externalLabel = this.$element.closest('label');
316
+ $externalLabel.on('click', function (event) {
317
+ event.preventDefault();
318
+ event.stopImmediatePropagation();
319
+ if (event.target === $externalLabel[0]) {
320
+ _this7.toggleState();
321
+ }
322
+ });
323
+ }
324
+
325
+ function prvformHandler() {
326
+ function isBootstrapSwitch() {
327
+ return $(this).data('bootstrap-switch');
328
+ }
329
+
330
+ function performReset() {
331
+ return $(this).bootstrapSwitch('state', this.checked);
332
+ }
333
+
334
+ var $form = this.$element.closest('form');
335
+ if ($form.data('bootstrap-switch')) {
336
+ return;
337
+ }
338
+ $form.on('reset.bootstrapSwitch', function () {
339
+ window.setTimeout(function () {
340
+ $form.find('input').filter(isBootstrapSwitch).each(performReset);
341
+ }, 1);
342
+ }).data('bootstrap-switch', true);
343
+ }
344
+
345
+ function prvgetClasses(classes) {
346
+ var _this8 = this;
347
+
348
+ if (!$.isArray(classes)) {
349
+ return [prvgetClass.call(this, classes)];
350
+ }
351
+ return classes.map(function (v) {
352
+ return prvgetClass.call(_this8, v);
353
+ });
354
+ }
355
+
356
+ var BootstrapSwitch = function () {
357
+ function BootstrapSwitch(element) {
358
+ var _this9 = this;
359
+
360
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
361
+
362
+ _classCallCheck(this, BootstrapSwitch);
363
+
364
+ this.$element = $(element);
365
+ this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, prvgetElementOptions.call(this), options);
366
+ this.prevOptions = {};
367
+ this.$wrapper = $('<div>', {
368
+ class: function _class() {
369
+ return getClasses(_this9.options, _this9.$element.attr('id')).map(function (v) {
370
+ return prvgetClass.call(_this9, v);
371
+ }).concat([_this9.options.baseClass], prvgetClasses.call(_this9, _this9.options.wrapperClass)).join(' ');
372
+ }
373
+ });
374
+ this.$container = $('<div>', { class: prvgetClass.call(this, 'container') });
375
+ this.$on = $('<span>', {
376
+ html: this.options.onText,
377
+ class: prvgetClass.call(this, 'handle-on') + ' ' + prvgetClass.call(this, this.options.onColor)
378
+ });
379
+ this.$off = $('<span>', {
380
+ html: this.options.offText,
381
+ class: prvgetClass.call(this, 'handle-off') + ' ' + prvgetClass.call(this, this.options.offColor)
382
+ });
383
+ this.$label = $('<span>', {
384
+ html: this.options.labelText,
385
+ class: prvgetClass.call(this, 'label')
386
+ });
387
+
388
+ this.$element.on('init.bootstrapSwitch', function () {
389
+ return _this9.options.onInit(element);
390
+ });
391
+ this.$element.on('switchChange.bootstrapSwitch', function () {
392
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
393
+ args[_key] = arguments[_key];
394
+ }
395
+
396
+ if (_this9.options.onSwitchChange.apply(element, args) === false) {
397
+ if (_this9.$element.is(':radio')) {
398
+ $('[name="' + _this9.$element.attr('name') + '"]').trigger('previousState.bootstrapSwitch', true);
399
+ } else {
400
+ _this9.$element.trigger('previousState.bootstrapSwitch', true);
401
+ }
402
+ }
403
+ });
404
+
405
+ this.$container = this.$element.wrap(this.$container).parent();
406
+ this.$wrapper = this.$container.wrap(this.$wrapper).parent();
407
+ this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
120
408
 
121
- BootstrapSwitch.prototype._constructor = BootstrapSwitch;
409
+ if (this.options.indeterminate) {
410
+ this.$element.prop('indeterminate', true);
411
+ }
122
412
 
123
- BootstrapSwitch.prototype.state = function(value, skip) {
124
- if (typeof value === "undefined") {
413
+ prvinit.call(this);
414
+ prvelementHandlers.call(this);
415
+ prvhandleHandlers.call(this);
416
+ prvlabelHandlers.call(this);
417
+ prvformHandler.call(this);
418
+ prvexternalLabelHandler.call(this);
419
+ this.$element.trigger('init.bootstrapSwitch', this.options.state);
420
+ }
421
+
422
+ _createClass(BootstrapSwitch, [{
423
+ key: 'setPrevOptions',
424
+ value: function setPrevOptions() {
425
+ this.prevOptions = _extends({}, this.options);
426
+ }
427
+ }, {
428
+ key: 'state',
429
+ value: function state(value, skip) {
430
+ if (typeof value === 'undefined') {
125
431
  return this.options.state;
126
432
  }
127
- if (this.options.disabled || this.options.readonly) {
433
+ if (this.options.disabled || this.options.readonly || this.options.state && !this.options.radioAllOff && this.$element.is(':radio')) {
128
434
  return this.$element;
129
435
  }
130
- if (this.options.state && !this.options.radioAllOff && this.$element.is(":radio")) {
131
- return this.$element;
436
+ if (this.$element.is(':radio')) {
437
+ $('[name="' + this.$element.attr('name') + '"]').trigger('setPreviousOptions.bootstrapSwitch');
438
+ } else {
439
+ this.$element.trigger('setPreviousOptions.bootstrapSwitch');
132
440
  }
133
441
  if (this.options.indeterminate) {
134
442
  this.indeterminate(false);
135
443
  }
136
- value = !!value;
137
- this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
444
+ this.$element.prop('checked', Boolean(value)).trigger('change.bootstrapSwitch', skip);
138
445
  return this.$element;
139
- };
140
-
141
- BootstrapSwitch.prototype.toggleState = function(skip) {
446
+ }
447
+ }, {
448
+ key: 'toggleState',
449
+ value: function toggleState(skip) {
142
450
  if (this.options.disabled || this.options.readonly) {
143
451
  return this.$element;
144
452
  }
145
453
  if (this.options.indeterminate) {
146
454
  this.indeterminate(false);
147
455
  return this.state(true);
148
- } else {
149
- return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
150
456
  }
151
- };
152
-
153
- BootstrapSwitch.prototype.size = function(value) {
154
- if (typeof value === "undefined") {
457
+ return this.$element.prop('checked', !this.options.state).trigger('change.bootstrapSwitch', skip);
458
+ }
459
+ }, {
460
+ key: 'size',
461
+ value: function size(value) {
462
+ if (typeof value === 'undefined') {
155
463
  return this.options.size;
156
464
  }
157
465
  if (this.options.size != null) {
158
- this.$wrapper.removeClass("" + this.options.baseClass + "-" + this.options.size);
466
+ this.$wrapper.removeClass(prvgetClass.call(this, this.options.size));
159
467
  }
160
468
  if (value) {
161
- this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
469
+ this.$wrapper.addClass(prvgetClass.call(this, value));
162
470
  }
163
- this._width();
164
- this._containerPosition();
471
+ prvwidth.call(this);
472
+ prvcontainerPosition.call(this);
165
473
  this.options.size = value;
166
474
  return this.$element;
167
- };
168
-
169
- BootstrapSwitch.prototype.animate = function(value) {
170
- if (typeof value === "undefined") {
475
+ }
476
+ }, {
477
+ key: 'animate',
478
+ value: function animate(value) {
479
+ if (typeof value === 'undefined') {
171
480
  return this.options.animate;
172
481
  }
173
- value = !!value;
174
- if (value === this.options.animate) {
482
+ if (this.options.animate === Boolean(value)) {
175
483
  return this.$element;
176
484
  }
177
485
  return this.toggleAnimate();
178
- };
179
-
180
- BootstrapSwitch.prototype.toggleAnimate = function() {
486
+ }
487
+ }, {
488
+ key: 'toggleAnimate',
489
+ value: function toggleAnimate() {
181
490
  this.options.animate = !this.options.animate;
182
- this.$wrapper.toggleClass("" + this.options.baseClass + "-animate");
491
+ this.$wrapper.toggleClass(prvgetClass.call(this, 'animate'));
183
492
  return this.$element;
184
- };
185
-
186
- BootstrapSwitch.prototype.disabled = function(value) {
187
- if (typeof value === "undefined") {
493
+ }
494
+ }, {
495
+ key: 'disabled',
496
+ value: function disabled(value) {
497
+ if (typeof value === 'undefined') {
188
498
  return this.options.disabled;
189
499
  }
190
- value = !!value;
191
- if (value === this.options.disabled) {
500
+ if (this.options.disabled === Boolean(value)) {
192
501
  return this.$element;
193
502
  }
194
503
  return this.toggleDisabled();
195
- };
196
-
197
- BootstrapSwitch.prototype.toggleDisabled = function() {
504
+ }
505
+ }, {
506
+ key: 'toggleDisabled',
507
+ value: function toggleDisabled() {
198
508
  this.options.disabled = !this.options.disabled;
199
- this.$element.prop("disabled", this.options.disabled);
200
- this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
509
+ this.$element.prop('disabled', this.options.disabled);
510
+ this.$wrapper.toggleClass(prvgetClass.call(this, 'disabled'));
201
511
  return this.$element;
202
- };
203
-
204
- BootstrapSwitch.prototype.readonly = function(value) {
205
- if (typeof value === "undefined") {
512
+ }
513
+ }, {
514
+ key: 'readonly',
515
+ value: function readonly(value) {
516
+ if (typeof value === 'undefined') {
206
517
  return this.options.readonly;
207
518
  }
208
- value = !!value;
209
- if (value === this.options.readonly) {
519
+ if (this.options.readonly === Boolean(value)) {
210
520
  return this.$element;
211
521
  }
212
522
  return this.toggleReadonly();
213
- };
214
-
215
- BootstrapSwitch.prototype.toggleReadonly = function() {
523
+ }
524
+ }, {
525
+ key: 'toggleReadonly',
526
+ value: function toggleReadonly() {
216
527
  this.options.readonly = !this.options.readonly;
217
- this.$element.prop("readonly", this.options.readonly);
218
- this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
528
+ this.$element.prop('readonly', this.options.readonly);
529
+ this.$wrapper.toggleClass(prvgetClass.call(this, 'readonly'));
219
530
  return this.$element;
220
- };
221
-
222
- BootstrapSwitch.prototype.indeterminate = function(value) {
223
- if (typeof value === "undefined") {
531
+ }
532
+ }, {
533
+ key: 'indeterminate',
534
+ value: function indeterminate(value) {
535
+ if (typeof value === 'undefined') {
224
536
  return this.options.indeterminate;
225
537
  }
226
- value = !!value;
227
- if (value === this.options.indeterminate) {
538
+ if (this.options.indeterminate === Boolean(value)) {
228
539
  return this.$element;
229
540
  }
230
541
  return this.toggleIndeterminate();
231
- };
232
-
233
- BootstrapSwitch.prototype.toggleIndeterminate = function() {
542
+ }
543
+ }, {
544
+ key: 'toggleIndeterminate',
545
+ value: function toggleIndeterminate() {
234
546
  this.options.indeterminate = !this.options.indeterminate;
235
- this.$element.prop("indeterminate", this.options.indeterminate);
236
- this.$wrapper.toggleClass("" + this.options.baseClass + "-indeterminate");
237
- this._containerPosition();
547
+ this.$element.prop('indeterminate', this.options.indeterminate);
548
+ this.$wrapper.toggleClass(prvgetClass.call(this, 'indeterminate'));
549
+ prvcontainerPosition.call(this);
238
550
  return this.$element;
239
- };
240
-
241
- BootstrapSwitch.prototype.inverse = function(value) {
242
- if (typeof value === "undefined") {
551
+ }
552
+ }, {
553
+ key: 'inverse',
554
+ value: function inverse(value) {
555
+ if (typeof value === 'undefined') {
243
556
  return this.options.inverse;
244
557
  }
245
- value = !!value;
246
- if (value === this.options.inverse) {
558
+ if (this.options.inverse === Boolean(value)) {
247
559
  return this.$element;
248
560
  }
249
561
  return this.toggleInverse();
250
- };
251
-
252
- BootstrapSwitch.prototype.toggleInverse = function() {
253
- var $off, $on;
254
- this.$wrapper.toggleClass("" + this.options.baseClass + "-inverse");
255
- $on = this.$on.clone(true);
256
- $off = this.$off.clone(true);
562
+ }
563
+ }, {
564
+ key: 'toggleInverse',
565
+ value: function toggleInverse() {
566
+ this.$wrapper.toggleClass(prvgetClass.call(this, 'inverse'));
567
+ var $on = this.$on.clone(true);
568
+ var $off = this.$off.clone(true);
257
569
  this.$on.replaceWith($off);
258
570
  this.$off.replaceWith($on);
259
571
  this.$on = $off;
260
572
  this.$off = $on;
261
573
  this.options.inverse = !this.options.inverse;
262
574
  return this.$element;
263
- };
264
-
265
- BootstrapSwitch.prototype.onColor = function(value) {
266
- var color;
267
- color = this.options.onColor;
268
- if (typeof value === "undefined") {
269
- return color;
575
+ }
576
+ }, {
577
+ key: 'onColor',
578
+ value: function onColor(value) {
579
+ if (typeof value === 'undefined') {
580
+ return this.options.onColor;
270
581
  }
271
- if (color != null) {
272
- this.$on.removeClass("" + this.options.baseClass + "-" + color);
582
+ if (this.options.onColor) {
583
+ this.$on.removeClass(prvgetClass.call(this, this.options.onColor));
273
584
  }
274
- this.$on.addClass("" + this.options.baseClass + "-" + value);
585
+ this.$on.addClass(prvgetClass.call(this, value));
275
586
  this.options.onColor = value;
276
587
  return this.$element;
277
- };
278
-
279
- BootstrapSwitch.prototype.offColor = function(value) {
280
- var color;
281
- color = this.options.offColor;
282
- if (typeof value === "undefined") {
283
- return color;
588
+ }
589
+ }, {
590
+ key: 'offColor',
591
+ value: function offColor(value) {
592
+ if (typeof value === 'undefined') {
593
+ return this.options.offColor;
284
594
  }
285
- if (color != null) {
286
- this.$off.removeClass("" + this.options.baseClass + "-" + color);
595
+ if (this.options.offColor) {
596
+ this.$off.removeClass(prvgetClass.call(this, this.options.offColor));
287
597
  }
288
- this.$off.addClass("" + this.options.baseClass + "-" + value);
598
+ this.$off.addClass(prvgetClass.call(this, value));
289
599
  this.options.offColor = value;
290
600
  return this.$element;
291
- };
292
-
293
- BootstrapSwitch.prototype.onText = function(value) {
294
- if (typeof value === "undefined") {
601
+ }
602
+ }, {
603
+ key: 'onText',
604
+ value: function onText(value) {
605
+ if (typeof value === 'undefined') {
295
606
  return this.options.onText;
296
607
  }
297
608
  this.$on.html(value);
298
- this._width();
299
- this._containerPosition();
609
+ prvwidth.call(this);
610
+ prvcontainerPosition.call(this);
300
611
  this.options.onText = value;
301
612
  return this.$element;
302
- };
303
-
304
- BootstrapSwitch.prototype.offText = function(value) {
305
- if (typeof value === "undefined") {
613
+ }
614
+ }, {
615
+ key: 'offText',
616
+ value: function offText(value) {
617
+ if (typeof value === 'undefined') {
306
618
  return this.options.offText;
307
619
  }
308
620
  this.$off.html(value);
309
- this._width();
310
- this._containerPosition();
621
+ prvwidth.call(this);
622
+ prvcontainerPosition.call(this);
311
623
  this.options.offText = value;
312
624
  return this.$element;
313
- };
314
-
315
- BootstrapSwitch.prototype.labelText = function(value) {
316
- if (typeof value === "undefined") {
625
+ }
626
+ }, {
627
+ key: 'labelText',
628
+ value: function labelText(value) {
629
+ if (typeof value === 'undefined') {
317
630
  return this.options.labelText;
318
631
  }
319
632
  this.$label.html(value);
320
- this._width();
633
+ prvwidth.call(this);
321
634
  this.options.labelText = value;
322
635
  return this.$element;
323
- };
324
-
325
- BootstrapSwitch.prototype.handleWidth = function(value) {
326
- if (typeof value === "undefined") {
636
+ }
637
+ }, {
638
+ key: 'handleWidth',
639
+ value: function handleWidth(value) {
640
+ if (typeof value === 'undefined') {
327
641
  return this.options.handleWidth;
328
642
  }
329
643
  this.options.handleWidth = value;
330
- this._width();
331
- this._containerPosition();
644
+ prvwidth.call(this);
645
+ prvcontainerPosition.call(this);
332
646
  return this.$element;
333
- };
334
-
335
- BootstrapSwitch.prototype.labelWidth = function(value) {
336
- if (typeof value === "undefined") {
647
+ }
648
+ }, {
649
+ key: 'labelWidth',
650
+ value: function labelWidth(value) {
651
+ if (typeof value === 'undefined') {
337
652
  return this.options.labelWidth;
338
653
  }
339
654
  this.options.labelWidth = value;
340
- this._width();
341
- this._containerPosition();
655
+ prvwidth.call(this);
656
+ prvcontainerPosition.call(this);
342
657
  return this.$element;
343
- };
344
-
345
- BootstrapSwitch.prototype.baseClass = function(value) {
658
+ }
659
+ }, {
660
+ key: 'baseClass',
661
+ value: function baseClass() {
346
662
  return this.options.baseClass;
347
- };
348
-
349
- BootstrapSwitch.prototype.wrapperClass = function(value) {
350
- if (typeof value === "undefined") {
663
+ }
664
+ }, {
665
+ key: 'wrapperClass',
666
+ value: function wrapperClass(value) {
667
+ if (typeof value === 'undefined') {
351
668
  return this.options.wrapperClass;
352
669
  }
353
- if (!value) {
354
- value = $.fn.bootstrapSwitch.defaults.wrapperClass;
355
- }
356
- this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
357
- this.$wrapper.addClass(this._getClasses(value).join(" "));
358
- this.options.wrapperClass = value;
670
+ var wrapperClass = value || $.fn.bootstrapSwitch.defaults.wrapperClass;
671
+ this.$wrapper.removeClass(prvgetClasses.call(this, this.options.wrapperClass).join(' '));
672
+ this.$wrapper.addClass(prvgetClasses.call(this, wrapperClass).join(' '));
673
+ this.options.wrapperClass = wrapperClass;
359
674
  return this.$element;
360
- };
361
-
362
- BootstrapSwitch.prototype.radioAllOff = function(value) {
363
- if (typeof value === "undefined") {
675
+ }
676
+ }, {
677
+ key: 'radioAllOff',
678
+ value: function radioAllOff(value) {
679
+ if (typeof value === 'undefined') {
364
680
  return this.options.radioAllOff;
365
681
  }
366
- value = !!value;
367
- if (value === this.options.radioAllOff) {
682
+ var val = Boolean(value);
683
+ if (this.options.radioAllOff === val) {
368
684
  return this.$element;
369
685
  }
370
- this.options.radioAllOff = value;
686
+ this.options.radioAllOff = val;
371
687
  return this.$element;
372
- };
373
-
374
- BootstrapSwitch.prototype.onInit = function(value) {
375
- if (typeof value === "undefined") {
688
+ }
689
+ }, {
690
+ key: 'onInit',
691
+ value: function onInit(value) {
692
+ if (typeof value === 'undefined') {
376
693
  return this.options.onInit;
377
694
  }
378
- if (!value) {
379
- value = $.fn.bootstrapSwitch.defaults.onInit;
380
- }
381
- this.options.onInit = value;
695
+ this.options.onInit = value || $.fn.bootstrapSwitch.defaults.onInit;
382
696
  return this.$element;
383
- };
384
-
385
- BootstrapSwitch.prototype.onSwitchChange = function(value) {
386
- if (typeof value === "undefined") {
697
+ }
698
+ }, {
699
+ key: 'onSwitchChange',
700
+ value: function onSwitchChange(value) {
701
+ if (typeof value === 'undefined') {
387
702
  return this.options.onSwitchChange;
388
703
  }
389
- if (!value) {
390
- value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
391
- }
392
- this.options.onSwitchChange = value;
704
+ this.options.onSwitchChange = value || $.fn.bootstrapSwitch.defaults.onSwitchChange;
393
705
  return this.$element;
394
- };
395
-
396
- BootstrapSwitch.prototype.destroy = function() {
397
- var $form;
398
- $form = this.$element.closest("form");
706
+ }
707
+ }, {
708
+ key: 'destroy',
709
+ value: function destroy() {
710
+ var $form = this.$element.closest('form');
399
711
  if ($form.length) {
400
- $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
712
+ $form.off('reset.bootstrapSwitch').removeData('bootstrap-switch');
401
713
  }
402
714
  this.$container.children().not(this.$element).remove();
403
- this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
715
+ this.$element.unwrap().unwrap().off('.bootstrapSwitch').removeData('bootstrap-switch');
404
716
  return this.$element;
405
- };
406
-
407
- BootstrapSwitch.prototype._width = function() {
408
- var $handles, handleWidth;
409
- $handles = this.$on.add(this.$off);
410
- $handles.add(this.$label).css("width", "");
411
- handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
412
- $handles.width(handleWidth);
413
- this.$label.width((function(_this) {
414
- return function(index, width) {
415
- if (_this.options.labelWidth !== "auto") {
416
- return _this.options.labelWidth;
417
- }
418
- if (width < handleWidth) {
419
- return handleWidth;
420
- } else {
421
- return width;
422
- }
423
- };
424
- })(this));
425
- this._handleWidth = this.$on.outerWidth();
426
- this._labelWidth = this.$label.outerWidth();
427
- this.$container.width((this._handleWidth * 2) + this._labelWidth);
428
- return this.$wrapper.width(this._handleWidth + this._labelWidth);
429
- };
430
-
431
- BootstrapSwitch.prototype._containerPosition = function(state, callback) {
432
- if (state == null) {
433
- state = this.options.state;
434
- }
435
- this.$container.css("margin-left", (function(_this) {
436
- return function() {
437
- var values;
438
- values = [0, "-" + _this._handleWidth + "px"];
439
- if (_this.options.indeterminate) {
440
- return "-" + (_this._handleWidth / 2) + "px";
441
- }
442
- if (state) {
443
- if (_this.options.inverse) {
444
- return values[1];
445
- } else {
446
- return values[0];
447
- }
448
- } else {
449
- if (_this.options.inverse) {
450
- return values[0];
451
- } else {
452
- return values[1];
453
- }
454
- }
455
- };
456
- })(this));
457
- if (!callback) {
458
- return;
459
- }
460
- return setTimeout(function() {
461
- return callback();
462
- }, 50);
463
- };
464
-
465
- BootstrapSwitch.prototype._init = function() {
466
- var init, initInterval;
467
- init = (function(_this) {
468
- return function() {
469
- _this._width();
470
- return _this._containerPosition(null, function() {
471
- if (_this.options.animate) {
472
- return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
473
- }
474
- });
475
- };
476
- })(this);
477
- if (this.$wrapper.is(":visible")) {
478
- return init();
479
- }
480
- return initInterval = window.setInterval((function(_this) {
481
- return function() {
482
- if (_this.$wrapper.is(":visible")) {
483
- init();
484
- return window.clearInterval(initInterval);
485
- }
486
- };
487
- })(this), 50);
488
- };
489
-
490
- BootstrapSwitch.prototype._elementHandlers = function() {
491
- return this.$element.on({
492
- "change.bootstrapSwitch": (function(_this) {
493
- return function(e, skip) {
494
- var state;
495
- e.preventDefault();
496
- e.stopImmediatePropagation();
497
- state = _this.$element.is(":checked");
498
- _this._containerPosition(state);
499
- if (state === _this.options.state) {
500
- return;
501
- }
502
- _this.options.state = state;
503
- _this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
504
- if (!skip) {
505
- if (_this.$element.is(":radio")) {
506
- $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
507
- }
508
- return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
509
- }
510
- };
511
- })(this),
512
- "focus.bootstrapSwitch": (function(_this) {
513
- return function(e) {
514
- e.preventDefault();
515
- return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
516
- };
517
- })(this),
518
- "blur.bootstrapSwitch": (function(_this) {
519
- return function(e) {
520
- e.preventDefault();
521
- return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
522
- };
523
- })(this),
524
- "keydown.bootstrapSwitch": (function(_this) {
525
- return function(e) {
526
- if (!e.which || _this.options.disabled || _this.options.readonly) {
527
- return;
528
- }
529
- switch (e.which) {
530
- case 37:
531
- e.preventDefault();
532
- e.stopImmediatePropagation();
533
- return _this.state(false);
534
- case 39:
535
- e.preventDefault();
536
- e.stopImmediatePropagation();
537
- return _this.state(true);
538
- }
539
- };
540
- })(this)
541
- });
542
- };
543
-
544
- BootstrapSwitch.prototype._handleHandlers = function() {
545
- this.$on.on("click.bootstrapSwitch", (function(_this) {
546
- return function(event) {
547
- event.preventDefault();
548
- event.stopPropagation();
549
- _this.state(false);
550
- return _this.$element.trigger("focus.bootstrapSwitch");
551
- };
552
- })(this));
553
- return this.$off.on("click.bootstrapSwitch", (function(_this) {
554
- return function(event) {
555
- event.preventDefault();
556
- event.stopPropagation();
557
- _this.state(true);
558
- return _this.$element.trigger("focus.bootstrapSwitch");
559
- };
560
- })(this));
561
- };
562
-
563
- BootstrapSwitch.prototype._labelHandlers = function() {
564
- return this.$label.on({
565
- "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
566
- return function(e) {
567
- if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
568
- return;
569
- }
570
- e.preventDefault();
571
- e.stopPropagation();
572
- _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
573
- if (_this.options.animate) {
574
- _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
575
- }
576
- return _this.$element.trigger("focus.bootstrapSwitch");
577
- };
578
- })(this),
579
- "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
580
- return function(e) {
581
- var difference;
582
- if (_this._dragStart == null) {
583
- return;
584
- }
585
- e.preventDefault();
586
- difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
587
- if (difference < -_this._handleWidth || difference > 0) {
588
- return;
589
- }
590
- _this._dragEnd = difference;
591
- return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
592
- };
593
- })(this),
594
- "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
595
- return function(e) {
596
- var state;
597
- if (!_this._dragStart) {
598
- return;
599
- }
600
- e.preventDefault();
601
- if (_this.options.animate) {
602
- _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
603
- }
604
- if (_this._dragEnd) {
605
- state = _this._dragEnd > -(_this._handleWidth / 2);
606
- _this._dragEnd = false;
607
- _this.state(_this.options.inverse ? !state : state);
608
- } else {
609
- _this.state(!_this.options.state);
610
- }
611
- return _this._dragStart = false;
612
- };
613
- })(this),
614
- "mouseleave.bootstrapSwitch": (function(_this) {
615
- return function(e) {
616
- return _this.$label.trigger("mouseup.bootstrapSwitch");
617
- };
618
- })(this)
619
- });
620
- };
621
-
622
- BootstrapSwitch.prototype._externalLabelHandler = function() {
623
- var $externalLabel;
624
- $externalLabel = this.$element.closest("label");
625
- return $externalLabel.on("click", (function(_this) {
626
- return function(event) {
627
- event.preventDefault();
628
- event.stopImmediatePropagation();
629
- if (event.target === $externalLabel[0]) {
630
- return _this.toggleState();
631
- }
632
- };
633
- })(this));
634
- };
635
-
636
- BootstrapSwitch.prototype._formHandler = function() {
637
- var $form;
638
- $form = this.$element.closest("form");
639
- if ($form.data("bootstrap-switch")) {
640
- return;
641
- }
642
- return $form.on("reset.bootstrapSwitch", function() {
643
- return window.setTimeout(function() {
644
- return $form.find("input").filter(function() {
645
- return $(this).data("bootstrap-switch");
646
- }).each(function() {
647
- return $(this).bootstrapSwitch("state", this.checked);
648
- });
649
- }, 1);
650
- }).data("bootstrap-switch", true);
651
- };
652
-
653
- BootstrapSwitch.prototype._getClasses = function(classes) {
654
- var c, cls, _i, _len;
655
- if (!$.isArray(classes)) {
656
- return ["" + this.options.baseClass + "-" + classes];
657
- }
658
- cls = [];
659
- for (_i = 0, _len = classes.length; _i < _len; _i++) {
660
- c = classes[_i];
661
- cls.push("" + this.options.baseClass + "-" + c);
662
- }
663
- return cls;
664
- };
665
-
666
- return BootstrapSwitch;
667
-
668
- })();
669
- $.fn.bootstrapSwitch = function() {
670
- var args, option, ret;
671
- option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
672
- ret = this;
673
- this.each(function() {
674
- var $this, data;
675
- $this = $(this);
676
- data = $this.data("bootstrap-switch");
677
- if (!data) {
678
- $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
679
- }
680
- if (typeof option === "string") {
681
- return ret = data[option].apply(data, args);
682
- }
683
- });
717
+ }
718
+ }]);
719
+
720
+ return BootstrapSwitch;
721
+ }();
722
+
723
+ function bootstrapSwitch(option) {
724
+ for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
725
+ args[_key2 - 1] = arguments[_key2];
726
+ }
727
+
728
+ function reducer(ret, next) {
729
+ var $this = $(next);
730
+ var existingData = $this.data('bootstrap-switch');
731
+ var data = existingData || new BootstrapSwitch(next, option);
732
+ if (!existingData) {
733
+ $this.data('bootstrap-switch', data);
734
+ }
735
+ if (typeof option === 'string') {
736
+ return data[option].apply(data, args);
737
+ }
684
738
  return ret;
685
- };
686
- $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
687
- return $.fn.bootstrapSwitch.defaults = {
688
- state: true,
689
- size: null,
690
- animate: true,
691
- disabled: false,
692
- readonly: false,
693
- indeterminate: false,
694
- inverse: false,
695
- radioAllOff: false,
696
- onColor: "primary",
697
- offColor: "default",
698
- onText: "ON",
699
- offText: "OFF",
700
- labelText: "&nbsp;",
701
- handleWidth: "auto",
702
- labelWidth: "auto",
703
- baseClass: "bootstrap-switch",
704
- wrapperClass: "wrapper",
705
- onInit: function() {},
706
- onSwitchChange: function() {}
707
- };
708
- })(window.jQuery, window);
709
-
710
- }).call(this);
739
+ }
740
+ return Array.prototype.reduce.call(this, reducer, this);
741
+ }
742
+
743
+ $.fn.bootstrapSwitch = bootstrapSwitch;
744
+ $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
745
+ $.fn.bootstrapSwitch.defaults = {
746
+ state: true,
747
+ size: null,
748
+ animate: true,
749
+ disabled: false,
750
+ readonly: false,
751
+ indeterminate: false,
752
+ inverse: false,
753
+ radioAllOff: false,
754
+ onColor: 'primary',
755
+ offColor: 'default',
756
+ onText: 'ON',
757
+ offText: 'OFF',
758
+ labelText: '&nbsp',
759
+ handleWidth: 'auto',
760
+ labelWidth: 'auto',
761
+ baseClass: 'bootstrap-switch',
762
+ wrapperClass: 'wrapper',
763
+ onInit: function onInit() {},
764
+ onSwitchChange: function onSwitchChange() {}
765
+ };
766
+ });