bootstrap-switch-rails-bcj-version 3.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +1 -0
- data/bootstrap-switch-rails-bcj-version.gemspec +23 -0
- data/lib/bootstrap-switch-rails.rb +14 -0
- data/lib/bootstrap-switch-rails/engine.rb +8 -0
- data/lib/bootstrap-switch-rails/railtie.rb +7 -0
- data/lib/bootstrap-switch-rails/version.rb +7 -0
- data/update_from_vendor.sh +18 -0
- data/vendor/assets/javascripts/bootstrap-switch.js +710 -0
- data/vendor/assets/stylesheets/bootstrap2-switch.scss +519 -0
- data/vendor/assets/stylesheets/bootstrap3-switch.scss +195 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cdb3fba2470e9a349904fdd829b2006860dd14b0
|
4
|
+
data.tar.gz: 5be6dcd4d193e8129b575843ab1683e24989b5f5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e9512da37db93008535add9b827a3e9533e33daf5f3481a0c5a3f7716fdda45d7b77b3f213b240942fd1c2218f51ba68525ceded7828e0e3d3e1dac2cfc69e8
|
7
|
+
data.tar.gz: 2775aadf0ab5134b2aae294f9e70ed8ad84270d377b43e0963df99ed93a960eb12687b52027ff557298268673a849214485ff143e8b5dd9ff31d5e2c1d28f2f8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +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.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
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
|
+
## License
|
52
|
+
|
53
|
+
* The [bootstrap-switch](http://www.bootstrap-switch.org/) plugin is licensed under the
|
54
|
+
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
55
|
+
* The [bootstrap-switch-rails](https://github.com/manuelvanrijn/bootstrap-switch-rails) project is
|
56
|
+
licensed under the [MIT License](http://opensource.org/licenses/mit-license.html)
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +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-bcj-version"
|
8
|
+
spec.version = Bootstrap::Switch::Rails::VERSION
|
9
|
+
spec.authors = ["Blaed Johnston"]
|
10
|
+
spec.email = ["blaedj@gmail.com"]
|
11
|
+
spec.description = %q{A small gem for putting bootstrap-switch into the Rails asset pipeline, all credit for this goes to the original creator, Manuel van Rijn. see https://github.com/manuelvanrjin/bootstrap-switch-rails. this is created to include a tweak to the bootstrap-switch source that I needed for a specific project}
|
12
|
+
spec.summary = %q{an asset gemification of the bootstrap-switch plugin}
|
13
|
+
spec.homepage = "https://github.com/blaedj/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
|
@@ -0,0 +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
|
@@ -0,0 +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/dist/js/bootstrap-switch.js vendor/assets/javascripts/bootstrap-switch.js
|
10
|
+
echo "Copying bootstrap-switch.css files"
|
11
|
+
cp tmp_vendor/dist/css/bootstrap2/bootstrap-switch.css vendor/assets/stylesheets/bootstrap2-switch.scss
|
12
|
+
cp tmp_vendor/dist/css/bootstrap3/bootstrap-switch.css vendor/assets/stylesheets/bootstrap3-switch.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"
|
@@ -0,0 +1,710 @@
|
|
1
|
+
/* ========================================================================
|
2
|
+
* bootstrap-switch - v3.3.2
|
3
|
+
* http://www.bootstrap-switch.org
|
4
|
+
* ========================================================================
|
5
|
+
* Copyright 2012-2013 Mattia Larentis
|
6
|
+
*
|
7
|
+
* ========================================================================
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
* you may not use this file except in compliance with the License.
|
10
|
+
* You may obtain a copy of the License at
|
11
|
+
*
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
*
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
* See the License for the specific language governing permissions and
|
18
|
+
* limitations under the License.
|
19
|
+
* ========================================================================
|
20
|
+
*/
|
21
|
+
|
22
|
+
(function() {
|
23
|
+
var __slice = [].slice;
|
24
|
+
|
25
|
+
(function($, window) {
|
26
|
+
"use strict";
|
27
|
+
var BootstrapSwitch;
|
28
|
+
BootstrapSwitch = (function() {
|
29
|
+
function BootstrapSwitch(element, options) {
|
30
|
+
if (options == null) {
|
31
|
+
options = {};
|
32
|
+
}
|
33
|
+
this.$element = $(element);
|
34
|
+
this.options = $.extend({}, $.fn.bootstrapSwitch.defaults, {
|
35
|
+
state: this.$element.is(":checked"),
|
36
|
+
size: this.$element.data("size"),
|
37
|
+
animate: this.$element.data("animate"),
|
38
|
+
disabled: this.$element.is(":disabled"),
|
39
|
+
readonly: this.$element.is("[readonly]"),
|
40
|
+
indeterminate: this.$element.data("indeterminate"),
|
41
|
+
inverse: this.$element.data("inverse"),
|
42
|
+
radioAllOff: this.$element.data("radio-all-off"),
|
43
|
+
onColor: this.$element.data("on-color"),
|
44
|
+
offColor: this.$element.data("off-color"),
|
45
|
+
onText: this.$element.data("on-text"),
|
46
|
+
offText: this.$element.data("off-text"),
|
47
|
+
labelText: this.$element.data("label-text"),
|
48
|
+
handleWidth: this.$element.data("handle-width"),
|
49
|
+
labelWidth: this.$element.data("label-width"),
|
50
|
+
baseClass: this.$element.data("base-class"),
|
51
|
+
wrapperClass: this.$element.data("wrapper-class")
|
52
|
+
}, options);
|
53
|
+
this.$wrapper = $("<div>", {
|
54
|
+
"class": (function(_this) {
|
55
|
+
return function() {
|
56
|
+
var classes;
|
57
|
+
classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass));
|
58
|
+
classes.push(_this.options.state ? "" + _this.options.baseClass + "-on" : "" + _this.options.baseClass + "-off");
|
59
|
+
if (_this.options.size != null) {
|
60
|
+
classes.push("" + _this.options.baseClass + "-" + _this.options.size);
|
61
|
+
}
|
62
|
+
if (_this.options.disabled) {
|
63
|
+
classes.push("" + _this.options.baseClass + "-disabled");
|
64
|
+
}
|
65
|
+
if (_this.options.readonly) {
|
66
|
+
classes.push("" + _this.options.baseClass + "-readonly");
|
67
|
+
}
|
68
|
+
if (_this.options.indeterminate) {
|
69
|
+
classes.push("" + _this.options.baseClass + "-indeterminate");
|
70
|
+
}
|
71
|
+
if (_this.options.inverse) {
|
72
|
+
classes.push("" + _this.options.baseClass + "-inverse");
|
73
|
+
}
|
74
|
+
if (_this.$element.attr("id")) {
|
75
|
+
classes.push("" + _this.options.baseClass + "-id-" + (_this.$element.attr("id")));
|
76
|
+
}
|
77
|
+
return classes.join(" ");
|
78
|
+
};
|
79
|
+
})(this)()
|
80
|
+
});
|
81
|
+
this.$container = $("<div>", {
|
82
|
+
"class": "" + this.options.baseClass + "-container"
|
83
|
+
});
|
84
|
+
this.$on = $("<span>", {
|
85
|
+
html: this.options.onText,
|
86
|
+
"class": "" + this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor
|
87
|
+
});
|
88
|
+
this.$off = $("<span>", {
|
89
|
+
html: this.options.offText,
|
90
|
+
"class": "" + this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor
|
91
|
+
});
|
92
|
+
this.$label = $("<span>", {
|
93
|
+
html: this.options.labelText,
|
94
|
+
"class": "" + this.options.baseClass + "-label"
|
95
|
+
});
|
96
|
+
this.$element.on("init.bootstrapSwitch", (function(_this) {
|
97
|
+
return function() {
|
98
|
+
return _this.options.onInit.apply(element, arguments);
|
99
|
+
};
|
100
|
+
})(this));
|
101
|
+
this.$element.on("switchChange.bootstrapSwitch", (function(_this) {
|
102
|
+
return function() {
|
103
|
+
return _this.options.onSwitchChange.apply(element, arguments);
|
104
|
+
};
|
105
|
+
})(this));
|
106
|
+
this.$container = this.$element.wrap(this.$container).parent();
|
107
|
+
this.$wrapper = this.$container.wrap(this.$wrapper).parent();
|
108
|
+
this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off);
|
109
|
+
if (this.options.indeterminate) {
|
110
|
+
this.$element.prop("indeterminate", true);
|
111
|
+
}
|
112
|
+
this._init();
|
113
|
+
this._elementHandlers();
|
114
|
+
this._handleHandlers();
|
115
|
+
this._labelHandlers();
|
116
|
+
this._formHandler();
|
117
|
+
this._externalLabelHandler();
|
118
|
+
this.$element.trigger("init.bootstrapSwitch");
|
119
|
+
}
|
120
|
+
|
121
|
+
BootstrapSwitch.prototype._constructor = BootstrapSwitch;
|
122
|
+
|
123
|
+
BootstrapSwitch.prototype.state = function(value, skip) {
|
124
|
+
if (typeof value === "undefined") {
|
125
|
+
return this.options.state;
|
126
|
+
}
|
127
|
+
if (this.options.disabled || this.options.readonly) {
|
128
|
+
return this.$element;
|
129
|
+
}
|
130
|
+
if (this.options.state && !this.options.radioAllOff && this.$element.is(":radio")) {
|
131
|
+
return this.$element;
|
132
|
+
}
|
133
|
+
if (this.options.indeterminate) {
|
134
|
+
this.indeterminate(false);
|
135
|
+
}
|
136
|
+
value = !!value;
|
137
|
+
this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip);
|
138
|
+
return this.$element;
|
139
|
+
};
|
140
|
+
|
141
|
+
BootstrapSwitch.prototype.toggleState = function(skip) {
|
142
|
+
if (this.options.disabled || this.options.readonly) {
|
143
|
+
return this.$element;
|
144
|
+
}
|
145
|
+
if (this.options.indeterminate) {
|
146
|
+
this.indeterminate(false);
|
147
|
+
return this.state(true);
|
148
|
+
} else {
|
149
|
+
return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip);
|
150
|
+
}
|
151
|
+
};
|
152
|
+
|
153
|
+
BootstrapSwitch.prototype.size = function(value) {
|
154
|
+
if (typeof value === "undefined") {
|
155
|
+
return this.options.size;
|
156
|
+
}
|
157
|
+
if (this.options.size != null) {
|
158
|
+
this.$wrapper.removeClass("" + this.options.baseClass + "-" + this.options.size);
|
159
|
+
}
|
160
|
+
if (value) {
|
161
|
+
this.$wrapper.addClass("" + this.options.baseClass + "-" + value);
|
162
|
+
}
|
163
|
+
this._width();
|
164
|
+
this._containerPosition();
|
165
|
+
this.options.size = value;
|
166
|
+
return this.$element;
|
167
|
+
};
|
168
|
+
|
169
|
+
BootstrapSwitch.prototype.animate = function(value) {
|
170
|
+
if (typeof value === "undefined") {
|
171
|
+
return this.options.animate;
|
172
|
+
}
|
173
|
+
value = !!value;
|
174
|
+
if (value === this.options.animate) {
|
175
|
+
return this.$element;
|
176
|
+
}
|
177
|
+
return this.toggleAnimate();
|
178
|
+
};
|
179
|
+
|
180
|
+
BootstrapSwitch.prototype.toggleAnimate = function() {
|
181
|
+
this.options.animate = !this.options.animate;
|
182
|
+
this.$wrapper.toggleClass("" + this.options.baseClass + "-animate");
|
183
|
+
return this.$element;
|
184
|
+
};
|
185
|
+
|
186
|
+
BootstrapSwitch.prototype.disabled = function(value) {
|
187
|
+
if (typeof value === "undefined") {
|
188
|
+
return this.options.disabled;
|
189
|
+
}
|
190
|
+
value = !!value;
|
191
|
+
if (value === this.options.disabled) {
|
192
|
+
return this.$element;
|
193
|
+
}
|
194
|
+
return this.toggleDisabled();
|
195
|
+
};
|
196
|
+
|
197
|
+
BootstrapSwitch.prototype.toggleDisabled = function() {
|
198
|
+
this.options.disabled = !this.options.disabled;
|
199
|
+
this.$element.prop("disabled", this.options.disabled);
|
200
|
+
this.$wrapper.toggleClass("" + this.options.baseClass + "-disabled");
|
201
|
+
return this.$element;
|
202
|
+
};
|
203
|
+
|
204
|
+
BootstrapSwitch.prototype.readonly = function(value) {
|
205
|
+
if (typeof value === "undefined") {
|
206
|
+
return this.options.readonly;
|
207
|
+
}
|
208
|
+
value = !!value;
|
209
|
+
if (value === this.options.readonly) {
|
210
|
+
return this.$element;
|
211
|
+
}
|
212
|
+
return this.toggleReadonly();
|
213
|
+
};
|
214
|
+
|
215
|
+
BootstrapSwitch.prototype.toggleReadonly = function() {
|
216
|
+
this.options.readonly = !this.options.readonly;
|
217
|
+
this.$element.prop("readonly", this.options.readonly);
|
218
|
+
this.$wrapper.toggleClass("" + this.options.baseClass + "-readonly");
|
219
|
+
return this.$element;
|
220
|
+
};
|
221
|
+
|
222
|
+
BootstrapSwitch.prototype.indeterminate = function(value) {
|
223
|
+
if (typeof value === "undefined") {
|
224
|
+
return this.options.indeterminate;
|
225
|
+
}
|
226
|
+
value = !!value;
|
227
|
+
if (value === this.options.indeterminate) {
|
228
|
+
return this.$element;
|
229
|
+
}
|
230
|
+
return this.toggleIndeterminate();
|
231
|
+
};
|
232
|
+
|
233
|
+
BootstrapSwitch.prototype.toggleIndeterminate = function() {
|
234
|
+
this.options.indeterminate = !this.options.indeterminate;
|
235
|
+
this.$element.prop("indeterminate", this.options.indeterminate);
|
236
|
+
this.$wrapper.toggleClass("" + this.options.baseClass + "-indeterminate");
|
237
|
+
this._containerPosition();
|
238
|
+
return this.$element;
|
239
|
+
};
|
240
|
+
|
241
|
+
BootstrapSwitch.prototype.inverse = function(value) {
|
242
|
+
if (typeof value === "undefined") {
|
243
|
+
return this.options.inverse;
|
244
|
+
}
|
245
|
+
value = !!value;
|
246
|
+
if (value === this.options.inverse) {
|
247
|
+
return this.$element;
|
248
|
+
}
|
249
|
+
return this.toggleInverse();
|
250
|
+
};
|
251
|
+
|
252
|
+
BootstrapSwitch.prototype.toggleInverse = function() {
|
253
|
+
var $off, $on;
|
254
|
+
this.$wrapper.toggleClass("" + this.options.baseClass + "-inverse");
|
255
|
+
$on = this.$on.clone(true);
|
256
|
+
$off = this.$off.clone(true);
|
257
|
+
this.$on.replaceWith($off);
|
258
|
+
this.$off.replaceWith($on);
|
259
|
+
this.$on = $off;
|
260
|
+
this.$off = $on;
|
261
|
+
this.options.inverse = !this.options.inverse;
|
262
|
+
return this.$element;
|
263
|
+
};
|
264
|
+
|
265
|
+
BootstrapSwitch.prototype.onColor = function(value) {
|
266
|
+
var color;
|
267
|
+
color = this.options.onColor;
|
268
|
+
if (typeof value === "undefined") {
|
269
|
+
return color;
|
270
|
+
}
|
271
|
+
if (color != null) {
|
272
|
+
this.$on.removeClass("" + this.options.baseClass + "-" + color);
|
273
|
+
}
|
274
|
+
this.$on.addClass("" + this.options.baseClass + "-" + value);
|
275
|
+
this.options.onColor = value;
|
276
|
+
return this.$element;
|
277
|
+
};
|
278
|
+
|
279
|
+
BootstrapSwitch.prototype.offColor = function(value) {
|
280
|
+
var color;
|
281
|
+
color = this.options.offColor;
|
282
|
+
if (typeof value === "undefined") {
|
283
|
+
return color;
|
284
|
+
}
|
285
|
+
if (color != null) {
|
286
|
+
this.$off.removeClass("" + this.options.baseClass + "-" + color);
|
287
|
+
}
|
288
|
+
this.$off.addClass("" + this.options.baseClass + "-" + value);
|
289
|
+
this.options.offColor = value;
|
290
|
+
return this.$element;
|
291
|
+
};
|
292
|
+
|
293
|
+
BootstrapSwitch.prototype.onText = function(value) {
|
294
|
+
if (typeof value === "undefined") {
|
295
|
+
return this.options.onText;
|
296
|
+
}
|
297
|
+
this.$on.html(value);
|
298
|
+
this._width();
|
299
|
+
this._containerPosition();
|
300
|
+
this.options.onText = value;
|
301
|
+
return this.$element;
|
302
|
+
};
|
303
|
+
|
304
|
+
BootstrapSwitch.prototype.offText = function(value) {
|
305
|
+
if (typeof value === "undefined") {
|
306
|
+
return this.options.offText;
|
307
|
+
}
|
308
|
+
this.$off.html(value);
|
309
|
+
this._width();
|
310
|
+
this._containerPosition();
|
311
|
+
this.options.offText = value;
|
312
|
+
return this.$element;
|
313
|
+
};
|
314
|
+
|
315
|
+
BootstrapSwitch.prototype.labelText = function(value) {
|
316
|
+
if (typeof value === "undefined") {
|
317
|
+
return this.options.labelText;
|
318
|
+
}
|
319
|
+
this.$label.html(value);
|
320
|
+
this._width();
|
321
|
+
this.options.labelText = value;
|
322
|
+
return this.$element;
|
323
|
+
};
|
324
|
+
|
325
|
+
BootstrapSwitch.prototype.handleWidth = function(value) {
|
326
|
+
if (typeof value === "undefined") {
|
327
|
+
return this.options.handleWidth;
|
328
|
+
}
|
329
|
+
this.options.handleWidth = value;
|
330
|
+
this._width();
|
331
|
+
this._containerPosition();
|
332
|
+
return this.$element;
|
333
|
+
};
|
334
|
+
|
335
|
+
BootstrapSwitch.prototype.labelWidth = function(value) {
|
336
|
+
if (typeof value === "undefined") {
|
337
|
+
return this.options.labelWidth;
|
338
|
+
}
|
339
|
+
this.options.labelWidth = value;
|
340
|
+
this._width();
|
341
|
+
this._containerPosition();
|
342
|
+
return this.$element;
|
343
|
+
};
|
344
|
+
|
345
|
+
BootstrapSwitch.prototype.baseClass = function(value) {
|
346
|
+
return this.options.baseClass;
|
347
|
+
};
|
348
|
+
|
349
|
+
BootstrapSwitch.prototype.wrapperClass = function(value) {
|
350
|
+
if (typeof value === "undefined") {
|
351
|
+
return this.options.wrapperClass;
|
352
|
+
}
|
353
|
+
if (!value) {
|
354
|
+
value = $.fn.bootstrapSwitch.defaults.wrapperClass;
|
355
|
+
}
|
356
|
+
this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" "));
|
357
|
+
this.$wrapper.addClass(this._getClasses(value).join(" "));
|
358
|
+
this.options.wrapperClass = value;
|
359
|
+
return this.$element;
|
360
|
+
};
|
361
|
+
|
362
|
+
BootstrapSwitch.prototype.radioAllOff = function(value) {
|
363
|
+
if (typeof value === "undefined") {
|
364
|
+
return this.options.radioAllOff;
|
365
|
+
}
|
366
|
+
value = !!value;
|
367
|
+
if (value === this.options.radioAllOff) {
|
368
|
+
return this.$element;
|
369
|
+
}
|
370
|
+
this.options.radioAllOff = value;
|
371
|
+
return this.$element;
|
372
|
+
};
|
373
|
+
|
374
|
+
BootstrapSwitch.prototype.onInit = function(value) {
|
375
|
+
if (typeof value === "undefined") {
|
376
|
+
return this.options.onInit;
|
377
|
+
}
|
378
|
+
if (!value) {
|
379
|
+
value = $.fn.bootstrapSwitch.defaults.onInit;
|
380
|
+
}
|
381
|
+
this.options.onInit = value;
|
382
|
+
return this.$element;
|
383
|
+
};
|
384
|
+
|
385
|
+
BootstrapSwitch.prototype.onSwitchChange = function(value) {
|
386
|
+
if (typeof value === "undefined") {
|
387
|
+
return this.options.onSwitchChange;
|
388
|
+
}
|
389
|
+
if (!value) {
|
390
|
+
value = $.fn.bootstrapSwitch.defaults.onSwitchChange;
|
391
|
+
}
|
392
|
+
this.options.onSwitchChange = value;
|
393
|
+
return this.$element;
|
394
|
+
};
|
395
|
+
|
396
|
+
BootstrapSwitch.prototype.destroy = function() {
|
397
|
+
var $form;
|
398
|
+
$form = this.$element.closest("form");
|
399
|
+
if ($form.length) {
|
400
|
+
$form.off("reset.bootstrapSwitch").removeData("bootstrap-switch");
|
401
|
+
}
|
402
|
+
this.$container.children().not(this.$element).remove();
|
403
|
+
this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch");
|
404
|
+
return this.$element;
|
405
|
+
};
|
406
|
+
|
407
|
+
BootstrapSwitch.prototype._width = function() {
|
408
|
+
var $handles, handleWidth;
|
409
|
+
$handles = this.$on.add(this.$off);
|
410
|
+
$handles.add(this.$label).css("width", "");
|
411
|
+
handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth;
|
412
|
+
$handles.width(handleWidth);
|
413
|
+
this.$label.width((function(_this) {
|
414
|
+
return function(index, width) {
|
415
|
+
if (_this.options.labelWidth !== "auto") {
|
416
|
+
return _this.options.labelWidth;
|
417
|
+
}
|
418
|
+
if (width < handleWidth) {
|
419
|
+
return handleWidth;
|
420
|
+
} else {
|
421
|
+
return width;
|
422
|
+
}
|
423
|
+
};
|
424
|
+
})(this));
|
425
|
+
this._handleWidth = this.$on.outerWidth();
|
426
|
+
this._labelWidth = this.$label.outerWidth();
|
427
|
+
this.$container.width((this._handleWidth * 2) + this._labelWidth);
|
428
|
+
return this.$wrapper.width(this._handleWidth + this._labelWidth);
|
429
|
+
};
|
430
|
+
|
431
|
+
BootstrapSwitch.prototype._containerPosition = function(state, callback) {
|
432
|
+
if (state == null) {
|
433
|
+
state = this.options.state;
|
434
|
+
}
|
435
|
+
this.$container.css("margin-left", (function(_this) {
|
436
|
+
return function() {
|
437
|
+
var values;
|
438
|
+
values = [0, "-" + _this._handleWidth + "px"];
|
439
|
+
if (_this.options.indeterminate) {
|
440
|
+
return "-" + (_this._handleWidth / 2) + "px";
|
441
|
+
}
|
442
|
+
if (state) {
|
443
|
+
if (_this.options.inverse) {
|
444
|
+
return values[1];
|
445
|
+
} else {
|
446
|
+
return values[0];
|
447
|
+
}
|
448
|
+
} else {
|
449
|
+
if (_this.options.inverse) {
|
450
|
+
return values[0];
|
451
|
+
} else {
|
452
|
+
return values[1];
|
453
|
+
}
|
454
|
+
}
|
455
|
+
};
|
456
|
+
})(this));
|
457
|
+
if (!callback) {
|
458
|
+
return;
|
459
|
+
}
|
460
|
+
return setTimeout(function() {
|
461
|
+
return callback();
|
462
|
+
}, 50);
|
463
|
+
};
|
464
|
+
|
465
|
+
BootstrapSwitch.prototype._init = function() {
|
466
|
+
var init, initInterval;
|
467
|
+
init = (function(_this) {
|
468
|
+
return function() {
|
469
|
+
_this._width();
|
470
|
+
return _this._containerPosition(null, function() {
|
471
|
+
if (_this.options.animate) {
|
472
|
+
return _this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
|
473
|
+
}
|
474
|
+
});
|
475
|
+
};
|
476
|
+
})(this);
|
477
|
+
if (this.$wrapper.is(":visible")) {
|
478
|
+
return init();
|
479
|
+
}
|
480
|
+
return initInterval = window.setInterval((function(_this) {
|
481
|
+
return function() {
|
482
|
+
if (_this.$wrapper.is(":visible")) {
|
483
|
+
init();
|
484
|
+
return window.clearInterval(initInterval);
|
485
|
+
}
|
486
|
+
};
|
487
|
+
})(this), 50);
|
488
|
+
};
|
489
|
+
|
490
|
+
BootstrapSwitch.prototype._elementHandlers = function() {
|
491
|
+
return this.$element.on({
|
492
|
+
"change.bootstrapSwitch": (function(_this) {
|
493
|
+
return function(e, skip) {
|
494
|
+
var state;
|
495
|
+
e.preventDefault();
|
496
|
+
e.stopImmediatePropagation();
|
497
|
+
state = _this.$element.is(":checked");
|
498
|
+
_this._containerPosition(state);
|
499
|
+
if (state === _this.options.state) {
|
500
|
+
return;
|
501
|
+
}
|
502
|
+
_this.options.state = state;
|
503
|
+
_this.$wrapper.toggleClass("" + _this.options.baseClass + "-off").toggleClass("" + _this.options.baseClass + "-on");
|
504
|
+
if (!skip) {
|
505
|
+
if (_this.$element.is(":radio")) {
|
506
|
+
$("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true);
|
507
|
+
}
|
508
|
+
return _this.$element.trigger("switchChange.bootstrapSwitch", [state]);
|
509
|
+
}
|
510
|
+
};
|
511
|
+
})(this),
|
512
|
+
"focus.bootstrapSwitch": (function(_this) {
|
513
|
+
return function(e) {
|
514
|
+
e.preventDefault();
|
515
|
+
return _this.$wrapper.addClass("" + _this.options.baseClass + "-focused");
|
516
|
+
};
|
517
|
+
})(this),
|
518
|
+
"blur.bootstrapSwitch": (function(_this) {
|
519
|
+
return function(e) {
|
520
|
+
e.preventDefault();
|
521
|
+
return _this.$wrapper.removeClass("" + _this.options.baseClass + "-focused");
|
522
|
+
};
|
523
|
+
})(this),
|
524
|
+
"keydown.bootstrapSwitch": (function(_this) {
|
525
|
+
return function(e) {
|
526
|
+
if (!e.which || _this.options.disabled || _this.options.readonly) {
|
527
|
+
return;
|
528
|
+
}
|
529
|
+
switch (e.which) {
|
530
|
+
case 37:
|
531
|
+
e.preventDefault();
|
532
|
+
e.stopImmediatePropagation();
|
533
|
+
return _this.state(false);
|
534
|
+
case 39:
|
535
|
+
e.preventDefault();
|
536
|
+
e.stopImmediatePropagation();
|
537
|
+
return _this.state(true);
|
538
|
+
}
|
539
|
+
};
|
540
|
+
})(this)
|
541
|
+
});
|
542
|
+
};
|
543
|
+
|
544
|
+
BootstrapSwitch.prototype._handleHandlers = function() {
|
545
|
+
this.$on.on("click.bootstrapSwitch", (function(_this) {
|
546
|
+
return function(event) {
|
547
|
+
event.preventDefault();
|
548
|
+
event.stopPropagation();
|
549
|
+
_this.state(false);
|
550
|
+
return _this.$element.trigger("focus.bootstrapSwitch");
|
551
|
+
};
|
552
|
+
})(this));
|
553
|
+
return this.$off.on("click.bootstrapSwitch", (function(_this) {
|
554
|
+
return function(event) {
|
555
|
+
event.preventDefault();
|
556
|
+
event.stopPropagation();
|
557
|
+
_this.state(true);
|
558
|
+
return _this.$element.trigger("focus.bootstrapSwitch");
|
559
|
+
};
|
560
|
+
})(this));
|
561
|
+
};
|
562
|
+
|
563
|
+
BootstrapSwitch.prototype._labelHandlers = function() {
|
564
|
+
return this.$label.on({
|
565
|
+
"mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) {
|
566
|
+
return function(e) {
|
567
|
+
if (_this._dragStart || _this.options.disabled || _this.options.readonly) {
|
568
|
+
return;
|
569
|
+
}
|
570
|
+
e.preventDefault();
|
571
|
+
e.stopPropagation();
|
572
|
+
_this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10);
|
573
|
+
if (_this.options.animate) {
|
574
|
+
_this.$wrapper.removeClass("" + _this.options.baseClass + "-animate");
|
575
|
+
}
|
576
|
+
return _this.$element.trigger("focus.bootstrapSwitch");
|
577
|
+
};
|
578
|
+
})(this),
|
579
|
+
"mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) {
|
580
|
+
return function(e) {
|
581
|
+
var difference;
|
582
|
+
if (_this._dragStart == null) {
|
583
|
+
return;
|
584
|
+
}
|
585
|
+
e.preventDefault();
|
586
|
+
difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart;
|
587
|
+
if (difference < -_this._handleWidth || difference > 0) {
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
_this._dragEnd = difference;
|
591
|
+
return _this.$container.css("margin-left", "" + _this._dragEnd + "px");
|
592
|
+
};
|
593
|
+
})(this),
|
594
|
+
"mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) {
|
595
|
+
return function(e) {
|
596
|
+
var state;
|
597
|
+
if (!_this._dragStart) {
|
598
|
+
return;
|
599
|
+
}
|
600
|
+
e.preventDefault();
|
601
|
+
if (_this.options.animate) {
|
602
|
+
_this.$wrapper.addClass("" + _this.options.baseClass + "-animate");
|
603
|
+
}
|
604
|
+
if (_this._dragEnd) {
|
605
|
+
state = _this._dragEnd > -(_this._handleWidth / 2);
|
606
|
+
_this._dragEnd = false;
|
607
|
+
_this.state(_this.options.inverse ? !state : state);
|
608
|
+
} else {
|
609
|
+
_this.state(!_this.options.state);
|
610
|
+
}
|
611
|
+
return _this._dragStart = false;
|
612
|
+
};
|
613
|
+
})(this),
|
614
|
+
"mouseleave.bootstrapSwitch": (function(_this) {
|
615
|
+
return function(e) {
|
616
|
+
return _this.$label.trigger("mouseup.bootstrapSwitch");
|
617
|
+
};
|
618
|
+
})(this)
|
619
|
+
});
|
620
|
+
};
|
621
|
+
|
622
|
+
BootstrapSwitch.prototype._externalLabelHandler = function() {
|
623
|
+
var $externalLabel;
|
624
|
+
$externalLabel = this.$element.closest("label");
|
625
|
+
return $externalLabel.on("click", (function(_this) {
|
626
|
+
return function(event) {
|
627
|
+
event.preventDefault();
|
628
|
+
event.stopImmediatePropagation();
|
629
|
+
if (event.target === $externalLabel[0]) {
|
630
|
+
return _this.toggleState();
|
631
|
+
}
|
632
|
+
};
|
633
|
+
})(this));
|
634
|
+
};
|
635
|
+
|
636
|
+
BootstrapSwitch.prototype._formHandler = function() {
|
637
|
+
var $form;
|
638
|
+
$form = this.$element.closest("form");
|
639
|
+
if ($form.data("bootstrap-switch")) {
|
640
|
+
return;
|
641
|
+
}
|
642
|
+
return $form.on("reset.bootstrapSwitch", function() {
|
643
|
+
return window.setTimeout(function() {
|
644
|
+
return $form.find("input").filter(function() {
|
645
|
+
return $(this).data("bootstrap-switch");
|
646
|
+
}).each(function() {
|
647
|
+
return $(this).bootstrapSwitch("state", this.checked);
|
648
|
+
});
|
649
|
+
}, 1);
|
650
|
+
}).data("bootstrap-switch", true);
|
651
|
+
};
|
652
|
+
|
653
|
+
BootstrapSwitch.prototype._getClasses = function(classes) {
|
654
|
+
var c, cls, _i, _len;
|
655
|
+
if (!$.isArray(classes)) {
|
656
|
+
return ["" + this.options.baseClass + "-" + classes];
|
657
|
+
}
|
658
|
+
cls = [];
|
659
|
+
for (_i = 0, _len = classes.length; _i < _len; _i++) {
|
660
|
+
c = classes[_i];
|
661
|
+
cls.push("" + this.options.baseClass + "-" + c);
|
662
|
+
}
|
663
|
+
return cls;
|
664
|
+
};
|
665
|
+
|
666
|
+
return BootstrapSwitch;
|
667
|
+
|
668
|
+
})();
|
669
|
+
$.fn.bootstrapSwitch = function() {
|
670
|
+
var args, option, ret;
|
671
|
+
option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
672
|
+
ret = this;
|
673
|
+
this.each(function() {
|
674
|
+
var $this, data;
|
675
|
+
$this = $(this);
|
676
|
+
data = $this.data("bootstrap-switch");
|
677
|
+
if (!data) {
|
678
|
+
$this.data("bootstrap-switch", data = new BootstrapSwitch(this, option));
|
679
|
+
}
|
680
|
+
if (typeof option === "string") {
|
681
|
+
return ret = data[option].apply(data, args);
|
682
|
+
}
|
683
|
+
});
|
684
|
+
return ret;
|
685
|
+
};
|
686
|
+
$.fn.bootstrapSwitch.Constructor = BootstrapSwitch;
|
687
|
+
return $.fn.bootstrapSwitch.defaults = {
|
688
|
+
state: true,
|
689
|
+
size: null,
|
690
|
+
animate: true,
|
691
|
+
disabled: false,
|
692
|
+
readonly: false,
|
693
|
+
indeterminate: false,
|
694
|
+
inverse: false,
|
695
|
+
radioAllOff: false,
|
696
|
+
onColor: "primary",
|
697
|
+
offColor: "default",
|
698
|
+
onText: "ON",
|
699
|
+
offText: "OFF",
|
700
|
+
labelText: " ",
|
701
|
+
handleWidth: "auto",
|
702
|
+
labelWidth: "auto",
|
703
|
+
baseClass: "bootstrap-switch",
|
704
|
+
wrapperClass: "wrapper",
|
705
|
+
onInit: function() {},
|
706
|
+
onSwitchChange: function() {}
|
707
|
+
};
|
708
|
+
})(window.jQuery, window);
|
709
|
+
|
710
|
+
}).call(this);
|