bootstrap-switch-rails 1.4.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -18
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +62 -55
- data/Rakefile +1 -1
- data/bootstrap-switch-rails.gemspec +23 -23
- data/lib/bootstrap-switch-rails.rb +14 -14
- data/lib/bootstrap-switch-rails/engine.rb +8 -8
- data/lib/bootstrap-switch-rails/railtie.rb +7 -7
- data/lib/bootstrap-switch-rails/version.rb +7 -7
- data/update_from_vendor.sh +17 -17
- data/vendor/assets/javascripts/bootstrap-switch.js +383 -264
- data/vendor/assets/stylesheets/{bootstrap-switch.css → bootstrap-switch.css.scss} +408 -391
- metadata +16 -10
- checksums.yaml +0 -7
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
|
data/LICENSE.txt
CHANGED
@@ -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](
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
##
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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.
|
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
|
data/update_from_vendor.sh
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
#!/bin/
|
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.
|
3
|
-
* http://www.larentis.eu/
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* http://www.
|
7
|
-
*
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
,
|
25
|
-
,
|
26
|
-
,
|
27
|
-
,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if ($element.data('
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
.
|
50
|
-
|
51
|
-
|
52
|
-
.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
.addClass(
|
62
|
-
.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
$
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
$element
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
$
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
$
|
245
|
-
|
246
|
-
|
247
|
-
$
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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(" ")
|
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);
|