bootstrap-switch-rails 1.4.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,18 +1,18 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- _source
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ _source
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in genericons.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in genericons.gemspec
4
+ gemspec
@@ -1,22 +1,22 @@
1
- Copyright (c) 2013 Manuel van Rijn
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2013 Manuel van Rijn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,55 +1,62 @@
1
- # bootstrap-switch-rails [![Gem Version](https://badge.fury.io/rb/bootstrap-switch-rails.png)](http://badge.fury.io/rb/bootstrap-switch-rails)
2
-
3
- bootstrap-switch-rails provides the [bootstrap-switch](https://github.com/nostalgiaz/bootstrap-switch)
4
- plugin as a Rails engine to use it within the asset pipeline.
5
-
6
- ## Installation
7
-
8
- Add this to your Gemfile:
9
-
10
- ```ruby
11
- gem "bootstrap-switch-rails"
12
- ```
13
-
14
- and run `bundle install`.
15
-
16
- ## Usage
17
-
18
- In your `application.js`, include the following:
19
-
20
- ```js
21
- //= require bootstrap-switch
22
- ```
23
-
24
- In your `application.css`, include the following:
25
-
26
- ```css
27
- *= require bootstrap-switch
28
- ```
29
-
30
- ## Examples
31
-
32
- See the [demo page of Mattia Larentis](http://www.larentis.eu/switch/) for examples how to use the plugin
33
-
34
- ## Changes
35
-
36
- | Version | Notes |
37
- |---------+-------------------------------------------------------------------------------------|
38
- | 1.4.0 | Update to v1.4 of the bootstrap-switch plugin and make version equal to the plugin |
39
- | 0.1.1 | Update to v1.3 of the bootstrap-switch plugin |
40
- | 0.1.0 | Initial release |
41
-
42
- ## License
43
-
44
- * The [bootstrap-switch](http://genericons.com/) plugin is licensed under the
45
- [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
46
- * The [bootstrap-switch-rails](https://github.com/manuelvanrijn/bootstrap-switch-rails) project is
47
- licensed under the [MIT License](http://opensource.org/licenses/mit-license.html)
48
-
49
- ## Contributing
50
-
51
- 1. Fork it
52
- 2. Create your feature branch (`git checkout -b my-new-feature`)
53
- 3. Commit your changes (`git commit -am 'Add some feature'`)
54
- 4. Push to the branch (`git push origin my-new-feature`)
55
- 5. Create new Pull Request
1
+ # bootstrap-switch-rails [![Gem Version](https://badge.fury.io/rb/bootstrap-switch-rails.png)](http://badge.fury.io/rb/bootstrap-switch-rails)
2
+
3
+ bootstrap-switch-rails provides the [bootstrap-switch](http://www.bootstrap-switch.org/)
4
+ plugin as a Rails engine to use it within the asset pipeline.
5
+
6
+ ## Installation
7
+
8
+ Add this to your Gemfile:
9
+
10
+ ```ruby
11
+ gem "bootstrap-switch-rails"
12
+ ```
13
+
14
+ and run `bundle install`.
15
+
16
+ ## Usage
17
+
18
+ In your `application.js`, include the following:
19
+
20
+ ```js
21
+ //= require bootstrap-switch
22
+ ```
23
+
24
+ In your `application.css`, include the following:
25
+
26
+ ```css
27
+ *= require bootstrap-switch
28
+ ```
29
+
30
+ or in any `SASS` file, include the following:
31
+
32
+ ```css
33
+ @import "bootstrap-switch";
34
+ ```
35
+
36
+ ## Examples
37
+
38
+ See the [demo page of Mattia Larentis](http://www.bootstrap-switch.org/) for examples how to use the plugin
39
+
40
+ ## Changes
41
+
42
+ | Version | Notes |
43
+ | -------:| ----------------------------------------------------------------------------------- |
44
+ | 1.8.0 | Update to v1.8 of the bootstrap-switch plugin |
45
+ | 1.4.0 | Update to v1.4 of the bootstrap-switch plugin and make version equal to the plugin |
46
+ | 0.1.1 | Update to v1.3 of the bootstrap-switch plugin |
47
+ | 0.1.0 | Initial release |
48
+
49
+ ## License
50
+
51
+ * The [bootstrap-switch](http://www.bootstrap-switch.org/) plugin is licensed under the
52
+ [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
53
+ * The [bootstrap-switch-rails](https://github.com/manuelvanrijn/bootstrap-switch-rails) project is
54
+ licensed under the [MIT License](http://opensource.org/licenses/mit-license.html)
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1,23 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'bootstrap-switch-rails/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "bootstrap-switch-rails"
8
- spec.version = Bootstrap::Switch::Rails::VERSION
9
- spec.authors = ["Manuel van Rijn"]
10
- spec.email = ["manuel@manuelles.nl"]
11
- spec.description = %q{A small gem for putting bootstrap-switch into the Rails asset pipeline}
12
- spec.summary = %q{an asset gemification of the bootstrap-switch plugin}
13
- spec.homepage = "https://github.com/manuelvanrijn/bootstrap-switch-rails"
14
- spec.license = "MIT, Apache License v2.0"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bootstrap-switch-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bootstrap-switch-rails"
8
+ spec.version = Bootstrap::Switch::Rails::VERSION
9
+ spec.authors = ["Manuel van Rijn"]
10
+ spec.email = ["manuel@manuelles.nl"]
11
+ spec.description = %q{A small gem for putting bootstrap-switch into the Rails asset pipeline}
12
+ spec.summary = %q{an asset gemification of the bootstrap-switch plugin}
13
+ spec.homepage = "https://github.com/manuelvanrijn/bootstrap-switch-rails"
14
+ spec.license = "MIT, Apache License v2.0"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -1,14 +1,14 @@
1
- require "rails"
2
- require "bootstrap-switch-rails/version"
3
-
4
- module Bootstrap
5
- module Switch
6
- module Rails
7
- if ::Rails.version < "3.1"
8
- require "bootstrap-switch-rails/railtie"
9
- else
10
- require "bootstrap-switch-rails/engine"
11
- end
12
- end
13
- end
14
- end
1
+ require "rails"
2
+ require "bootstrap-switch-rails/version"
3
+
4
+ module Bootstrap
5
+ module Switch
6
+ module Rails
7
+ if ::Rails.version < "3.1"
8
+ require "bootstrap-switch-rails/railtie"
9
+ else
10
+ require "bootstrap-switch-rails/engine"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,8 @@
1
- module Bootstrap
2
- module Switch
3
- module Rails
4
- class Engine < ::Rails::Engine
5
- end
6
- end
7
- end
8
- end
1
+ module Bootstrap
2
+ module Switch
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
- module Bootstrap
2
- module Switch
3
- module Rails
4
- class Railtie < ::Rails::Railtie; end
5
- end
6
- end
7
- end
1
+ module Bootstrap
2
+ module Switch
3
+ module Rails
4
+ class Railtie < ::Rails::Railtie; end
5
+ end
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
- module Bootstrap
2
- module Switch
3
- module Rails
4
- VERSION = "1.4.0"
5
- end
6
- end
7
- end
1
+ module Bootstrap
2
+ module Switch
3
+ module Rails
4
+ VERSION = "1.8.1"
5
+ end
6
+ end
7
+ end
@@ -1,17 +1,17 @@
1
- #!/bin/bash
2
-
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
6
-
7
- # Copy files
8
- echo "Copying bootstrap-switch.js"
9
- cp tmp_vendor/static/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
10
- echo "Copying bootstrap-switch.css"
11
- cp tmp_vendor/static/stylesheets/bootstrap-switch.css vendor/assets/stylesheets/bootstrap-switch.css
12
-
13
- # Delete vendor repo
14
- echo "Removing cloned vendor repo"
15
- rm -rf tmp_vendor
16
-
17
- echo "Finished... You'll need to commit the changes. You should consider updating the changelog and gem version number"
1
+ #!/bin/sh
2
+
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
6
+
7
+ # Copy files
8
+ echo "Copying bootstrap-switch.js"
9
+ cp tmp_vendor/static/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
10
+ echo "Copying bootstrap-switch.css"
11
+ cp tmp_vendor/static/stylesheets/bootstrap-switch.css vendor/assets/stylesheets/bootstrap-switch.css.scss
12
+
13
+ # Delete vendor repo
14
+ echo "Removing cloned vendor repo"
15
+ rm -rf tmp_vendor
16
+
17
+ echo "Finished... You'll need to commit the changes. You should consider updating the changelog and gem version number"
@@ -1,264 +1,383 @@
1
- /* ============================================================
2
- * bootstrapSwitch v1.4 by Larentis Mattia @spiritualGuru
3
- * http://www.larentis.eu/switch/
4
- * ============================================================
5
- * Licensed under the Apache License, Version 2.0
6
- * http://www.apache.org/licenses/LICENSE-2.0
7
- * ============================================================ */
8
-
9
- !function ($) {
10
- "use strict";
11
-
12
- $.fn['bootstrapSwitch'] = function (method) {
13
- var methods = {
14
- init: function () {
15
- return this.each(function () {
16
- var $element = $(this)
17
- , $div
18
- , $switchLeft
19
- , $switchRight
20
- , $label
21
- , myClasses = ""
22
- , classes = $element.attr('class')
23
- , color
24
- , moving
25
- , onLabel = "ON"
26
- , offLabel = "OFF"
27
- , icon = false;
28
-
29
- $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
30
- if (classes.indexOf(el) >= 0)
31
- myClasses = el;
32
- });
33
-
34
- $element.addClass('has-switch');
35
-
36
- if ($element.data('on') !== undefined)
37
- color = "switch-" + $element.data('on');
38
-
39
- if ($element.data('on-label') !== undefined)
40
- onLabel = $element.data('on-label');
41
-
42
- if ($element.data('off-label') !== undefined)
43
- offLabel = $element.data('off-label');
44
-
45
- if ($element.data('icon') !== undefined)
46
- icon = $element.data('icon');
47
-
48
- $switchLeft = $('<span>')
49
- .addClass("switch-left")
50
- .addClass(myClasses)
51
- .addClass(color)
52
- .html(onLabel);
53
-
54
- color = '';
55
- if ($element.data('off') !== undefined)
56
- color = "switch-" + $element.data('off');
57
-
58
- $switchRight = $('<span>')
59
- .addClass("switch-right")
60
- .addClass(myClasses)
61
- .addClass(color)
62
- .html(offLabel);
63
-
64
- $label = $('<label>')
65
- .html("&nbsp;")
66
- .addClass(myClasses)
67
- .attr('for', $element.find('input').attr('id'));
68
-
69
- if (icon) {
70
- $label.html('<i class="icon icon-' + icon + '"></i>');
71
- }
72
-
73
- $div = $element.find(':checkbox').wrap($('<div>')).parent().data('animated', false);
74
-
75
- if ($element.data('animated') !== false)
76
- $div.addClass('switch-animate').data('animated', true);
77
-
78
- $div
79
- .append($switchLeft)
80
- .append($label)
81
- .append($switchRight);
82
-
83
- $element.find('>div').addClass(
84
- $element.find('input').is(':checked') ? 'switch-on' : 'switch-off'
85
- );
86
-
87
- if ($element.find('input').is(':disabled'))
88
- $(this).addClass('deactivate');
89
-
90
- var changeStatus = function ($this) {
91
- $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
92
- };
93
-
94
- $element.on('keydown', function (e) {
95
- if (e.keyCode === 32) {
96
- e.stopImmediatePropagation();
97
- e.preventDefault();
98
- changeStatus($(e.target).find('span:first'));
99
- }
100
- });
101
-
102
- $switchLeft.on('click', function (e) {
103
- changeStatus($(this));
104
- });
105
-
106
- $switchRight.on('click', function (e) {
107
- changeStatus($(this));
108
- });
109
-
110
- $element.find('input').on('change', function (e, skipOnChange) {
111
- var $this = $(this)
112
- , $element = $this.parent()
113
- , thisState = $this.is(':checked')
114
- , state = $element.is('.switch-off');
115
-
116
- e.preventDefault();
117
-
118
- $element.css('left', '');
119
-
120
- if (state === thisState) {
121
-
122
- if (thisState)
123
- $element.removeClass('switch-off').addClass('switch-on');
124
- else $element.removeClass('switch-on').addClass('switch-off');
125
-
126
- if ($element.data('animated') !== false)
127
- $element.addClass("switch-animate");
128
-
129
- if (typeof skipOnChange === 'boolean' && skipOnChange)
130
- return;
131
-
132
- $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
133
- }
134
- });
135
-
136
- $element.find('label').on('mousedown touchstart', function (e) {
137
- var $this = $(this);
138
- moving = false;
139
-
140
- e.preventDefault();
141
- e.stopImmediatePropagation();
142
-
143
- $this.closest('div').removeClass('switch-animate');
144
-
145
- if ($this.closest('.has-switch').is('.deactivate'))
146
- $this.unbind('click');
147
- else {
148
- $this.on('mousemove touchmove', function (e) {
149
- var $element = $(this).closest('.switch')
150
- , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
151
- , percent = (relativeX / $element.width()) * 100
152
- , left = 25
153
- , right = 75;
154
-
155
- moving = true;
156
-
157
- if (percent < left)
158
- percent = left;
159
- else if (percent > right)
160
- percent = right;
161
-
162
- $element.find('>div').css('left', (percent - right) + "%")
163
- });
164
-
165
- $this.on('click touchend', function (e) {
166
- var $this = $(this)
167
- , $target = $(e.target)
168
- , $myCheckBox = $target.siblings('input');
169
-
170
- e.stopImmediatePropagation();
171
- e.preventDefault();
172
-
173
- $this.unbind('mouseleave');
174
-
175
- if (moving)
176
- $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
177
- else $myCheckBox.prop("checked", !$myCheckBox.is(":checked"));
178
-
179
- moving = false;
180
- $myCheckBox.trigger('change');
181
- });
182
-
183
- $this.on('mouseleave', function (e) {
184
- var $this = $(this)
185
- , $myCheckBox = $this.siblings('input');
186
-
187
- e.preventDefault();
188
- e.stopImmediatePropagation();
189
-
190
- $this.unbind('mouseleave');
191
- $this.trigger('mouseup');
192
-
193
- $myCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
194
- });
195
-
196
- $this.on('mouseup', function (e) {
197
- e.stopImmediatePropagation();
198
- e.preventDefault();
199
-
200
- $(this).unbind('mousemove');
201
- });
202
- }
203
- });
204
- }
205
- );
206
- },
207
- toggleActivation: function () {
208
- var $this = $(this);
209
-
210
- $this.toggleClass('deactivate');
211
- $this.find('input:checkbox').attr('disabled', $this.is('.deactivate'));
212
- },
213
- isActive: function () {
214
- return !$(this).hasClass('deactivate');
215
- },
216
- setActive: function (active) {
217
- var $this = $(this);
218
-
219
- if (active) {
220
- $this.removeClass('deactivate');
221
- $this.find('input:checkbox').attr('disabled', false);
222
- }
223
- else {
224
- $this.addClass('deactivate');
225
- $this.find('input:checkbox').attr('disabled', true);
226
- }
227
- },
228
- toggleState: function (skipOnChange) {
229
- var $input = $(this).find('input:checkbox');
230
- $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
231
- },
232
- setState: function (value, skipOnChange) {
233
- $(this).find('input:checkbox').prop('checked', value).trigger('change', skipOnChange);
234
- },
235
- status: function () {
236
- return $(this).find('input:checkbox').is(':checked');
237
- },
238
- destroy: function () {
239
- var $div = $(this).find('div')
240
- , $checkbox;
241
-
242
- $div.find(':not(input:checkbox)').remove();
243
-
244
- $checkbox = $div.children();
245
- $checkbox.unwrap().unwrap();
246
-
247
- $checkbox.unbind('change');
248
-
249
- return $checkbox;
250
- }
251
- };
252
-
253
- if (methods[method])
254
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
255
- else if (typeof method === 'object' || !method)
256
- return methods.init.apply(this, arguments);
257
- else
258
- $.error('Method ' + method + ' does not exist!');
259
- };
260
- }(jQuery);
261
-
262
- $(function () {
263
- $('.switch')['bootstrapSwitch']();
264
- });
1
+ /*! ============================================================
2
+ * bootstrapSwitch v1.8 by Larentis Mattia @SpiritualGuru
3
+ * http://www.larentis.eu/
4
+ *
5
+ * Enhanced for radiobuttons by Stein, Peter @BdMdesigN
6
+ * http://www.bdmdesign.org/
7
+ *
8
+ * Project site:
9
+ * http://www.larentis.eu/switch/
10
+ * ============================================================
11
+ * Licensed under the Apache License, Version 2.0
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ * ============================================================ */
14
+
15
+ !function ($) {
16
+ "use strict";
17
+
18
+ $.fn['bootstrapSwitch'] = function (method) {
19
+ var inputSelector = 'input[type!="hidden"]';
20
+ var methods = {
21
+ init: function () {
22
+ return this.each(function () {
23
+ var $element = $(this)
24
+ , $div
25
+ , $switchLeft
26
+ , $switchRight
27
+ , $label
28
+ , $form = $element.closest('form')
29
+ , myClasses = ""
30
+ , classes = $element.attr('class')
31
+ , color
32
+ , moving
33
+ , onLabel = "ON"
34
+ , offLabel = "OFF"
35
+ , icon = false
36
+ , textLabel = false;
37
+
38
+ $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
39
+ if (classes.indexOf(el) >= 0)
40
+ myClasses = el;
41
+ });
42
+
43
+ $element.addClass('has-switch');
44
+
45
+ if ($element.data('on') !== undefined)
46
+ color = "switch-" + $element.data('on');
47
+
48
+ if ($element.data('on-label') !== undefined)
49
+ onLabel = $element.data('on-label');
50
+
51
+ if ($element.data('off-label') !== undefined)
52
+ offLabel = $element.data('off-label');
53
+
54
+ if ($element.data('label-icon') !== undefined)
55
+ icon = $element.data('label-icon');
56
+
57
+ if ($element.data('text-label') !== undefined)
58
+ textLabel = $element.data('text-label');
59
+
60
+ $switchLeft = $('<span>')
61
+ .addClass("switch-left")
62
+ .addClass(myClasses)
63
+ .addClass(color)
64
+ .html(onLabel);
65
+
66
+ color = '';
67
+ if ($element.data('off') !== undefined)
68
+ color = "switch-" + $element.data('off');
69
+
70
+ $switchRight = $('<span>')
71
+ .addClass("switch-right")
72
+ .addClass(myClasses)
73
+ .addClass(color)
74
+ .html(offLabel);
75
+
76
+ $label = $('<label>')
77
+ .html("&nbsp;")
78
+ .addClass(myClasses)
79
+ .attr('for', $element.find(inputSelector).attr('id'));
80
+
81
+ if (icon) {
82
+ $label.html('<i class="icon ' + icon + '"></i>');
83
+ }
84
+
85
+ if (textLabel) {
86
+ $label.html('' + textLabel + '');
87
+ }
88
+
89
+ $div = $element.find(inputSelector).wrap($('<div>')).parent().data('animated', false);
90
+
91
+ if ($element.data('animated') !== false)
92
+ $div.addClass('switch-animate').data('animated', true);
93
+
94
+ $div
95
+ .append($switchLeft)
96
+ .append($label)
97
+ .append($switchRight);
98
+
99
+ $element.find('>div').addClass(
100
+ $element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off'
101
+ );
102
+
103
+ if ($element.find(inputSelector).is(':disabled'))
104
+ $(this).addClass('deactivate');
105
+
106
+ var changeStatus = function ($this) {
107
+ if ($element.parent('label').is('.label-change-switch')) {
108
+
109
+ } else {
110
+ $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
111
+ }
112
+ };
113
+
114
+ $element.on('keydown', function (e) {
115
+ if (e.keyCode === 32) {
116
+ e.stopImmediatePropagation();
117
+ e.preventDefault();
118
+ changeStatus($(e.target).find('span:first'));
119
+ }
120
+ });
121
+
122
+ $switchLeft.on('click', function (e) {
123
+ changeStatus($(this));
124
+ });
125
+
126
+ $switchRight.on('click', function (e) {
127
+ changeStatus($(this));
128
+ });
129
+
130
+ $element.find(inputSelector).on('change', function (e, skipOnChange) {
131
+ var $this = $(this)
132
+ , $element = $this.parent()
133
+ , thisState = $this.is(':checked')
134
+ , state = $element.is('.switch-off');
135
+
136
+ e.preventDefault();
137
+
138
+ $element.css('left', '');
139
+
140
+ if (state === thisState) {
141
+
142
+ if (thisState)
143
+ $element.removeClass('switch-off').addClass('switch-on');
144
+ else $element.removeClass('switch-on').addClass('switch-off');
145
+
146
+ if ($element.data('animated') !== false)
147
+ $element.addClass("switch-animate");
148
+
149
+ if (typeof skipOnChange === 'boolean' && skipOnChange)
150
+ return;
151
+
152
+ $element.parent().trigger('switch-change', {'el': $this, 'value': thisState})
153
+ }
154
+ });
155
+
156
+ $element.find('label').on('mousedown touchstart', function (e) {
157
+ var $this = $(this);
158
+ moving = false;
159
+
160
+ e.preventDefault();
161
+ e.stopImmediatePropagation();
162
+
163
+ $this.closest('div').removeClass('switch-animate');
164
+
165
+ if ($this.closest('.has-switch').is('.deactivate')) {
166
+ $this.unbind('click');
167
+ } else if ($this.closest('.switch-on').parent().is('.radio-no-uncheck')) {
168
+ $this.unbind('click');
169
+ } else {
170
+ $this.on('mousemove touchmove', function (e) {
171
+ var $element = $(this).closest('.make-switch')
172
+ , relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left
173
+ , percent = (relativeX / $element.width()) * 100
174
+ , left = 25
175
+ , right = 75;
176
+
177
+ moving = true;
178
+
179
+ if (percent < left)
180
+ percent = left;
181
+ else if (percent > right)
182
+ percent = right;
183
+
184
+ $element.find('>div').css('left', (percent - right) + "%")
185
+ });
186
+
187
+ $this.on('click touchend', function (e) {
188
+ var $this = $(this)
189
+ , $target = $(e.target)
190
+ , $myRadioCheckBox = $target.siblings('input');
191
+
192
+ e.stopImmediatePropagation();
193
+ e.preventDefault();
194
+
195
+ $this.unbind('mouseleave');
196
+
197
+ if (moving)
198
+ $myRadioCheckBox.prop('checked', !(parseInt($this.parent().css('left')) < -25));
199
+ else
200
+ $myRadioCheckBox.prop("checked", !$myRadioCheckBox.is(":checked"));
201
+
202
+ moving = false;
203
+ $myRadioCheckBox.trigger('change');
204
+ });
205
+
206
+ $this.on('mouseleave', function (e) {
207
+ var $this = $(this)
208
+ , $myInputBox = $this.siblings('input');
209
+
210
+ e.preventDefault();
211
+ e.stopImmediatePropagation();
212
+
213
+ $this.unbind('mouseleave');
214
+ $this.trigger('mouseup');
215
+
216
+ $myInputBox.prop('checked', !(parseInt($this.parent().css('left')) < -25)).trigger('change');
217
+ });
218
+
219
+ $this.on('mouseup', function (e) {
220
+ e.stopImmediatePropagation();
221
+ e.preventDefault();
222
+
223
+ $(this).unbind('mousemove');
224
+ });
225
+ }
226
+ });
227
+
228
+ if ($form.data('bootstrapSwitch') !== 'injected') {
229
+ $form.bind('reset', function () {
230
+ setTimeout(function () {
231
+ $form.find('.make-switch').each(function () {
232
+ var $input = $(this).find(inputSelector);
233
+
234
+ $input.prop('checked', $input.is(':checked')).trigger('change');
235
+ });
236
+ }, 1);
237
+ });
238
+ $form.data('bootstrapSwitch', 'injected');
239
+ }
240
+ }
241
+ );
242
+ },
243
+ toggleActivation: function () {
244
+ var $this = $(this);
245
+
246
+ $this.toggleClass('deactivate');
247
+ $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
248
+ },
249
+ isActive: function () {
250
+ return !$(this).hasClass('deactivate');
251
+ },
252
+ setActive: function (active) {
253
+ var $this = $(this);
254
+
255
+ if (active) {
256
+ $this.removeClass('deactivate');
257
+ $this.find(inputSelector).removeAttr('disabled');
258
+ }
259
+ else {
260
+ $this.addClass('deactivate');
261
+ $this.find(inputSelector).attr('disabled', 'disabled');
262
+ }
263
+ },
264
+ toggleState: function (skipOnChange) {
265
+ var $input = $(this).find(':checkbox');
266
+ $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
267
+ },
268
+ toggleRadioState: function (skipOnChange) {
269
+ var $radioinput = $(this).find(':radio');
270
+ $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
271
+ },
272
+ toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
273
+ var $radioinput = $(this).find(':radio');
274
+ if (uncheck) {
275
+ $radioinput.not(':checked').trigger('change', skipOnChange);
276
+ }
277
+ else {
278
+ $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
279
+ }
280
+ },
281
+ setState: function (value, skipOnChange) {
282
+ $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
283
+ },
284
+ setOnLabel: function (value) {
285
+ var $switchLeft = $(this).find(".switch-left");
286
+ $switchLeft.html(value);
287
+ },
288
+ setOffLabel: function (value) {
289
+ var $switchRight = $(this).find(".switch-right");
290
+ $switchRight.html(value);
291
+ },
292
+ setOnClass: function (value) {
293
+ var $switchLeft = $(this).find(".switch-left");
294
+ var color = '';
295
+ if (value !== undefined) {
296
+ if ($(this).attr('data-on') !== undefined) {
297
+ color = "switch-" + $(this).attr('data-on')
298
+ }
299
+ $switchLeft.removeClass(color);
300
+ color = "switch-" + value;
301
+ $switchLeft.addClass(color);
302
+ }
303
+ },
304
+ setOffClass: function (value) {
305
+ var $switchRight = $(this).find(".switch-right");
306
+ var color = '';
307
+ if (value !== undefined) {
308
+ if ($(this).attr('data-off') !== undefined) {
309
+ color = "switch-" + $(this).attr('data-off')
310
+ }
311
+ $switchRight.removeClass(color);
312
+ color = "switch-" + value;
313
+ $switchRight.addClass(color);
314
+ }
315
+ },
316
+ setAnimated: function (value) {
317
+ var $element = $(this).find(inputSelector).parent();
318
+ if (value === undefined) value = false;
319
+ $element.data('animated', value);
320
+ $element.attr('data-animated', value);
321
+
322
+ if ($element.data('animated') !== false) {
323
+ $element.addClass("switch-animate");
324
+ } else {
325
+ $element.removeClass("switch-animate");
326
+ }
327
+ },
328
+ setSizeClass: function (value) {
329
+ var $element = $(this);
330
+ var $switchLeft = $element.find(".switch-left");
331
+ var $switchRight = $element.find(".switch-right");
332
+ var $label = $element.find("label");
333
+ $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
334
+ if (el !== value) {
335
+ $switchLeft.removeClass(el)
336
+ $switchRight.removeClass(el);
337
+ $label.removeClass(el);
338
+ } else {
339
+ $switchLeft.addClass(el);
340
+ $switchRight.addClass(el);
341
+ $label.addClass(el);
342
+ }
343
+ });
344
+ },
345
+ status: function () {
346
+ return $(this).find(inputSelector).is(':checked');
347
+ },
348
+ destroy: function () {
349
+ var $element = $(this)
350
+ , $div = $element.find('div')
351
+ , $form = $element.closest('form')
352
+ , $inputbox;
353
+
354
+ $div.find(':not(input)').remove();
355
+
356
+ $inputbox = $div.children();
357
+ $inputbox.unwrap().unwrap();
358
+
359
+ $inputbox.unbind('change');
360
+
361
+ if ($form) {
362
+ $form.unbind('reset');
363
+ $form.removeData('bootstrapSwitch');
364
+ }
365
+
366
+ return $inputbox;
367
+ }
368
+ };
369
+
370
+ if (methods[method])
371
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
372
+ else if (typeof method === 'object' || !method)
373
+ return methods.init.apply(this, arguments);
374
+ else
375
+ $.error('Method ' + method + ' does not exist!');
376
+ };
377
+ }(jQuery);
378
+
379
+ (function ($) {
380
+ $(function () {
381
+ $('.make-switch')['bootstrapSwitch']();
382
+ });
383
+ })(jQuery);