bootstrap-switch-rails 1.8.1 → 1.9.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4150236ba468a058a3f97c877f745fd84b58be7a
4
+ data.tar.gz: 69c7c48ee226f5914da76053eb1fb4f77d7e1adc
5
+ SHA512:
6
+ metadata.gz: bf84359c4057da6fc3686fba966e56012d00b51bb67536d50a65d92b98c2ad0dc6c55c0d0fa74d3510550996c60a0db4d14f95c88532e2e41559618d75af99a2
7
+ data.tar.gz: c37ba651802222aa99e0bf57787b821aa1090aaa35c8b75885067d66aa2de53f393fd0113e38da8a3f8f70d331de53570213cdb6c38404d32cd4c84f02c3eb7a
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,62 +1,74 @@
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
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
+ /*
28
+ * for bootstrap3
29
+ *= require bootstrap3-switch
30
+ *
31
+ * or for bootstrap2
32
+ *= require bootstrap2-switch
33
+ */
34
+
35
+ *= require bootstrap-switch
36
+ ```
37
+
38
+ or in any `SASS` file, include the following:
39
+
40
+ ```css
41
+ /* for bootstrap3 */
42
+ @import "bootstrap3-switch";
43
+ /* or for bootstrap2 */
44
+ @import "bootstrap2-switch";
45
+ ```
46
+
47
+ ## Examples
48
+
49
+ See the [demo page of Mattia Larentis](http://www.bootstrap-switch.org/) for examples how to use the plugin
50
+
51
+ ## Changes
52
+
53
+ | Version | Notes |
54
+ | -------:| ----------------------------------------------------------------------------------- |
55
+ | 1.9.0 | Update to v1.9 of the bootstrap-switch plugin |
56
+ | 1.8.0 | Update to v1.8 of the bootstrap-switch plugin |
57
+ | 1.4.0 | Update to v1.4 of the bootstrap-switch plugin and make version equal to the plugin |
58
+ | 0.1.1 | Update to v1.3 of the bootstrap-switch plugin |
59
+ | 0.1.0 | Initial release |
60
+
61
+ ## License
62
+
63
+ * The [bootstrap-switch](http://www.bootstrap-switch.org/) plugin is licensed under the
64
+ [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
65
+ * The [bootstrap-switch-rails](https://github.com/manuelvanrijn/bootstrap-switch-rails) project is
66
+ licensed under the [MIT License](http://opensource.org/licenses/mit-license.html)
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 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.8.1"
5
- end
6
- end
7
- end
1
+ module Bootstrap
2
+ module Switch
3
+ module Rails
4
+ VERSION = "1.9.0"
5
+ end
6
+ end
7
+ end
@@ -1,17 +1,18 @@
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
+ #!/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/build/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
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
13
+
14
+ # Delete vendor repo
15
+ echo "Removing cloned vendor repo"
16
+ rm -rf tmp_vendor
17
+
18
+ echo "Finished... You'll need to commit the changes. You should consider updating the changelog and gem version number"
@@ -1,383 +1,420 @@
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);
1
+ /*! ============================================================
2
+ * bootstrap-switch v1.9.0 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
+
22
+ init: function () {
23
+ return this.each(function () {
24
+ var $element = $(this),
25
+ $div,
26
+ $switchLeft,
27
+ $switchRight,
28
+ $label,
29
+ $form = $element.closest('form'),
30
+ myClasses = "",
31
+ classes = $element.attr('class'),
32
+ color,
33
+ moving,
34
+ onLabel = "ON",
35
+ offLabel = "OFF",
36
+ icon = false,
37
+ textLabel = false;
38
+
39
+ $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
40
+ if (classes.indexOf(el) >= 0) {
41
+ myClasses = el;
42
+ }
43
+ });
44
+
45
+ $element.addClass('has-switch');
46
+
47
+ if ($element.data('on') !== undefined) {
48
+ color = "switch-" + $element.data('on');
49
+ }
50
+
51
+ if ($element.data('on-label') !== undefined) {
52
+ onLabel = $element.data('on-label');
53
+ }
54
+
55
+ if ($element.data('off-label') !== undefined) {
56
+ offLabel = $element.data('off-label');
57
+ }
58
+
59
+ if ($element.data('label-icon') !== undefined) {
60
+ icon = $element.data('label-icon');
61
+ }
62
+
63
+ if ($element.data('text-label') !== undefined) {
64
+ textLabel = $element.data('text-label');
65
+ }
66
+
67
+ $switchLeft = $('<span>')
68
+ .addClass("switch-left")
69
+ .addClass(myClasses)
70
+ .addClass(color)
71
+ .html('' + onLabel + '');
72
+
73
+ color = '';
74
+ if ($element.data('off') !== undefined) {
75
+ color = "switch-" + $element.data('off');
76
+ }
77
+
78
+ $switchRight = $('<span>')
79
+ .addClass("switch-right")
80
+ .addClass(myClasses)
81
+ .addClass(color)
82
+ .html('' + offLabel + '');
83
+
84
+ $label = $('<label>')
85
+ .html("&nbsp;")
86
+ .addClass(myClasses)
87
+ .attr('for', $element.find(inputSelector).attr('id'));
88
+
89
+ if (icon) {
90
+ $label.html('<i class="icon ' + icon + '"></i>');
91
+ }
92
+
93
+ if (textLabel) {
94
+ $label.html('' + textLabel + '');
95
+ }
96
+
97
+ $div = $element.find(inputSelector).wrap($('<div>')).parent().data('animated', false);
98
+
99
+ if ($element.data('animated') !== false) {
100
+ $div.addClass('switch-animate').data('animated', true);
101
+ }
102
+
103
+ $div
104
+ .append($switchLeft)
105
+ .append($label)
106
+ .append($switchRight);
107
+
108
+ $element.find('> div').addClass($element.find(inputSelector).is(':checked') ? 'switch-on' : 'switch-off');
109
+
110
+ if ($element.find(inputSelector).is(':disabled')) {
111
+ $(this).addClass('deactivate');
112
+ }
113
+
114
+ var changeStatus = function ($this) {
115
+ if ($element.parent('label').is('.label-change-switch')) {
116
+
117
+ } else {
118
+ $this.siblings('label').trigger('mousedown').trigger('mouseup').trigger('click');
119
+ }
120
+ };
121
+
122
+ $element.on('keydown', function (e) {
123
+ if (e.keyCode === 32) {
124
+ e.stopImmediatePropagation();
125
+ e.preventDefault();
126
+ changeStatus($(e.target).find('span:first'));
127
+ }
128
+ });
129
+
130
+ $switchLeft.on('click', function () {
131
+ changeStatus($(this));
132
+ });
133
+
134
+ $switchRight.on('click', function () {
135
+ changeStatus($(this));
136
+ });
137
+
138
+ $element.find(inputSelector).on('change', function (e, skipOnChange) {
139
+ var $this = $(this),
140
+ $element = $this.parent(),
141
+ thisState = $this.is(':checked'),
142
+ state = $element.is('.switch-off');
143
+
144
+ e.preventDefault();
145
+
146
+ $element.css('left', '');
147
+
148
+ if (state === thisState) {
149
+ if (thisState) {
150
+ $element.removeClass('switch-off').addClass('switch-on');
151
+ }
152
+ else {
153
+ $element.removeClass('switch-on').addClass('switch-off');
154
+ }
155
+
156
+ if ($element.data('animated') !== false) {
157
+ $element.addClass("switch-animate");
158
+ }
159
+
160
+ if (typeof skipOnChange === 'boolean' && skipOnChange) {
161
+ return;
162
+ }
163
+
164
+ $element.parent().trigger('switch-change', {
165
+ el: $this,
166
+ value: thisState
167
+ });
168
+ }
169
+ });
170
+
171
+ $element.find('label').on('mousedown touchstart', function (e) {
172
+ var $this = $(this);
173
+ moving = false;
174
+
175
+ e.preventDefault();
176
+ e.stopImmediatePropagation();
177
+
178
+ $this.closest('div').removeClass('switch-animate');
179
+
180
+ if ($this.closest('.has-switch').is('.deactivate')) {
181
+ $this.unbind('click');
182
+ } else if ($this.closest('.switch-on').parent().is('.radio-no-uncheck')) {
183
+ $this.unbind('click');
184
+ } else {
185
+ $this.on('mousemove touchmove', function (e) {
186
+ var $element = $(this).closest('.make-switch'),
187
+ relativeX = (e.pageX || e.originalEvent.targetTouches[0].pageX) - $element.offset().left,
188
+ percent = (relativeX / $element.width()) * 100,
189
+ left = 25,
190
+ right = 75;
191
+
192
+ moving = true;
193
+
194
+ if (percent < left) {
195
+ percent = left;
196
+ }
197
+ else if (percent > right) {
198
+ percent = right;
199
+ }
200
+
201
+ $element.find('>div').css('left', (percent - right) + "%");
202
+ });
203
+
204
+ $this.on('click touchend', function (e) {
205
+ var $this = $(this),
206
+ $myInputBox = $this.siblings('input');
207
+
208
+ e.stopImmediatePropagation();
209
+ e.preventDefault();
210
+
211
+ $this.unbind('mouseleave');
212
+
213
+ if (moving) {
214
+ $myInputBox.prop('checked', !(parseInt($this.parent().css('left'), 10) < -25));
215
+ }
216
+ else {
217
+ $myInputBox.prop("checked", !$myInputBox.is(":checked"));
218
+ }
219
+
220
+ moving = false;
221
+ $myInputBox.trigger('change');
222
+ });
223
+
224
+ $this.on('mouseleave', function (e) {
225
+ var $this = $(this),
226
+ $myInputBox = $this.siblings('input');
227
+
228
+ e.preventDefault();
229
+ e.stopImmediatePropagation();
230
+
231
+ $this.unbind('mouseleave mousemove');
232
+ $this.trigger('mouseup');
233
+
234
+ $myInputBox.prop('checked', ! (parseInt($this.parent().css('left'), 10) < -25)).trigger('change');
235
+ });
236
+
237
+ $this.on('mouseup', function (e) {
238
+ e.stopImmediatePropagation();
239
+ e.preventDefault();
240
+
241
+ $(this).trigger('mouseleave');
242
+ });
243
+ }
244
+ });
245
+
246
+ if ($form.data('bootstrapSwitch') !== 'injected') {
247
+ $form.bind('reset', function () {
248
+ setTimeout(function () {
249
+ $form.find('.make-switch').each(function () {
250
+ var $input = $(this).find(inputSelector);
251
+
252
+ $input.prop('checked', $input.is(':checked')).trigger('change');
253
+ });
254
+ }, 1);
255
+ });
256
+ $form.data('bootstrapSwitch', 'injected');
257
+ }
258
+ }
259
+ );
260
+ },
261
+
262
+ toggleActivation: function () {
263
+ var $this = $(this);
264
+
265
+ $this.toggleClass('deactivate');
266
+ $this.find(inputSelector).prop('disabled', $this.is('.deactivate'));
267
+ },
268
+
269
+ isActive: function () {
270
+ return !$(this).hasClass('deactivate');
271
+ },
272
+
273
+ setActive: function (active) {
274
+ var $this = $(this);
275
+
276
+ if (active) {
277
+ $this.removeClass('deactivate');
278
+ $this.find(inputSelector).removeAttr('disabled');
279
+ }
280
+ else {
281
+ $this.addClass('deactivate');
282
+ $this.find(inputSelector).attr('disabled', 'disabled');
283
+ }
284
+ },
285
+
286
+ toggleState: function (skipOnChange) {
287
+ var $input = $(this).find(':checkbox');
288
+ $input.prop('checked', !$input.is(':checked')).trigger('change', skipOnChange);
289
+ },
290
+
291
+ toggleRadioState: function (skipOnChange) {
292
+ var $radioinput = $(this).find(':radio');
293
+ $radioinput.not(':checked').prop('checked', !$radioinput.is(':checked')).trigger('change', skipOnChange);
294
+ },
295
+
296
+ toggleRadioStateAllowUncheck: function (uncheck, skipOnChange) {
297
+ var $radioinput = $(this).find(':radio');
298
+
299
+ if (uncheck) {
300
+ $radioinput.not(':checked').trigger('change', skipOnChange);
301
+ }
302
+ else {
303
+ $radioinput.not(':checked').prop('checked', ! $radioinput.is(':checked')).trigger('change', skipOnChange);
304
+ }
305
+ },
306
+
307
+ setState: function (value, skipOnChange) {
308
+ $(this).find(inputSelector).prop('checked', value).trigger('change', skipOnChange);
309
+ },
310
+
311
+ setOnLabel: function (value) {
312
+ var $switchLeft = $(this).find(".switch-left");
313
+
314
+ $switchLeft.html(value);
315
+ },
316
+
317
+ setOffLabel: function (value) {
318
+ var $switchRight = $(this).find(".switch-right");
319
+
320
+ $switchRight.html(value);
321
+ },
322
+
323
+ setOnClass: function (value) {
324
+ var $switchLeft = $(this).find(".switch-left"),
325
+ color = '';
326
+
327
+ if (value !== undefined) {
328
+ if ($(this).attr('data-on') !== undefined) {
329
+ color = "switch-" + $(this).attr('data-on');
330
+ }
331
+ $switchLeft.removeClass(color);
332
+ color = "switch-" + value;
333
+ $switchLeft.addClass(color);
334
+ }
335
+ },
336
+
337
+ setOffClass: function (value) {
338
+ var $switchRight = $(this).find(".switch-right"),
339
+ color = '';
340
+
341
+ if (value !== undefined) {
342
+ if ($(this).attr('data-off') !== undefined) {
343
+ color = "switch-" + $(this).attr('data-off');
344
+ }
345
+ $switchRight.removeClass(color);
346
+ color = "switch-" + value;
347
+ $switchRight.addClass(color);
348
+ }
349
+ },
350
+
351
+ setAnimated: function (value) {
352
+ var $element = $(this).find(inputSelector).parent();
353
+
354
+ if (value === undefined) {
355
+ value = false;
356
+ }
357
+
358
+ $element.data('animated', value);
359
+ $element.attr('data-animated', value);
360
+ $element[$element.data('animated') !== false ? 'addClass' : 'removeClass']("switch-animate");
361
+ },
362
+
363
+ setSizeClass: function (value) {
364
+ var $element = $(this);
365
+ var $switchLeft = $element.find(".switch-left");
366
+ var $switchRight = $element.find(".switch-right");
367
+ var $label = $element.find("label");
368
+ $.each(['switch-mini', 'switch-small', 'switch-large'], function (i, el) {
369
+ if (el !== value) {
370
+ $switchLeft.removeClass(el);
371
+ $switchRight.removeClass(el);
372
+ $label.removeClass(el);
373
+ } else {
374
+ $switchLeft.addClass(el);
375
+ $switchRight.addClass(el);
376
+ $label.addClass(el);
377
+ }
378
+ });
379
+ },
380
+
381
+ status: function () {
382
+ return $(this).find(inputSelector).is(':checked');
383
+ },
384
+
385
+ destroy: function () {
386
+ var $element = $(this),
387
+ $div = $element.find('div'),
388
+ $form = $element.closest('form'),
389
+ $inputbox;
390
+
391
+ $div.find(':not(input)').remove();
392
+ $inputbox = $div.children();
393
+ $inputbox.unwrap().unwrap();
394
+ $inputbox.unbind('change');
395
+
396
+ if ($form) {
397
+ $form.unbind('reset');
398
+ $form.removeData('bootstrapSwitch');
399
+ }
400
+
401
+ return $inputbox;
402
+ }
403
+ };
404
+
405
+ if (methods[method]) {
406
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
407
+ }
408
+ if (typeof method === 'object' || ! method) {
409
+ return methods.init.apply(this, arguments);
410
+ }
411
+
412
+ $.error('Method ' + method + ' does not exist!');
413
+ };
414
+ }(jQuery);
415
+
416
+ (function ($) {
417
+ $(function () {
418
+ $('.make-switch').bootstrapSwitch();
419
+ });
420
+ })(jQuery);