bootstrap-switch-rails 2.0.2 → 3.0.0

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
2
  SHA1:
3
- metadata.gz: 28485ebd85f1fe222c48f34124b153f4f2b19dcb
4
- data.tar.gz: b000a39d719b64c76dd6635d1eb8855a19fb0d19
3
+ metadata.gz: b569c7302489d80dee34d472835b53d43fcf085b
4
+ data.tar.gz: 7cad20420e35d893bd6e15d2ad18c8578e2b2045
5
5
  SHA512:
6
- metadata.gz: f652b71695e39f1acab9987c2fee0af4b8172c9a9a011e89692b8a07dd1878d5d992afc80e53ea36e277d1c71e21eece6c37708ae6dc9dafe3bf293e4b04a42a
7
- data.tar.gz: afce3e83412c0ad48a21907c72b556e54872343b281b39e1e3ab3903279115d2c2edd6a071a97930d4ec8b2ea3a5c18b29b4df34e52ce070d04d7e94d4f5bf0d
6
+ metadata.gz: 4abd6004218bc06371640a221c99b20f44f8a1099ec0e3bd0c692b389aed1996624b9d60135440f5548e32a574024ff610865ca9bfe99d57fbe96756d87409ab
7
+ data.tar.gz: f69c9a8b9c9420cf059434b054d42c269de0b3f6fcc46172549127123d37d4c134e35a9563aaf32db716521056f675242c624f7006827ff4a4bc41a35f6265b2
data/README.md CHANGED
@@ -52,6 +52,7 @@ See the [demo page of Mattia Larentis](http://www.bootstrap-switch.org/) for exa
52
52
 
53
53
  | Version | Notes |
54
54
  | -------:| ----------------------------------------------------------------------------------- |
55
+ | 3.0.0 | Update to v3.0.0 of the bootstrap-switch plugin |
55
56
  | 2.0.2 | Fixed issue where bootstrap 2 sass wasn't compiling (issue #7) |
56
57
  | 2.0.1 | Update to v2.0.1 of the bootstrap-switch plugin |
57
58
  | 2.0.0 | Update to v2.0 of the bootstrap-switch plugin |
@@ -1,7 +1,7 @@
1
1
  module Bootstrap
2
2
  module Switch
3
3
  module Rails
4
- VERSION = "2.0.2"
4
+ VERSION = "3.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -6,10 +6,10 @@ git clone https://github.com/nostalgiaz/bootstrap-switch.git tmp_vendor
6
6
 
7
7
  # Copy files
8
8
  echo "Copying bootstrap-switch.js"
9
- cp tmp_vendor/build/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
9
+ cp tmp_vendor/dist/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
10
10
  echo "Copying bootstrap-switch.css files"
11
- cp tmp_vendor/build/css/bootstrap2/bootstrap-switch.css vendor/assets/stylesheets/bootstrap2-switch.css.scss
12
- cp tmp_vendor/build/css/bootstrap3/bootstrap-switch.css vendor/assets/stylesheets/bootstrap3-switch.css.scss
11
+ cp tmp_vendor/dist/css/bootstrap2/bootstrap-switch.css vendor/assets/stylesheets/bootstrap2-switch.css.scss
12
+ cp tmp_vendor/dist/css/bootstrap3/bootstrap-switch.css vendor/assets/stylesheets/bootstrap3-switch.css.scss
13
13
 
14
14
  # Delete vendor repo
15
15
  echo "Removing cloned vendor repo"
@@ -1,5 +1,5 @@
1
1
  /* ========================================================================
2
- * bootstrap-switch - v2.0.1
2
+ * bootstrap-switch - v3.0.0
3
3
  * http://www.bootstrap-switch.org
4
4
  * ========================================================================
5
5
  * Copyright 2012-2013 Mattia Larentis
@@ -20,375 +20,460 @@
20
20
  */
21
21
 
22
22
  (function() {
23
- (function($) {
24
- $.fn.bootstrapSwitch = function(method) {
25
- var methods;
26
- methods = {
27
- init: function() {
28
- return this.each(function() {
29
- var $div, $element, $form, $label, $switchLeft, $switchRight, $wrapper, changeState;
30
- $element = $(this);
31
- $switchLeft = $("<span>", {
32
- "class": "switch-left",
33
- html: function() {
34
- var html, label;
35
- html = "ON";
36
- label = $element.data("on-label");
37
- if (label != null) {
38
- html = label;
39
- }
40
- return html;
23
+ var __slice = [].slice;
24
+
25
+ (function($, window) {
26
+ "use strict";
27
+ var BootstrapSwitch;
28
+ BootstrapSwitch = (function() {
29
+ BootstrapSwitch.prototype.name = "bootstrap-switch";
30
+
31
+ function BootstrapSwitch(element, options) {
32
+ if (options == null) {
33
+ options = {};
34
+ }
35
+ this.$element = $(element);
36
+ this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, options, {
37
+ state: this.$element.is(":checked"),
38
+ size: this.$element.data("size"),
39
+ animate: this.$element.data("animate"),
40
+ disabled: this.$element.is(":disabled"),
41
+ readonly: this.$element.is("[readonly]"),
42
+ onColor: this.$element.data("on-color"),
43
+ offColor: this.$element.data("off-color"),
44
+ onText: this.$element.data("on-text"),
45
+ offText: this.$element.data("off-text"),
46
+ labelText: this.$element.data("label-text"),
47
+ baseClass: this.$element.data("base-class"),
48
+ wrapperClass: this.$element.data("wrapper-class")
49
+ });
50
+ this.$wrapper = $("<div>", {
51
+ "class": (function(_this) {
52
+ return function() {
53
+ var classes;
54
+ classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass));
55
+ classes.push(_this.options.state ? "" + _this.options.baseClass + "-on" : "" + _this.options.baseClass + "-off");
56
+ if (_this.options.size != null) {
57
+ classes.push("" + _this.options.baseClass + "-" + _this.options.size);
41
58
  }
42
- });
43
- $switchRight = $("<span>", {
44
- "class": "switch-right",
45
- html: function() {
46
- var html, label;
47
- html = "OFF";
48
- label = $element.data("off-label");
49
- if (label != null) {
50
- html = label;
51
- }
52
- return html;
59
+ if (_this.options.animate) {
60
+ classes.push("" + _this.options.baseClass + "-animate");
53
61
  }
54
- });
55
- $label = $("<label>", {
56
- "for": $element.attr("id"),
57
- html: function() {
58
- var html, icon, label;
59
- html = "&nbsp;";
60
- icon = $element.data("label-icon");
61
- label = $element.data("text-label");
62
- if (icon != null) {
63
- html = "<i class=\"icon " + icon + "\"></i>";
64
- }
65
- if (label != null) {
66
- html = label;
67
- }
68
- return html;
62
+ if (_this.options.disabled) {
63
+ classes.push("" + _this.options.baseClass + "-disabled");
69
64
  }
70
- });
71
- $div = $("<div>");
72
- $wrapper = $("<div>", {
73
- "class": "has-switch",
74
- tabindex: 0
75
- });
76
- $form = $element.closest("form");
77
- changeState = function() {
78
- if ($label.hasClass("label-change-switch")) {
79
- return;
65
+ if (_this.options.readonly) {
66
+ classes.push("" + _this.options.baseClass + "-readonly");
80
67
  }
81
- return $label.trigger("mousedown").trigger("mouseup").trigger("click");
82
- };
83
- $element.data("bootstrap-switch", true);
84
- if ($element.data("on") != null) {
85
- $switchLeft.addClass("switch-" + $element.data("on"));
86
- }
87
- if ($element.data("off") != null) {
88
- $switchRight.addClass("switch-" + $element.data("off"));
89
- }
90
- $wrapper.data("animated", false);
91
- if ($element.data("animated") !== false) {
92
- $wrapper.addClass("switch-animate").data("animated", true);
93
- }
94
- $div = $element.wrap($div).parent();
95
- $wrapper = $div.wrap($wrapper).parent();
96
- if ($element.attr("class")) {
97
- $.each(["switch-mini", "switch-small", "switch-large"], function(i, cls) {
98
- if ($element.attr("class").indexOf(cls) >= 0) {
99
- return $wrapper.addClass(cls);
100
- }
101
- });
102
- }
103
- $element.before($switchLeft).before($label).before($switchRight);
104
- $wrapper.addClass($element.is(":checked") ? "switch-on" : "switch-off");
105
- if ($element.is(":disabled") || $element.is("[readonly]")) {
106
- $wrapper.addClass("disabled");
107
- }
108
- $element.on("keydown", function(e) {
109
- if (e.keyCode !== 32) {
110
- return;
68
+ if (_this.$element.attr("id")) {
69
+ classes.push("" + _this.options.baseClass + "-id-" + (_this.$element.attr("id")));
111
70
  }
112
- e.stopImmediatePropagation();
113
- e.preventDefault();
114
- return changeState();
115
- }).on("change", function(e, skip) {
116
- var isChecked, state;
117
- isChecked = $element.is(":checked");
118
- state = $wrapper.hasClass("switch-off");
71
+ return classes.join(" ");
72
+ };
73
+ })(this)()
74
+ });
75
+ this.$container = $("<div>", {
76
+ "class": "" + this.options.baseClass + "-container"
77
+ });
78
+ this.$on = $("<span>", {
79
+ html: this.options.onText,
80
+ "class": "" + this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor
81
+ });
82
+ this.$off = $("<span>", {
83
+ html: this.options.offText,
84
+ "class": "" + this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
85
+ });
86
+ this.$label = $("<label>", {
87
+ "for": this.$element.attr("id"),
88
+ html: this.options.labelText,
89
+ "class": "" + this.options.baseClass + "-label"
90
+ });
91
+ this.$element.on("init.bootstrapSwitch", (function(_this) {
92
+ return function() {
93
+ return _this.options.onInit.apply(element, arguments);
94
+ };
95
+ })(this));
96
+ this.$element.on("switchChange.bootstrapSwitch", (function(_this) {
97
+ return function() {
98
+ return _this.options.onSwitchChange.apply(element, arguments);
99
+ };
100
+ })(this));
101
+ this.$container = this.$element.wrap(this.$container).parent();
102
+ this.$wrapper = this.$container.wrap(this.$wrapper).parent();
103
+ this.$element.before(this.$on).before(this.$label).before(this.$off).trigger("init.bootstrapSwitch");
104
+ this._elementHandlers();
105
+ this._handleHandlers();
106
+ this._labelHandlers();
107
+ this._formHandler();
108
+ }
109
+
110
+ BootstrapSwitch.prototype._constructor = BootstrapSwitch;
111
+
112
+ BootstrapSwitch.prototype.state = function(value, skip) {
113
+ if (typeof value === "undefined") {
114
+ return this.options.state;
115
+ }
116
+ if (this.options.disabled || this.options.readonly) {
117
+ return this.$element;
118
+ }
119
+ value = !!value;
120
+ this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
121
+ return this.$element;
122
+ };
123
+
124
+ BootstrapSwitch.prototype.toggleState = function(skip) {
125
+ if (this.options.disabled || this.options.readonly) {
126
+ return this.$element;
127
+ }
128
+ return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
129
+ };
130
+
131
+ BootstrapSwitch.prototype.size = function(value) {
132
+ if (typeof value === "undefined") {
133
+ return this.options.size;
134
+ }
135
+ if (this.options.size != null) {
136
+ this.$wrapper.removeClass("" + this.options.baseClass + "-" + this.options.size);
137
+ }
138
+ if (value) {
139
+ this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
140
+ }
141
+ this.options.size = value;
142
+ return this.$element;
143
+ };
144
+
145
+ BootstrapSwitch.prototype.animate = function(value) {
146
+ if (typeof value === "undefined") {
147
+ return this.options.animate;
148
+ }
149
+ value = !!value;
150
+ this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-animate");
151
+ this.options.animate = value;
152
+ return this.$element;
153
+ };
154
+
155
+ BootstrapSwitch.prototype.disabled = function(value) {
156
+ if (typeof value === "undefined") {
157
+ return this.options.disabled;
158
+ }
159
+ value = !!value;
160
+ this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-disabled");
161
+ this.$element.prop("disabled", value);
162
+ this.options.disabled = value;
163
+ return this.$element;
164
+ };
165
+
166
+ BootstrapSwitch.prototype.toggleDisabled = function() {
167
+ this.$element.prop("disabled", !this.options.disabled);
168
+ this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
169
+ this.options.disabled = !this.options.disabled;
170
+ return this.$element;
171
+ };
172
+
173
+ BootstrapSwitch.prototype.readonly = function(value) {
174
+ if (typeof value === "undefined") {
175
+ return this.options.readonly;
176
+ }
177
+ value = !!value;
178
+ this.$wrapper[value ? "addClass" : "removeClass"]("" + this.options.baseClass + "-readonly");
179
+ this.$element.prop("readonly", value);
180
+ this.options.readonly = value;
181
+ return this.$element;
182
+ };
183
+
184
+ BootstrapSwitch.prototype.toggleReadonly = function() {
185
+ this.$element.prop("readonly", !this.options.readonly);
186
+ this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
187
+ this.options.readonly = !this.options.readonly;
188
+ return this.$element;
189
+ };
190
+
191
+ BootstrapSwitch.prototype.onColor = function(value) {
192
+ var color;
193
+ color = this.options.onColor;
194
+ if (typeof value === "undefined") {
195
+ return color;
196
+ }
197
+ if (color != null) {
198
+ this.$on.removeClass("" + this.options.baseClass + "-" + color);
199
+ }
200
+ this.$on.addClass("" + this.options.baseClass + "-" + value);
201
+ this.options.onColor = value;
202
+ return this.$element;
203
+ };
204
+
205
+ BootstrapSwitch.prototype.offColor = function(value) {
206
+ var color;
207
+ color = this.options.offColor;
208
+ if (typeof value === "undefined") {
209
+ return color;
210
+ }
211
+ if (color != null) {
212
+ this.$off.removeClass("" + this.options.baseClass + "-" + color);
213
+ }
214
+ this.$off.addClass("" + this.options.baseClass + "-" + value);
215
+ this.options.offColor = value;
216
+ return this.$element;
217
+ };
218
+
219
+ BootstrapSwitch.prototype.onText = function(value) {
220
+ if (typeof value === "undefined") {
221
+ return this.options.onText;
222
+ }
223
+ this.$on.html(value);
224
+ this.options.onText = value;
225
+ return this.$element;
226
+ };
227
+
228
+ BootstrapSwitch.prototype.offText = function(value) {
229
+ if (typeof value === "undefined") {
230
+ return this.options.offText;
231
+ }
232
+ this.$off.html(value);
233
+ this.options.offText = value;
234
+ return this.$element;
235
+ };
236
+
237
+ BootstrapSwitch.prototype.labelText = function(value) {
238
+ if (typeof value === "undefined") {
239
+ return this.options.labelText;
240
+ }
241
+ this.$label.html(value);
242
+ this.options.labelText = value;
243
+ return this.$element;
244
+ };
245
+
246
+ BootstrapSwitch.prototype.baseClass = function(value) {
247
+ return this.options.baseClass;
248
+ };
249
+
250
+ BootstrapSwitch.prototype.wrapperClass = function(value) {
251
+ if (typeof value === "undefined") {
252
+ return this.options.wrapperClass;
253
+ }
254
+ if (!value) {
255
+ value = $.fn.bootstrapSwitch.defaults.wrapperClass;
256
+ }
257
+ this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
258
+ this.$wrapper.addClass(this._getClasses(value).join(" "));
259
+ this.options.wrapperClass = value;
260
+ return this.$element;
261
+ };
262
+
263
+ BootstrapSwitch.prototype.destroy = function() {
264
+ var $form;
265
+ $form = this.$element.closest("form");
266
+ if ($form.length) {
267
+ $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
268
+ }
269
+ this.$container.children().not(this.$element).remove();
270
+ this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
271
+ return this.$element;
272
+ };
273
+
274
+ BootstrapSwitch.prototype._elementHandlers = function() {
275
+ return this.$element.on({
276
+ "change.bootstrapSwitch": (function(_this) {
277
+ return function(e, skip) {
278
+ var checked;
119
279
  e.preventDefault();
120
- $div.css("left", "");
121
- if (state !== isChecked) {
280
+ e.stopPropagation();
281
+ e.stopImmediatePropagation();
282
+ checked = _this.$element.is(":checked");
283
+ if (checked === _this.options.state) {
122
284
  return;
123
285
  }
124
- if (isChecked) {
125
- $wrapper.removeClass("switch-off").addClass("switch-on");
126
- } else {
127
- $wrapper.removeClass("switch-on").addClass("switch-off");
128
- }
129
- if ($wrapper.data("animated") !== false) {
130
- $wrapper.addClass("switch-animate");
131
- }
132
- if (typeof skip === "boolean" && skip) {
133
- return;
286
+ _this.options.state = checked;
287
+ _this.$wrapper.removeClass(checked ? "" + _this.options.baseClass + "-off" : "" + _this.options.baseClass + "-on").addClass(checked ? "" + _this.options.baseClass + "-on" : "" + _this.options.baseClass + "-off");
288
+ if (!skip) {
289
+ if (_this.$element.is(":radio")) {
290
+ $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
291
+ }
292
+ return _this.$element.trigger("switchChange.bootstrapSwitch", [checked]);
134
293
  }
135
- return $element.trigger("switch-change", {
136
- el: $element,
137
- value: isChecked
138
- });
139
- });
140
- $wrapper.on("keydown", function(e) {
141
- if (!e.which || $element.is(":disabled") || $element.is("[readonly]")) {
294
+ };
295
+ })(this),
296
+ "focus.bootstrapSwitch": (function(_this) {
297
+ return function(e) {
298
+ e.preventDefault();
299
+ e.stopPropagation();
300
+ e.stopImmediatePropagation();
301
+ return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
302
+ };
303
+ })(this),
304
+ "blur.bootstrapSwitch": (function(_this) {
305
+ return function(e) {
306
+ e.preventDefault();
307
+ e.stopPropagation();
308
+ e.stopImmediatePropagation();
309
+ return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
310
+ };
311
+ })(this),
312
+ "keydown.bootstrapSwitch": (function(_this) {
313
+ return function(e) {
314
+ if (!e.which || _this.options.disabled || _this.options.readonly) {
142
315
  return;
143
316
  }
144
317
  switch (e.which) {
145
318
  case 32:
146
319
  e.preventDefault();
147
- return changeState();
320
+ e.stopPropagation();
321
+ e.stopImmediatePropagation();
322
+ return _this.toggleState();
148
323
  case 37:
149
324
  e.preventDefault();
150
- if ($element.is(":checked")) {
151
- return changeState();
152
- }
153
- break;
325
+ e.stopPropagation();
326
+ e.stopImmediatePropagation();
327
+ return _this.state(false);
154
328
  case 39:
155
329
  e.preventDefault();
156
- if (!$element.is(":checked")) {
157
- return changeState();
158
- }
330
+ e.stopPropagation();
331
+ e.stopImmediatePropagation();
332
+ return _this.state(true);
333
+ }
334
+ };
335
+ })(this)
336
+ });
337
+ };
338
+
339
+ BootstrapSwitch.prototype._handleHandlers = function() {
340
+ this.$on.on("click.bootstrapSwitch", (function(_this) {
341
+ return function(e) {
342
+ _this.state(false);
343
+ return _this.$element.trigger("focus.bootstrapSwitch");
344
+ };
345
+ })(this));
346
+ return this.$off.on("click.bootstrapSwitch", (function(_this) {
347
+ return function(e) {
348
+ _this.state(true);
349
+ return _this.$element.trigger("focus.bootstrapSwitch");
350
+ };
351
+ })(this));
352
+ };
353
+
354
+ BootstrapSwitch.prototype._labelHandlers = function() {
355
+ return this.$label.on({
356
+ "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
357
+ return function(e) {
358
+ var left, percent, right;
359
+ if (!_this.drag) {
360
+ return;
159
361
  }
160
- });
161
- $switchLeft.on("click", function() {
162
- return changeState();
163
- });
164
- $switchRight.on("click", function() {
165
- return changeState();
166
- });
167
- $label.on("mousedown touchstart", function(e) {
168
- var moving;
169
- moving = false;
170
362
  e.preventDefault();
171
- e.stopImmediatePropagation();
172
- $wrapper.removeClass("switch-animate");
173
- if ($element.is(":disabled") || $element.is("[readonly]") || $element.hasClass("radio-no-uncheck")) {
174
- return $label.unbind("click");
363
+ percent = (((e.pageX || e.originalEvent.touches[0].pageX) - _this.$wrapper.offset().left) / _this.$wrapper.width()) * 100;
364
+ left = 25;
365
+ right = 75;
366
+ if (percent < left) {
367
+ percent = left;
368
+ } else if (percent > right) {
369
+ percent = right;
175
370
  }
176
- return $label.on("mousemove touchmove", function(e) {
177
- var left, percent, relativeX, right;
178
- relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $wrapper.offset().left;
179
- percent = (relativeX / $wrapper.width()) * 100;
180
- left = 25;
181
- right = 75;
182
- moving = true;
183
- if (percent < left) {
184
- percent = left;
185
- } else if (percent > right) {
186
- percent = right;
187
- }
188
- return $div.css("left", (percent - right) + "%");
189
- }).on("click touchend", function(e) {
190
- e.stopImmediatePropagation();
191
- e.preventDefault();
192
- $label.unbind("mouseleave");
193
- if (moving) {
194
- $element.prop("checked", parseInt($label.parent().css("left"), 10) > -25);
195
- } else {
196
- $element.prop("checked", !$element.is(":checked"));
197
- }
198
- moving = false;
199
- return $element.trigger("change");
200
- }).on("mouseleave", function(e) {
201
- e.preventDefault();
202
- e.stopImmediatePropagation();
203
- $label.unbind("mouseleave mousemove").trigger("mouseup");
204
- return $element.prop("checked", parseInt($label.parent().css("left"), 10) > -25).trigger("change");
205
- }).on("mouseup", function(e) {
206
- e.stopImmediatePropagation();
207
- e.preventDefault();
208
- return $label.trigger("mouseleave");
209
- });
371
+ _this.$container.css("margin-left", "" + (percent - right) + "%");
372
+ return _this.$element.trigger("focus.bootstrapSwitch");
373
+ };
374
+ })(this),
375
+ "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
376
+ return function(e) {
377
+ if (_this.drag || _this.options.disabled || _this.options.readonly) {
378
+ return;
379
+ }
380
+ e.preventDefault();
381
+ _this.drag = true;
382
+ if (_this.options.animate) {
383
+ _this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
384
+ }
385
+ return _this.$element.trigger("focus.bootstrapSwitch");
386
+ };
387
+ })(this),
388
+ "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
389
+ return function(e) {
390
+ if (!_this.drag) {
391
+ return;
392
+ }
393
+ e.preventDefault();
394
+ _this.drag = false;
395
+ _this.$element.prop("checked", parseInt(_this.$container.css("margin-left"), 10) > -(_this.$container.width() / 6)).trigger("change.bootstrapSwitch");
396
+ _this.$container.css("margin-left", "");
397
+ if (_this.options.animate) {
398
+ return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
399
+ }
400
+ };
401
+ })(this),
402
+ "mouseleave.bootstrapSwitch": (function(_this) {
403
+ return function(e) {
404
+ return _this.$label.trigger("mouseup.bootstrapSwitch");
405
+ };
406
+ })(this)
407
+ });
408
+ };
409
+
410
+ BootstrapSwitch.prototype._formHandler = function() {
411
+ var $form;
412
+ $form = this.$element.closest("form");
413
+ if ($form.data("bootstrap-switch")) {
414
+ return;
415
+ }
416
+ return $form.on("reset.bootstrapSwitch", function() {
417
+ return window.setTimeout(function() {
418
+ return $form.find("input").filter(function() {
419
+ return $(this).data("bootstrap-switch");
420
+ }).each(function() {
421
+ return $(this).bootstrapSwitch("state", false);
210
422
  });
211
- if (!$form.data("bootstrap-switch")) {
212
- return $form.bind("reset", function() {
213
- return window.setTimeout(function() {
214
- return $form.find(".has-switch").each(function() {
215
- var $input;
216
- $input = $(this).find("input");
217
- return $input.prop("checked", $input.is(":checked")).trigger("change");
218
- });
219
- }, 1);
220
- }).data("bootstrap-switch", true);
221
- }
222
- });
223
- },
224
- setDisabled: function(disabled) {
225
- var $element, $wrapper;
226
- $element = $(this);
227
- $wrapper = $element.parents(".has-switch");
228
- if (disabled) {
229
- $wrapper.addClass("disabled");
230
- $element.prop("disabled", true);
231
- } else {
232
- $wrapper.removeClass("disabled");
233
- $element.prop("disabled", false);
234
- }
235
- return $element;
236
- },
237
- toggleDisabled: function() {
238
- var $element;
239
- $element = $(this);
240
- $element.prop("disabled", !$element.is(":disabled")).parents(".has-switch").toggleClass("disabled");
241
- return $element;
242
- },
243
- isDisabled: function() {
244
- return $(this).is(":disabled");
245
- },
246
- setReadOnly: function(readonly) {
247
- var $element, $wrapper;
248
- $element = $(this);
249
- $wrapper = $element.parents(".has-switch");
250
- if (readonly) {
251
- $wrapper.addClass("disabled");
252
- $element.prop("readonly", true);
253
- } else {
254
- $wrapper.removeClass("disabled");
255
- $element.prop("readonly", false);
256
- }
257
- return $element;
258
- },
259
- toggleReadOnly: function() {
260
- var $element;
261
- $element = $(this);
262
- $element.prop("readonly", !$element.is("[readonly]")).parents(".has-switch").toggleClass("disabled");
263
- return $element;
264
- },
265
- isReadOnly: function() {
266
- return $(this).is("[readonly]");
267
- },
268
- toggleState: function(skip) {
269
- var $element;
270
- $element = $(this);
271
- $element.prop("checked", !$element.is(":checked")).trigger("change", skip);
272
- return $element;
273
- },
274
- toggleRadioState: function(skip) {
275
- var $element;
276
- $element = $(this);
277
- $element.not(":checked").prop("checked", !$element.is(":checked")).trigger("change", skip);
278
- return $element;
279
- },
280
- toggleRadioStateAllowUncheck: function(uncheck, skip) {
281
- var $element;
282
- $element = $(this);
283
- if (uncheck) {
284
- $element.not(":checked").trigger("change", skip);
285
- } else {
286
- $element.not(":checked").prop("checked", !$element.is(":checked")).trigger("change", skip);
287
- }
288
- return $element;
289
- },
290
- setState: function(value, skip) {
291
- var $element;
292
- $element = $(this);
293
- $element.prop("checked", value).trigger("change", skip);
294
- return $element;
295
- },
296
- setOnLabel: function(value) {
297
- var $element;
298
- $element = $(this);
299
- $element.siblings(".switch-left").html(value);
300
- return $element;
301
- },
302
- setOffLabel: function(value) {
303
- var $element;
304
- $element = $(this);
305
- $element.siblings(".switch-right").html(value);
306
- return $element;
307
- },
308
- setOnClass: function(value) {
309
- var $element, $switchLeft, cls;
310
- $element = $(this);
311
- $switchLeft = $element.siblings(".switch-left");
312
- cls = $element.attr("data-on");
313
- if (value == null) {
314
- return;
315
- }
316
- if (cls != null) {
317
- $switchLeft.removeClass("switch-" + cls);
318
- }
319
- $switchLeft.addClass("switch-" + value);
320
- return $element;
321
- },
322
- setOffClass: function(value) {
323
- var $element, $switchRight, cls;
324
- $element = $(this);
325
- $switchRight = $element.siblings(".switch-right");
326
- cls = $element.attr("data-off");
327
- if (value == null) {
328
- return;
329
- }
330
- if (cls != null) {
331
- $switchRight.removeClass("switch-" + cls);
332
- }
333
- $switchRight.addClass("switch-" + value);
334
- return $element;
335
- },
336
- setAnimated: function(value) {
337
- var $element, $wrapper;
338
- $element = $(this);
339
- $wrapper = $element.parents(".has-switch");
340
- if (value == null) {
341
- value = false;
342
- }
343
- $wrapper.data("animated", value).attr("data-animated", value)[$wrapper.data("animated") !== false ? "addClass" : "removeClass"]("switch-animate");
344
- return $element;
345
- },
346
- setSizeClass: function(value) {
347
- var $element, $wrapper;
348
- $element = $(this);
349
- $wrapper = $element.parents(".has-switch");
350
- $.each(["switch-mini", "switch-small", "switch-large"], function(i, cls) {
351
- return $wrapper[cls !== value ? "removeClass" : "addClass"](cls);
352
- });
353
- return $element;
354
- },
355
- setTextLabel: function(value) {
356
- var $element;
357
- $element = $(this);
358
- $element.siblings("label").html(value || "&nbsp");
359
- return $element;
360
- },
361
- setTextIcon: function(value) {
362
- var $element;
363
- $element = $(this);
364
- $element.siblings("label").html(value ? "<i class=\"icon " + value + "\"></i>" : "&nbsp;");
365
- return $element;
366
- },
367
- state: function() {
368
- return $(this).is(":checked");
369
- },
370
- destroy: function() {
371
- var $div, $element, $form;
372
- $element = $(this);
373
- $div = $element.parent();
374
- $form = $div.closest("form");
375
- $div.children().not($element).remove();
376
- $element.unwrap().unwrap().off("change");
377
- if ($form.length) {
378
- $form.off("reset").removeData("bootstrap-switch");
379
- }
380
- return $element;
423
+ }, 1);
424
+ }).data("bootstrap-switch", true);
425
+ };
426
+
427
+ BootstrapSwitch.prototype._getClasses = function(classes) {
428
+ var c, cls, _i, _len;
429
+ if (!$.isArray(classes)) {
430
+ return ["" + this.options.baseClass + "-" + classes];
431
+ }
432
+ cls = [];
433
+ for (_i = 0, _len = classes.length; _i < _len; _i++) {
434
+ c = classes[_i];
435
+ cls.push("" + this.options.baseClass + "-" + c);
381
436
  }
437
+ return cls;
382
438
  };
383
- if (methods[method]) {
384
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
385
- }
386
- if (typeof method === "object" || !method) {
387
- return methods.init.apply(this, arguments);
388
- }
389
- return $.error("Method " + method + " does not exist!");
439
+
440
+ return BootstrapSwitch;
441
+
442
+ })();
443
+ $.fn.bootstrapSwitch = function() {
444
+ var args, option, ret;
445
+ option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
446
+ ret = this;
447
+ this.each(function() {
448
+ var $this, data;
449
+ $this = $(this);
450
+ data = $this.data("bootstrap-switch");
451
+ if (!data) {
452
+ $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
453
+ }
454
+ if (typeof option === "string") {
455
+ return ret = data[option].apply(data, args);
456
+ }
457
+ });
458
+ return ret;
459
+ };
460
+ $.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
461
+ return $.fn.bootstrapSwitch.defaults = {
462
+ state: true,
463
+ size: null,
464
+ animate: true,
465
+ disabled: false,
466
+ readonly: false,
467
+ onColor: "primary",
468
+ offColor: "default",
469
+ onText: "ON",
470
+ offText: "OFF",
471
+ labelText: "&nbsp;",
472
+ baseClass: "bootstrap-switch",
473
+ wrapperClass: "wrapper",
474
+ onInit: function() {},
475
+ onSwitchChange: function() {}
390
476
  };
391
- return this;
392
- })(jQuery);
477
+ })(window.jQuery, window);
393
478
 
394
479
  }).call(this);