Commit 374fb7715c047a73fcfa5fe354e6825fe62f6d66
1 parent
df71ab61
+ bootstrap switch
Showing
4 changed files
with
983 additions
and
0 deletions
Show diff stats
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 | +.bootstrap-switch { | |
23 | + display: inline-block; | |
24 | + direction: ltr; | |
25 | + cursor: pointer; | |
26 | + border-radius: 4px; | |
27 | + border: 1px solid; | |
28 | + border-color: #cccccc; | |
29 | + position: relative; | |
30 | + text-align: left; | |
31 | + overflow: hidden; | |
32 | + line-height: 8px; | |
33 | + z-index: 0; | |
34 | + -webkit-user-select: none; | |
35 | + -moz-user-select: none; | |
36 | + -ms-user-select: none; | |
37 | + user-select: none; | |
38 | + vertical-align: middle; | |
39 | + -webkit-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; | |
40 | + -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; | |
41 | + transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; | |
42 | +} | |
43 | +.bootstrap-switch .bootstrap-switch-container { | |
44 | + display: inline-block; | |
45 | + top: 0; | |
46 | + border-radius: 4px; | |
47 | + -webkit-transform: translate3d(0, 0, 0); | |
48 | + transform: translate3d(0, 0, 0); | |
49 | +} | |
50 | +.bootstrap-switch .bootstrap-switch-handle-on, | |
51 | +.bootstrap-switch .bootstrap-switch-handle-off, | |
52 | +.bootstrap-switch .bootstrap-switch-label { | |
53 | + -webkit-box-sizing: border-box; | |
54 | + -moz-box-sizing: border-box; | |
55 | + box-sizing: border-box; | |
56 | + cursor: pointer; | |
57 | + display: inline-block !important; | |
58 | + height: 100%; | |
59 | + padding: 6px 12px; | |
60 | + font-size: 14px; | |
61 | + line-height: 20px; | |
62 | +} | |
63 | +.bootstrap-switch .bootstrap-switch-handle-on, | |
64 | +.bootstrap-switch .bootstrap-switch-handle-off { | |
65 | + text-align: center; | |
66 | + z-index: 1; | |
67 | +} | |
68 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-primary, | |
69 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-primary { | |
70 | + color: #fff; | |
71 | + background: #337ab7; | |
72 | +} | |
73 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-info, | |
74 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-info { | |
75 | + color: #fff; | |
76 | + background: #5bc0de; | |
77 | +} | |
78 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success, | |
79 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success { | |
80 | + color: #fff; | |
81 | + background: #5cb85c; | |
82 | +} | |
83 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning, | |
84 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning { | |
85 | + background: #f0ad4e; | |
86 | + color: #fff; | |
87 | +} | |
88 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-danger, | |
89 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-danger { | |
90 | + color: #fff; | |
91 | + background: #d9534f; | |
92 | +} | |
93 | +.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-default, | |
94 | +.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-default { | |
95 | + color: #000; | |
96 | + background: #eeeeee; | |
97 | +} | |
98 | +.bootstrap-switch .bootstrap-switch-label { | |
99 | + text-align: center; | |
100 | + margin-top: -1px; | |
101 | + margin-bottom: -1px; | |
102 | + z-index: 100; | |
103 | + color: #333333; | |
104 | + background: #ffffff; | |
105 | +} | |
106 | +.bootstrap-switch .bootstrap-switch-handle-on { | |
107 | + border-bottom-left-radius: 3px; | |
108 | + border-top-left-radius: 3px; | |
109 | +} | |
110 | +.bootstrap-switch .bootstrap-switch-handle-off { | |
111 | + border-bottom-right-radius: 3px; | |
112 | + border-top-right-radius: 3px; | |
113 | +} | |
114 | +.bootstrap-switch input[type='radio'], | |
115 | +.bootstrap-switch input[type='checkbox'] { | |
116 | + position: absolute !important; | |
117 | + top: 0; | |
118 | + left: 0; | |
119 | + margin: 0; | |
120 | + z-index: -1; | |
121 | + opacity: 0; | |
122 | + filter: alpha(opacity=0); | |
123 | +} | |
124 | +.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-on, | |
125 | +.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-off, | |
126 | +.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-label { | |
127 | + padding: 1px 5px; | |
128 | + font-size: 12px; | |
129 | + line-height: 1.5; | |
130 | +} | |
131 | +.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-on, | |
132 | +.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-off, | |
133 | +.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-label { | |
134 | + padding: 5px 10px; | |
135 | + font-size: 12px; | |
136 | + line-height: 1.5; | |
137 | +} | |
138 | +.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-on, | |
139 | +.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-off, | |
140 | +.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-label { | |
141 | + padding: 6px 16px; | |
142 | + font-size: 18px; | |
143 | + line-height: 1.3333333; | |
144 | +} | |
145 | +.bootstrap-switch.bootstrap-switch-disabled, | |
146 | +.bootstrap-switch.bootstrap-switch-readonly, | |
147 | +.bootstrap-switch.bootstrap-switch-indeterminate { | |
148 | + cursor: default !important; | |
149 | +} | |
150 | +.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-on, | |
151 | +.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-on, | |
152 | +.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-on, | |
153 | +.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-off, | |
154 | +.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-off, | |
155 | +.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-off, | |
156 | +.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-label, | |
157 | +.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label, | |
158 | +.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-label { | |
159 | + opacity: 0.5; | |
160 | + filter: alpha(opacity=50); | |
161 | + cursor: default !important; | |
162 | +} | |
163 | +.bootstrap-switch.bootstrap-switch-animate .bootstrap-switch-container { | |
164 | + -webkit-transition: margin-left 0.5s; | |
165 | + -o-transition: margin-left 0.5s; | |
166 | + transition: margin-left 0.5s; | |
167 | +} | |
168 | +.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-on { | |
169 | + border-bottom-left-radius: 0; | |
170 | + border-top-left-radius: 0; | |
171 | + border-bottom-right-radius: 3px; | |
172 | + border-top-right-radius: 3px; | |
173 | +} | |
174 | +.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-off { | |
175 | + border-bottom-right-radius: 0; | |
176 | + border-top-right-radius: 0; | |
177 | + border-bottom-left-radius: 3px; | |
178 | + border-top-left-radius: 3px; | |
179 | +} | |
180 | +.bootstrap-switch.bootstrap-switch-focused { | |
181 | + border-color: #66afe9; | |
182 | + outline: 0; | |
183 | + -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); | |
184 | + box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, 0.6); | |
185 | +} | |
186 | +.bootstrap-switch.bootstrap-switch-on .bootstrap-switch-label, | |
187 | +.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-off .bootstrap-switch-label { | |
188 | + border-bottom-right-radius: 3px; | |
189 | + border-top-right-radius: 3px; | |
190 | +} | |
191 | +.bootstrap-switch.bootstrap-switch-off .bootstrap-switch-label, | |
192 | +.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-on .bootstrap-switch-label { | |
193 | + border-bottom-left-radius: 3px; | |
194 | + border-top-left-radius: 3px; | |
195 | +} | ... | ... |
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 | +.bootstrap-switch{display:inline-block;direction:ltr;cursor:pointer;border-radius:4px;border:1px solid #ccc;position:relative;text-align:left;overflow:hidden;line-height:8px;z-index:0;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;vertical-align:middle;-webkit-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.bootstrap-switch .bootstrap-switch-container{display:inline-block;top:0;border-radius:4px;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}.bootstrap-switch .bootstrap-switch-handle-off,.bootstrap-switch .bootstrap-switch-handle-on,.bootstrap-switch .bootstrap-switch-label{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;cursor:pointer;display:inline-block!important;height:100%;padding:6px 12px;font-size:14px;line-height:20px}.bootstrap-switch .bootstrap-switch-handle-off,.bootstrap-switch .bootstrap-switch-handle-on{text-align:center;z-index:1}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-primary,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-primary{color:#fff;background:#337ab7}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-info,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-info{color:#fff;background:#5bc0de}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-success,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-success{color:#fff;background:#5cb85c}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-warning,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-warning{background:#f0ad4e;color:#fff}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-danger,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-danger{color:#fff;background:#d9534f}.bootstrap-switch .bootstrap-switch-handle-off.bootstrap-switch-default,.bootstrap-switch .bootstrap-switch-handle-on.bootstrap-switch-default{color:#000;background:#eee}.bootstrap-switch .bootstrap-switch-label{text-align:center;margin-top:-1px;margin-bottom:-1px;z-index:100;color:#333;background:#fff}.bootstrap-switch .bootstrap-switch-handle-on{border-bottom-left-radius:3px;border-top-left-radius:3px}.bootstrap-switch .bootstrap-switch-handle-off{border-bottom-right-radius:3px;border-top-right-radius:3px}.bootstrap-switch input[type=radio],.bootstrap-switch input[type=checkbox]{position:absolute!important;top:0;left:0;margin:0;z-index:-1;opacity:0;filter:alpha(opacity=0)}.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-mini .bootstrap-switch-label{padding:1px 5px;font-size:12px;line-height:1.5}.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-small .bootstrap-switch-label{padding:5px 10px;font-size:12px;line-height:1.5}.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-large .bootstrap-switch-label{padding:6px 16px;font-size:18px;line-height:1.3333333}.bootstrap-switch.bootstrap-switch-disabled,.bootstrap-switch.bootstrap-switch-indeterminate,.bootstrap-switch.bootstrap-switch-readonly{cursor:default!important}.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-disabled .bootstrap-switch-label,.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-indeterminate .bootstrap-switch-label,.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-off,.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-handle-on,.bootstrap-switch.bootstrap-switch-readonly .bootstrap-switch-label{opacity:.5;filter:alpha(opacity=50);cursor:default!important}.bootstrap-switch.bootstrap-switch-animate .bootstrap-switch-container{-webkit-transition:margin-left .5s;-o-transition:margin-left .5s;transition:margin-left .5s}.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-on{border-radius:0 3px 3px 0}.bootstrap-switch.bootstrap-switch-inverse .bootstrap-switch-handle-off{border-radius:3px 0 0 3px}.bootstrap-switch.bootstrap-switch-focused{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-off .bootstrap-switch-label,.bootstrap-switch.bootstrap-switch-on .bootstrap-switch-label{border-bottom-right-radius:3px;border-top-right-radius:3px}.bootstrap-switch.bootstrap-switch-inverse.bootstrap-switch-on .bootstrap-switch-label,.bootstrap-switch.bootstrap-switch-off .bootstrap-switch-label{border-bottom-left-radius:3px;border-top-left-radius:3px} | |
0 | 23 | \ No newline at end of file | ... | ... |
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.prevOptions = {}; | |
54 | + this.$wrapper = $("<div>", { | |
55 | + "class": (function(_this) { | |
56 | + return function() { | |
57 | + var classes; | |
58 | + classes = ["" + _this.options.baseClass].concat(_this._getClasses(_this.options.wrapperClass)); | |
59 | + classes.push(_this.options.state ? _this.options.baseClass + "-on" : _this.options.baseClass + "-off"); | |
60 | + if (_this.options.size != null) { | |
61 | + classes.push(_this.options.baseClass + "-" + _this.options.size); | |
62 | + } | |
63 | + if (_this.options.disabled) { | |
64 | + classes.push(_this.options.baseClass + "-disabled"); | |
65 | + } | |
66 | + if (_this.options.readonly) { | |
67 | + classes.push(_this.options.baseClass + "-readonly"); | |
68 | + } | |
69 | + if (_this.options.indeterminate) { | |
70 | + classes.push(_this.options.baseClass + "-indeterminate"); | |
71 | + } | |
72 | + if (_this.options.inverse) { | |
73 | + classes.push(_this.options.baseClass + "-inverse"); | |
74 | + } | |
75 | + if (_this.$element.attr("id")) { | |
76 | + classes.push(_this.options.baseClass + "-id-" + (_this.$element.attr("id"))); | |
77 | + } | |
78 | + return classes.join(" "); | |
79 | + }; | |
80 | + })(this)() | |
81 | + }); | |
82 | + this.$container = $("<div>", { | |
83 | + "class": this.options.baseClass + "-container" | |
84 | + }); | |
85 | + this.$on = $("<span>", { | |
86 | + html: this.options.onText, | |
87 | + "class": this.options.baseClass + "-handle-on " + this.options.baseClass + "-" + this.options.onColor | |
88 | + }); | |
89 | + this.$off = $("<span>", { | |
90 | + html: this.options.offText, | |
91 | + "class": this.options.baseClass + "-handle-off " + this.options.baseClass + "-" + this.options.offColor | |
92 | + }); | |
93 | + this.$label = $("<span>", { | |
94 | + html: this.options.labelText, | |
95 | + "class": this.options.baseClass + "-label" | |
96 | + }); | |
97 | + this.$element.on("init.bootstrapSwitch", (function(_this) { | |
98 | + return function() { | |
99 | + return _this.options.onInit.apply(element, arguments); | |
100 | + }; | |
101 | + })(this)); | |
102 | + this.$element.on("switchChange.bootstrapSwitch", (function(_this) { | |
103 | + return function(e) { | |
104 | + if (false === _this.options.onSwitchChange.apply(element, arguments)) { | |
105 | + if (_this.$element.is(":radio")) { | |
106 | + return $("[name='" + (_this.$element.attr('name')) + "']").trigger("previousState.bootstrapSwitch", true); | |
107 | + } else { | |
108 | + return _this.$element.trigger("previousState.bootstrapSwitch", true); | |
109 | + } | |
110 | + } | |
111 | + }; | |
112 | + })(this)); | |
113 | + this.$container = this.$element.wrap(this.$container).parent(); | |
114 | + this.$wrapper = this.$container.wrap(this.$wrapper).parent(); | |
115 | + this.$element.before(this.options.inverse ? this.$off : this.$on).before(this.$label).before(this.options.inverse ? this.$on : this.$off); | |
116 | + if (this.options.indeterminate) { | |
117 | + this.$element.prop("indeterminate", true); | |
118 | + } | |
119 | + this._init(); | |
120 | + this._elementHandlers(); | |
121 | + this._handleHandlers(); | |
122 | + this._labelHandlers(); | |
123 | + this._formHandler(); | |
124 | + this._externalLabelHandler(); | |
125 | + this.$element.trigger("init.bootstrapSwitch", this.options.state); | |
126 | + } | |
127 | + | |
128 | + BootstrapSwitch.prototype._constructor = BootstrapSwitch; | |
129 | + | |
130 | + BootstrapSwitch.prototype.setPrevOptions = function() { | |
131 | + return this.prevOptions = $.extend(true, {}, this.options); | |
132 | + }; | |
133 | + | |
134 | + BootstrapSwitch.prototype.state = function(value, skip) { | |
135 | + if (typeof value === "undefined") { | |
136 | + return this.options.state; | |
137 | + } | |
138 | + if (this.options.disabled || this.options.readonly) { | |
139 | + return this.$element; | |
140 | + } | |
141 | + if (this.options.state && !this.options.radioAllOff && this.$element.is(":radio")) { | |
142 | + return this.$element; | |
143 | + } | |
144 | + if (this.$element.is(":radio")) { | |
145 | + $("[name='" + (this.$element.attr('name')) + "']").trigger("setPreviousOptions.bootstrapSwitch"); | |
146 | + } else { | |
147 | + this.$element.trigger("setPreviousOptions.bootstrapSwitch"); | |
148 | + } | |
149 | + if (this.options.indeterminate) { | |
150 | + this.indeterminate(false); | |
151 | + } | |
152 | + value = !!value; | |
153 | + this.$element.prop("checked", value).trigger("change.bootstrapSwitch", skip); | |
154 | + return this.$element; | |
155 | + }; | |
156 | + | |
157 | + BootstrapSwitch.prototype.toggleState = function(skip) { | |
158 | + if (this.options.disabled || this.options.readonly) { | |
159 | + return this.$element; | |
160 | + } | |
161 | + if (this.options.indeterminate) { | |
162 | + this.indeterminate(false); | |
163 | + return this.state(true); | |
164 | + } else { | |
165 | + return this.$element.prop("checked", !this.options.state).trigger("change.bootstrapSwitch", skip); | |
166 | + } | |
167 | + }; | |
168 | + | |
169 | + BootstrapSwitch.prototype.size = function(value) { | |
170 | + if (typeof value === "undefined") { | |
171 | + return this.options.size; | |
172 | + } | |
173 | + if (this.options.size != null) { | |
174 | + this.$wrapper.removeClass(this.options.baseClass + "-" + this.options.size); | |
175 | + } | |
176 | + if (value) { | |
177 | + this.$wrapper.addClass(this.options.baseClass + "-" + value); | |
178 | + } | |
179 | + this._width(); | |
180 | + this._containerPosition(); | |
181 | + this.options.size = value; | |
182 | + return this.$element; | |
183 | + }; | |
184 | + | |
185 | + BootstrapSwitch.prototype.animate = function(value) { | |
186 | + if (typeof value === "undefined") { | |
187 | + return this.options.animate; | |
188 | + } | |
189 | + value = !!value; | |
190 | + if (value === this.options.animate) { | |
191 | + return this.$element; | |
192 | + } | |
193 | + return this.toggleAnimate(); | |
194 | + }; | |
195 | + | |
196 | + BootstrapSwitch.prototype.toggleAnimate = function() { | |
197 | + this.options.animate = !this.options.animate; | |
198 | + this.$wrapper.toggleClass(this.options.baseClass + "-animate"); | |
199 | + return this.$element; | |
200 | + }; | |
201 | + | |
202 | + BootstrapSwitch.prototype.disabled = function(value) { | |
203 | + if (typeof value === "undefined") { | |
204 | + return this.options.disabled; | |
205 | + } | |
206 | + value = !!value; | |
207 | + if (value === this.options.disabled) { | |
208 | + return this.$element; | |
209 | + } | |
210 | + return this.toggleDisabled(); | |
211 | + }; | |
212 | + | |
213 | + BootstrapSwitch.prototype.toggleDisabled = function() { | |
214 | + this.options.disabled = !this.options.disabled; | |
215 | + this.$element.prop("disabled", this.options.disabled); | |
216 | + this.$wrapper.toggleClass(this.options.baseClass + "-disabled"); | |
217 | + return this.$element; | |
218 | + }; | |
219 | + | |
220 | + BootstrapSwitch.prototype.readonly = function(value) { | |
221 | + if (typeof value === "undefined") { | |
222 | + return this.options.readonly; | |
223 | + } | |
224 | + value = !!value; | |
225 | + if (value === this.options.readonly) { | |
226 | + return this.$element; | |
227 | + } | |
228 | + return this.toggleReadonly(); | |
229 | + }; | |
230 | + | |
231 | + BootstrapSwitch.prototype.toggleReadonly = function() { | |
232 | + this.options.readonly = !this.options.readonly; | |
233 | + this.$element.prop("readonly", this.options.readonly); | |
234 | + this.$wrapper.toggleClass(this.options.baseClass + "-readonly"); | |
235 | + return this.$element; | |
236 | + }; | |
237 | + | |
238 | + BootstrapSwitch.prototype.indeterminate = function(value) { | |
239 | + if (typeof value === "undefined") { | |
240 | + return this.options.indeterminate; | |
241 | + } | |
242 | + value = !!value; | |
243 | + if (value === this.options.indeterminate) { | |
244 | + return this.$element; | |
245 | + } | |
246 | + return this.toggleIndeterminate(); | |
247 | + }; | |
248 | + | |
249 | + BootstrapSwitch.prototype.toggleIndeterminate = function() { | |
250 | + this.options.indeterminate = !this.options.indeterminate; | |
251 | + this.$element.prop("indeterminate", this.options.indeterminate); | |
252 | + this.$wrapper.toggleClass(this.options.baseClass + "-indeterminate"); | |
253 | + this._containerPosition(); | |
254 | + return this.$element; | |
255 | + }; | |
256 | + | |
257 | + BootstrapSwitch.prototype.inverse = function(value) { | |
258 | + if (typeof value === "undefined") { | |
259 | + return this.options.inverse; | |
260 | + } | |
261 | + value = !!value; | |
262 | + if (value === this.options.inverse) { | |
263 | + return this.$element; | |
264 | + } | |
265 | + return this.toggleInverse(); | |
266 | + }; | |
267 | + | |
268 | + BootstrapSwitch.prototype.toggleInverse = function() { | |
269 | + var $off, $on; | |
270 | + this.$wrapper.toggleClass(this.options.baseClass + "-inverse"); | |
271 | + $on = this.$on.clone(true); | |
272 | + $off = this.$off.clone(true); | |
273 | + this.$on.replaceWith($off); | |
274 | + this.$off.replaceWith($on); | |
275 | + this.$on = $off; | |
276 | + this.$off = $on; | |
277 | + this.options.inverse = !this.options.inverse; | |
278 | + return this.$element; | |
279 | + }; | |
280 | + | |
281 | + BootstrapSwitch.prototype.onColor = function(value) { | |
282 | + var color; | |
283 | + color = this.options.onColor; | |
284 | + if (typeof value === "undefined") { | |
285 | + return color; | |
286 | + } | |
287 | + if (color != null) { | |
288 | + this.$on.removeClass(this.options.baseClass + "-" + color); | |
289 | + } | |
290 | + this.$on.addClass(this.options.baseClass + "-" + value); | |
291 | + this.options.onColor = value; | |
292 | + return this.$element; | |
293 | + }; | |
294 | + | |
295 | + BootstrapSwitch.prototype.offColor = function(value) { | |
296 | + var color; | |
297 | + color = this.options.offColor; | |
298 | + if (typeof value === "undefined") { | |
299 | + return color; | |
300 | + } | |
301 | + if (color != null) { | |
302 | + this.$off.removeClass(this.options.baseClass + "-" + color); | |
303 | + } | |
304 | + this.$off.addClass(this.options.baseClass + "-" + value); | |
305 | + this.options.offColor = value; | |
306 | + return this.$element; | |
307 | + }; | |
308 | + | |
309 | + BootstrapSwitch.prototype.onText = function(value) { | |
310 | + if (typeof value === "undefined") { | |
311 | + return this.options.onText; | |
312 | + } | |
313 | + this.$on.html(value); | |
314 | + this._width(); | |
315 | + this._containerPosition(); | |
316 | + this.options.onText = value; | |
317 | + return this.$element; | |
318 | + }; | |
319 | + | |
320 | + BootstrapSwitch.prototype.offText = function(value) { | |
321 | + if (typeof value === "undefined") { | |
322 | + return this.options.offText; | |
323 | + } | |
324 | + this.$off.html(value); | |
325 | + this._width(); | |
326 | + this._containerPosition(); | |
327 | + this.options.offText = value; | |
328 | + return this.$element; | |
329 | + }; | |
330 | + | |
331 | + BootstrapSwitch.prototype.labelText = function(value) { | |
332 | + if (typeof value === "undefined") { | |
333 | + return this.options.labelText; | |
334 | + } | |
335 | + this.$label.html(value); | |
336 | + this._width(); | |
337 | + this.options.labelText = value; | |
338 | + return this.$element; | |
339 | + }; | |
340 | + | |
341 | + BootstrapSwitch.prototype.handleWidth = function(value) { | |
342 | + if (typeof value === "undefined") { | |
343 | + return this.options.handleWidth; | |
344 | + } | |
345 | + this.options.handleWidth = value; | |
346 | + this._width(); | |
347 | + this._containerPosition(); | |
348 | + return this.$element; | |
349 | + }; | |
350 | + | |
351 | + BootstrapSwitch.prototype.labelWidth = function(value) { | |
352 | + if (typeof value === "undefined") { | |
353 | + return this.options.labelWidth; | |
354 | + } | |
355 | + this.options.labelWidth = value; | |
356 | + this._width(); | |
357 | + this._containerPosition(); | |
358 | + return this.$element; | |
359 | + }; | |
360 | + | |
361 | + BootstrapSwitch.prototype.baseClass = function(value) { | |
362 | + return this.options.baseClass; | |
363 | + }; | |
364 | + | |
365 | + BootstrapSwitch.prototype.wrapperClass = function(value) { | |
366 | + if (typeof value === "undefined") { | |
367 | + return this.options.wrapperClass; | |
368 | + } | |
369 | + if (!value) { | |
370 | + value = $.fn.bootstrapSwitch.defaults.wrapperClass; | |
371 | + } | |
372 | + this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" ")); | |
373 | + this.$wrapper.addClass(this._getClasses(value).join(" ")); | |
374 | + this.options.wrapperClass = value; | |
375 | + return this.$element; | |
376 | + }; | |
377 | + | |
378 | + BootstrapSwitch.prototype.radioAllOff = function(value) { | |
379 | + if (typeof value === "undefined") { | |
380 | + return this.options.radioAllOff; | |
381 | + } | |
382 | + value = !!value; | |
383 | + if (value === this.options.radioAllOff) { | |
384 | + return this.$element; | |
385 | + } | |
386 | + this.options.radioAllOff = value; | |
387 | + return this.$element; | |
388 | + }; | |
389 | + | |
390 | + BootstrapSwitch.prototype.onInit = function(value) { | |
391 | + if (typeof value === "undefined") { | |
392 | + return this.options.onInit; | |
393 | + } | |
394 | + if (!value) { | |
395 | + value = $.fn.bootstrapSwitch.defaults.onInit; | |
396 | + } | |
397 | + this.options.onInit = value; | |
398 | + return this.$element; | |
399 | + }; | |
400 | + | |
401 | + BootstrapSwitch.prototype.onSwitchChange = function(value) { | |
402 | + if (typeof value === "undefined") { | |
403 | + return this.options.onSwitchChange; | |
404 | + } | |
405 | + if (!value) { | |
406 | + value = $.fn.bootstrapSwitch.defaults.onSwitchChange; | |
407 | + } | |
408 | + this.options.onSwitchChange = value; | |
409 | + return this.$element; | |
410 | + }; | |
411 | + | |
412 | + BootstrapSwitch.prototype.destroy = function() { | |
413 | + var $form; | |
414 | + $form = this.$element.closest("form"); | |
415 | + if ($form.length) { | |
416 | + $form.off("reset.bootstrapSwitch").removeData("bootstrap-switch"); | |
417 | + } | |
418 | + this.$container.children().not(this.$element).remove(); | |
419 | + this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch"); | |
420 | + return this.$element; | |
421 | + }; | |
422 | + | |
423 | + BootstrapSwitch.prototype._width = function() { | |
424 | + var $handles, handleWidth; | |
425 | + $handles = this.$on.add(this.$off); | |
426 | + $handles.add(this.$label).css("width", ""); | |
427 | + handleWidth = this.options.handleWidth === "auto" ? Math.max(this.$on.width(), this.$off.width()) : this.options.handleWidth; | |
428 | + $handles.width(handleWidth); | |
429 | + this.$label.width((function(_this) { | |
430 | + return function(index, width) { | |
431 | + if (_this.options.labelWidth !== "auto") { | |
432 | + return _this.options.labelWidth; | |
433 | + } | |
434 | + if (width < handleWidth) { | |
435 | + return handleWidth; | |
436 | + } else { | |
437 | + return width; | |
438 | + } | |
439 | + }; | |
440 | + })(this)); | |
441 | + this._handleWidth = this.$on.outerWidth(); | |
442 | + this._labelWidth = this.$label.outerWidth(); | |
443 | + this.$container.width((this._handleWidth * 2) + this._labelWidth); | |
444 | + return this.$wrapper.width(this._handleWidth + this._labelWidth); | |
445 | + }; | |
446 | + | |
447 | + BootstrapSwitch.prototype._containerPosition = function(state, callback) { | |
448 | + if (state == null) { | |
449 | + state = this.options.state; | |
450 | + } | |
451 | + this.$container.css("margin-left", (function(_this) { | |
452 | + return function() { | |
453 | + var values; | |
454 | + values = [0, "-" + _this._handleWidth + "px"]; | |
455 | + if (_this.options.indeterminate) { | |
456 | + return "-" + (_this._handleWidth / 2) + "px"; | |
457 | + } | |
458 | + if (state) { | |
459 | + if (_this.options.inverse) { | |
460 | + return values[1]; | |
461 | + } else { | |
462 | + return values[0]; | |
463 | + } | |
464 | + } else { | |
465 | + if (_this.options.inverse) { | |
466 | + return values[0]; | |
467 | + } else { | |
468 | + return values[1]; | |
469 | + } | |
470 | + } | |
471 | + }; | |
472 | + })(this)); | |
473 | + if (!callback) { | |
474 | + return; | |
475 | + } | |
476 | + return setTimeout(function() { | |
477 | + return callback(); | |
478 | + }, 50); | |
479 | + }; | |
480 | + | |
481 | + BootstrapSwitch.prototype._init = function() { | |
482 | + var init, initInterval; | |
483 | + init = (function(_this) { | |
484 | + return function() { | |
485 | + _this.setPrevOptions(); | |
486 | + _this._width(); | |
487 | + return _this._containerPosition(null, function() { | |
488 | + if (_this.options.animate) { | |
489 | + return _this.$wrapper.addClass(_this.options.baseClass + "-animate"); | |
490 | + } | |
491 | + }); | |
492 | + }; | |
493 | + })(this); | |
494 | + if (this.$wrapper.is(":visible")) { | |
495 | + return init(); | |
496 | + } | |
497 | + return initInterval = window.setInterval((function(_this) { | |
498 | + return function() { | |
499 | + if (_this.$wrapper.is(":visible")) { | |
500 | + init(); | |
501 | + return window.clearInterval(initInterval); | |
502 | + } | |
503 | + }; | |
504 | + })(this), 50); | |
505 | + }; | |
506 | + | |
507 | + BootstrapSwitch.prototype._elementHandlers = function() { | |
508 | + return this.$element.on({ | |
509 | + "setPreviousOptions.bootstrapSwitch": (function(_this) { | |
510 | + return function(e) { | |
511 | + return _this.setPrevOptions(); | |
512 | + }; | |
513 | + })(this), | |
514 | + "previousState.bootstrapSwitch": (function(_this) { | |
515 | + return function(e) { | |
516 | + _this.options = _this.prevOptions; | |
517 | + if (_this.options.indeterminate) { | |
518 | + _this.$wrapper.addClass(_this.options.baseClass + "-indeterminate"); | |
519 | + } | |
520 | + return _this.$element.prop("checked", _this.options.state).trigger("change.bootstrapSwitch", true); | |
521 | + }; | |
522 | + })(this), | |
523 | + "change.bootstrapSwitch": (function(_this) { | |
524 | + return function(e, skip) { | |
525 | + var state; | |
526 | + e.preventDefault(); | |
527 | + e.stopImmediatePropagation(); | |
528 | + state = _this.$element.is(":checked"); | |
529 | + _this._containerPosition(state); | |
530 | + if (state === _this.options.state) { | |
531 | + return; | |
532 | + } | |
533 | + _this.options.state = state; | |
534 | + _this.$wrapper.toggleClass(_this.options.baseClass + "-off").toggleClass(_this.options.baseClass + "-on"); | |
535 | + if (!skip) { | |
536 | + if (_this.$element.is(":radio")) { | |
537 | + $("[name='" + (_this.$element.attr('name')) + "']").not(_this.$element).prop("checked", false).trigger("change.bootstrapSwitch", true); | |
538 | + } | |
539 | + return _this.$element.trigger("switchChange.bootstrapSwitch", [state]); | |
540 | + } | |
541 | + }; | |
542 | + })(this), | |
543 | + "focus.bootstrapSwitch": (function(_this) { | |
544 | + return function(e) { | |
545 | + e.preventDefault(); | |
546 | + return _this.$wrapper.addClass(_this.options.baseClass + "-focused"); | |
547 | + }; | |
548 | + })(this), | |
549 | + "blur.bootstrapSwitch": (function(_this) { | |
550 | + return function(e) { | |
551 | + e.preventDefault(); | |
552 | + return _this.$wrapper.removeClass(_this.options.baseClass + "-focused"); | |
553 | + }; | |
554 | + })(this), | |
555 | + "keydown.bootstrapSwitch": (function(_this) { | |
556 | + return function(e) { | |
557 | + if (!e.which || _this.options.disabled || _this.options.readonly) { | |
558 | + return; | |
559 | + } | |
560 | + switch (e.which) { | |
561 | + case 37: | |
562 | + e.preventDefault(); | |
563 | + e.stopImmediatePropagation(); | |
564 | + return _this.state(false); | |
565 | + case 39: | |
566 | + e.preventDefault(); | |
567 | + e.stopImmediatePropagation(); | |
568 | + return _this.state(true); | |
569 | + } | |
570 | + }; | |
571 | + })(this) | |
572 | + }); | |
573 | + }; | |
574 | + | |
575 | + BootstrapSwitch.prototype._handleHandlers = function() { | |
576 | + this.$on.on("click.bootstrapSwitch", (function(_this) { | |
577 | + return function(event) { | |
578 | + event.preventDefault(); | |
579 | + event.stopPropagation(); | |
580 | + _this.state(false); | |
581 | + return _this.$element.trigger("focus.bootstrapSwitch"); | |
582 | + }; | |
583 | + })(this)); | |
584 | + return this.$off.on("click.bootstrapSwitch", (function(_this) { | |
585 | + return function(event) { | |
586 | + event.preventDefault(); | |
587 | + event.stopPropagation(); | |
588 | + _this.state(true); | |
589 | + return _this.$element.trigger("focus.bootstrapSwitch"); | |
590 | + }; | |
591 | + })(this)); | |
592 | + }; | |
593 | + | |
594 | + BootstrapSwitch.prototype._labelHandlers = function() { | |
595 | + return this.$label.on({ | |
596 | + "click": function(e) { | |
597 | + return e.stopPropagation(); | |
598 | + }, | |
599 | + "mousedown.bootstrapSwitch touchstart.bootstrapSwitch": (function(_this) { | |
600 | + return function(e) { | |
601 | + if (_this._dragStart || _this.options.disabled || _this.options.readonly) { | |
602 | + return; | |
603 | + } | |
604 | + e.preventDefault(); | |
605 | + e.stopPropagation(); | |
606 | + _this._dragStart = (e.pageX || e.originalEvent.touches[0].pageX) - parseInt(_this.$container.css("margin-left"), 10); | |
607 | + if (_this.options.animate) { | |
608 | + _this.$wrapper.removeClass(_this.options.baseClass + "-animate"); | |
609 | + } | |
610 | + return _this.$element.trigger("focus.bootstrapSwitch"); | |
611 | + }; | |
612 | + })(this), | |
613 | + "mousemove.bootstrapSwitch touchmove.bootstrapSwitch": (function(_this) { | |
614 | + return function(e) { | |
615 | + var difference; | |
616 | + if (_this._dragStart == null) { | |
617 | + return; | |
618 | + } | |
619 | + e.preventDefault(); | |
620 | + difference = (e.pageX || e.originalEvent.touches[0].pageX) - _this._dragStart; | |
621 | + if (difference < -_this._handleWidth || difference > 0) { | |
622 | + return; | |
623 | + } | |
624 | + _this._dragEnd = difference; | |
625 | + return _this.$container.css("margin-left", _this._dragEnd + "px"); | |
626 | + }; | |
627 | + })(this), | |
628 | + "mouseup.bootstrapSwitch touchend.bootstrapSwitch": (function(_this) { | |
629 | + return function(e) { | |
630 | + var state; | |
631 | + if (!_this._dragStart) { | |
632 | + return; | |
633 | + } | |
634 | + e.preventDefault(); | |
635 | + if (_this.options.animate) { | |
636 | + _this.$wrapper.addClass(_this.options.baseClass + "-animate"); | |
637 | + } | |
638 | + if (_this._dragEnd) { | |
639 | + state = _this._dragEnd > -(_this._handleWidth / 2); | |
640 | + _this._dragEnd = false; | |
641 | + _this.state(_this.options.inverse ? !state : state); | |
642 | + } else { | |
643 | + _this.state(!_this.options.state); | |
644 | + } | |
645 | + return _this._dragStart = false; | |
646 | + }; | |
647 | + })(this), | |
648 | + "mouseleave.bootstrapSwitch": (function(_this) { | |
649 | + return function(e) { | |
650 | + return _this.$label.trigger("mouseup.bootstrapSwitch"); | |
651 | + }; | |
652 | + })(this) | |
653 | + }); | |
654 | + }; | |
655 | + | |
656 | + BootstrapSwitch.prototype._externalLabelHandler = function() { | |
657 | + var $externalLabel; | |
658 | + $externalLabel = this.$element.closest("label"); | |
659 | + return $externalLabel.on("click", (function(_this) { | |
660 | + return function(event) { | |
661 | + event.preventDefault(); | |
662 | + event.stopImmediatePropagation(); | |
663 | + if (event.target === $externalLabel[0]) { | |
664 | + return _this.toggleState(); | |
665 | + } | |
666 | + }; | |
667 | + })(this)); | |
668 | + }; | |
669 | + | |
670 | + BootstrapSwitch.prototype._formHandler = function() { | |
671 | + var $form; | |
672 | + $form = this.$element.closest("form"); | |
673 | + if ($form.data("bootstrap-switch")) { | |
674 | + return; | |
675 | + } | |
676 | + return $form.on("reset.bootstrapSwitch", function() { | |
677 | + return window.setTimeout(function() { | |
678 | + return $form.find("input").filter(function() { | |
679 | + return $(this).data("bootstrap-switch"); | |
680 | + }).each(function() { | |
681 | + return $(this).bootstrapSwitch("state", this.checked); | |
682 | + }); | |
683 | + }, 1); | |
684 | + }).data("bootstrap-switch", true); | |
685 | + }; | |
686 | + | |
687 | + BootstrapSwitch.prototype._getClasses = function(classes) { | |
688 | + var c, cls, i, len; | |
689 | + if (!$.isArray(classes)) { | |
690 | + return [this.options.baseClass + "-" + classes]; | |
691 | + } | |
692 | + cls = []; | |
693 | + for (i = 0, len = classes.length; i < len; i++) { | |
694 | + c = classes[i]; | |
695 | + cls.push(this.options.baseClass + "-" + c); | |
696 | + } | |
697 | + return cls; | |
698 | + }; | |
699 | + | |
700 | + return BootstrapSwitch; | |
701 | + | |
702 | + })(); | |
703 | + $.fn.bootstrapSwitch = function() { | |
704 | + var args, option, ret; | |
705 | + option = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; | |
706 | + ret = this; | |
707 | + this.each(function() { | |
708 | + var $this, data; | |
709 | + $this = $(this); | |
710 | + data = $this.data("bootstrap-switch"); | |
711 | + if (!data) { | |
712 | + $this.data("bootstrap-switch", data = new BootstrapSwitch(this, option)); | |
713 | + } | |
714 | + if (typeof option === "string") { | |
715 | + return ret = data[option].apply(data, args); | |
716 | + } | |
717 | + }); | |
718 | + return ret; | |
719 | + }; | |
720 | + $.fn.bootstrapSwitch.Constructor = BootstrapSwitch; | |
721 | + return $.fn.bootstrapSwitch.defaults = { | |
722 | + state: true, | |
723 | + size: null, | |
724 | + animate: true, | |
725 | + disabled: false, | |
726 | + readonly: false, | |
727 | + indeterminate: false, | |
728 | + inverse: false, | |
729 | + radioAllOff: false, | |
730 | + onColor: "primary", | |
731 | + offColor: "default", | |
732 | + onText: "ON", | |
733 | + offText: "OFF", | |
734 | + labelText: " ", | |
735 | + handleWidth: "auto", | |
736 | + labelWidth: "auto", | |
737 | + baseClass: "bootstrap-switch", | |
738 | + wrapperClass: "wrapper", | |
739 | + onInit: function() {}, | |
740 | + onSwitchChange: function() {} | |
741 | + }; | |
742 | + })(window.jQuery, window); | |
743 | + | |
744 | +}).call(this); | ... | ... |
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(){var t=[].slice;!function(e,i){"use strict";var n;return n=function(){function t(t,i){null==i&&(i={}),this.$element=e(t),this.options=e.extend({},e.fn.bootstrapSwitch.defaults,{state:this.$element.is(":checked"),size:this.$element.data("size"),animate:this.$element.data("animate"),disabled:this.$element.is(":disabled"),readonly:this.$element.is("[readonly]"),indeterminate:this.$element.data("indeterminate"),inverse:this.$element.data("inverse"),radioAllOff:this.$element.data("radio-all-off"),onColor:this.$element.data("on-color"),offColor:this.$element.data("off-color"),onText:this.$element.data("on-text"),offText:this.$element.data("off-text"),labelText:this.$element.data("label-text"),handleWidth:this.$element.data("handle-width"),labelWidth:this.$element.data("label-width"),baseClass:this.$element.data("base-class"),wrapperClass:this.$element.data("wrapper-class")},i),this.prevOptions={},this.$wrapper=e("<div>",{"class":function(t){return function(){var e;return e=[""+t.options.baseClass].concat(t._getClasses(t.options.wrapperClass)),e.push(t.options.state?t.options.baseClass+"-on":t.options.baseClass+"-off"),null!=t.options.size&&e.push(t.options.baseClass+"-"+t.options.size),t.options.disabled&&e.push(t.options.baseClass+"-disabled"),t.options.readonly&&e.push(t.options.baseClass+"-readonly"),t.options.indeterminate&&e.push(t.options.baseClass+"-indeterminate"),t.options.inverse&&e.push(t.options.baseClass+"-inverse"),t.$element.attr("id")&&e.push(t.options.baseClass+"-id-"+t.$element.attr("id")),e.join(" ")}}(this)()}),this.$container=e("<div>",{"class":this.options.baseClass+"-container"}),this.$on=e("<span>",{html:this.options.onText,"class":this.options.baseClass+"-handle-on "+this.options.baseClass+"-"+this.options.onColor}),this.$off=e("<span>",{html:this.options.offText,"class":this.options.baseClass+"-handle-off "+this.options.baseClass+"-"+this.options.offColor}),this.$label=e("<span>",{html:this.options.labelText,"class":this.options.baseClass+"-label"}),this.$element.on("init.bootstrapSwitch",function(e){return function(){return e.options.onInit.apply(t,arguments)}}(this)),this.$element.on("switchChange.bootstrapSwitch",function(i){return function(n){return!1===i.options.onSwitchChange.apply(t,arguments)?i.$element.is(":radio")?e("[name='"+i.$element.attr("name")+"']").trigger("previousState.bootstrapSwitch",!0):i.$element.trigger("previousState.bootstrapSwitch",!0):void 0}}(this)),this.$container=this.$element.wrap(this.$container).parent(),this.$wrapper=this.$container.wrap(this.$wrapper).parent(),this.$element.before(this.options.inverse?this.$off:this.$on).before(this.$label).before(this.options.inverse?this.$on:this.$off),this.options.indeterminate&&this.$element.prop("indeterminate",!0),this._init(),this._elementHandlers(),this._handleHandlers(),this._labelHandlers(),this._formHandler(),this._externalLabelHandler(),this.$element.trigger("init.bootstrapSwitch",this.options.state)}return t.prototype._constructor=t,t.prototype.setPrevOptions=function(){return this.prevOptions=e.extend(!0,{},this.options)},t.prototype.state=function(t,i){return"undefined"==typeof t?this.options.state:this.options.disabled||this.options.readonly?this.$element:this.options.state&&!this.options.radioAllOff&&this.$element.is(":radio")?this.$element:(this.$element.is(":radio")?e("[name='"+this.$element.attr("name")+"']").trigger("setPreviousOptions.bootstrapSwitch"):this.$element.trigger("setPreviousOptions.bootstrapSwitch"),this.options.indeterminate&&this.indeterminate(!1),t=!!t,this.$element.prop("checked",t).trigger("change.bootstrapSwitch",i),this.$element)},t.prototype.toggleState=function(t){return this.options.disabled||this.options.readonly?this.$element:this.options.indeterminate?(this.indeterminate(!1),this.state(!0)):this.$element.prop("checked",!this.options.state).trigger("change.bootstrapSwitch",t)},t.prototype.size=function(t){return"undefined"==typeof t?this.options.size:(null!=this.options.size&&this.$wrapper.removeClass(this.options.baseClass+"-"+this.options.size),t&&this.$wrapper.addClass(this.options.baseClass+"-"+t),this._width(),this._containerPosition(),this.options.size=t,this.$element)},t.prototype.animate=function(t){return"undefined"==typeof t?this.options.animate:(t=!!t,t===this.options.animate?this.$element:this.toggleAnimate())},t.prototype.toggleAnimate=function(){return this.options.animate=!this.options.animate,this.$wrapper.toggleClass(this.options.baseClass+"-animate"),this.$element},t.prototype.disabled=function(t){return"undefined"==typeof t?this.options.disabled:(t=!!t,t===this.options.disabled?this.$element:this.toggleDisabled())},t.prototype.toggleDisabled=function(){return this.options.disabled=!this.options.disabled,this.$element.prop("disabled",this.options.disabled),this.$wrapper.toggleClass(this.options.baseClass+"-disabled"),this.$element},t.prototype.readonly=function(t){return"undefined"==typeof t?this.options.readonly:(t=!!t,t===this.options.readonly?this.$element:this.toggleReadonly())},t.prototype.toggleReadonly=function(){return this.options.readonly=!this.options.readonly,this.$element.prop("readonly",this.options.readonly),this.$wrapper.toggleClass(this.options.baseClass+"-readonly"),this.$element},t.prototype.indeterminate=function(t){return"undefined"==typeof t?this.options.indeterminate:(t=!!t,t===this.options.indeterminate?this.$element:this.toggleIndeterminate())},t.prototype.toggleIndeterminate=function(){return this.options.indeterminate=!this.options.indeterminate,this.$element.prop("indeterminate",this.options.indeterminate),this.$wrapper.toggleClass(this.options.baseClass+"-indeterminate"),this._containerPosition(),this.$element},t.prototype.inverse=function(t){return"undefined"==typeof t?this.options.inverse:(t=!!t,t===this.options.inverse?this.$element:this.toggleInverse())},t.prototype.toggleInverse=function(){var t,e;return this.$wrapper.toggleClass(this.options.baseClass+"-inverse"),e=this.$on.clone(!0),t=this.$off.clone(!0),this.$on.replaceWith(t),this.$off.replaceWith(e),this.$on=t,this.$off=e,this.options.inverse=!this.options.inverse,this.$element},t.prototype.onColor=function(t){var e;return e=this.options.onColor,"undefined"==typeof t?e:(null!=e&&this.$on.removeClass(this.options.baseClass+"-"+e),this.$on.addClass(this.options.baseClass+"-"+t),this.options.onColor=t,this.$element)},t.prototype.offColor=function(t){var e;return e=this.options.offColor,"undefined"==typeof t?e:(null!=e&&this.$off.removeClass(this.options.baseClass+"-"+e),this.$off.addClass(this.options.baseClass+"-"+t),this.options.offColor=t,this.$element)},t.prototype.onText=function(t){return"undefined"==typeof t?this.options.onText:(this.$on.html(t),this._width(),this._containerPosition(),this.options.onText=t,this.$element)},t.prototype.offText=function(t){return"undefined"==typeof t?this.options.offText:(this.$off.html(t),this._width(),this._containerPosition(),this.options.offText=t,this.$element)},t.prototype.labelText=function(t){return"undefined"==typeof t?this.options.labelText:(this.$label.html(t),this._width(),this.options.labelText=t,this.$element)},t.prototype.handleWidth=function(t){return"undefined"==typeof t?this.options.handleWidth:(this.options.handleWidth=t,this._width(),this._containerPosition(),this.$element)},t.prototype.labelWidth=function(t){return"undefined"==typeof t?this.options.labelWidth:(this.options.labelWidth=t,this._width(),this._containerPosition(),this.$element)},t.prototype.baseClass=function(t){return this.options.baseClass},t.prototype.wrapperClass=function(t){return"undefined"==typeof t?this.options.wrapperClass:(t||(t=e.fn.bootstrapSwitch.defaults.wrapperClass),this.$wrapper.removeClass(this._getClasses(this.options.wrapperClass).join(" ")),this.$wrapper.addClass(this._getClasses(t).join(" ")),this.options.wrapperClass=t,this.$element)},t.prototype.radioAllOff=function(t){return"undefined"==typeof t?this.options.radioAllOff:(t=!!t,t===this.options.radioAllOff?this.$element:(this.options.radioAllOff=t,this.$element))},t.prototype.onInit=function(t){return"undefined"==typeof t?this.options.onInit:(t||(t=e.fn.bootstrapSwitch.defaults.onInit),this.options.onInit=t,this.$element)},t.prototype.onSwitchChange=function(t){return"undefined"==typeof t?this.options.onSwitchChange:(t||(t=e.fn.bootstrapSwitch.defaults.onSwitchChange),this.options.onSwitchChange=t,this.$element)},t.prototype.destroy=function(){var t;return t=this.$element.closest("form"),t.length&&t.off("reset.bootstrapSwitch").removeData("bootstrap-switch"),this.$container.children().not(this.$element).remove(),this.$element.unwrap().unwrap().off(".bootstrapSwitch").removeData("bootstrap-switch"),this.$element},t.prototype._width=function(){var t,e;return t=this.$on.add(this.$off),t.add(this.$label).css("width",""),e="auto"===this.options.handleWidth?Math.max(this.$on.width(),this.$off.width()):this.options.handleWidth,t.width(e),this.$label.width(function(t){return function(i,n){return"auto"!==t.options.labelWidth?t.options.labelWidth:e>n?e:n}}(this)),this._handleWidth=this.$on.outerWidth(),this._labelWidth=this.$label.outerWidth(),this.$container.width(2*this._handleWidth+this._labelWidth),this.$wrapper.width(this._handleWidth+this._labelWidth)},t.prototype._containerPosition=function(t,e){return null==t&&(t=this.options.state),this.$container.css("margin-left",function(e){return function(){var i;return i=[0,"-"+e._handleWidth+"px"],e.options.indeterminate?"-"+e._handleWidth/2+"px":t?e.options.inverse?i[1]:i[0]:e.options.inverse?i[0]:i[1]}}(this)),e?setTimeout(function(){return e()},50):void 0},t.prototype._init=function(){var t,e;return t=function(t){return function(){return t.setPrevOptions(),t._width(),t._containerPosition(null,function(){return t.options.animate?t.$wrapper.addClass(t.options.baseClass+"-animate"):void 0})}}(this),this.$wrapper.is(":visible")?t():e=i.setInterval(function(n){return function(){return n.$wrapper.is(":visible")?(t(),i.clearInterval(e)):void 0}}(this),50)},t.prototype._elementHandlers=function(){return this.$element.on({"setPreviousOptions.bootstrapSwitch":function(t){return function(e){return t.setPrevOptions()}}(this),"previousState.bootstrapSwitch":function(t){return function(e){return t.options=t.prevOptions,t.options.indeterminate&&t.$wrapper.addClass(t.options.baseClass+"-indeterminate"),t.$element.prop("checked",t.options.state).trigger("change.bootstrapSwitch",!0)}}(this),"change.bootstrapSwitch":function(t){return function(i,n){var o;return i.preventDefault(),i.stopImmediatePropagation(),o=t.$element.is(":checked"),t._containerPosition(o),o!==t.options.state?(t.options.state=o,t.$wrapper.toggleClass(t.options.baseClass+"-off").toggleClass(t.options.baseClass+"-on"),n?void 0:(t.$element.is(":radio")&&e("[name='"+t.$element.attr("name")+"']").not(t.$element).prop("checked",!1).trigger("change.bootstrapSwitch",!0),t.$element.trigger("switchChange.bootstrapSwitch",[o]))):void 0}}(this),"focus.bootstrapSwitch":function(t){return function(e){return e.preventDefault(),t.$wrapper.addClass(t.options.baseClass+"-focused")}}(this),"blur.bootstrapSwitch":function(t){return function(e){return e.preventDefault(),t.$wrapper.removeClass(t.options.baseClass+"-focused")}}(this),"keydown.bootstrapSwitch":function(t){return function(e){if(e.which&&!t.options.disabled&&!t.options.readonly)switch(e.which){case 37:return e.preventDefault(),e.stopImmediatePropagation(),t.state(!1);case 39:return e.preventDefault(),e.stopImmediatePropagation(),t.state(!0)}}}(this)})},t.prototype._handleHandlers=function(){return this.$on.on("click.bootstrapSwitch",function(t){return function(e){return e.preventDefault(),e.stopPropagation(),t.state(!1),t.$element.trigger("focus.bootstrapSwitch")}}(this)),this.$off.on("click.bootstrapSwitch",function(t){return function(e){return e.preventDefault(),e.stopPropagation(),t.state(!0),t.$element.trigger("focus.bootstrapSwitch")}}(this))},t.prototype._labelHandlers=function(){return this.$label.on({click:function(t){return t.stopPropagation()},"mousedown.bootstrapSwitch touchstart.bootstrapSwitch":function(t){return function(e){return t._dragStart||t.options.disabled||t.options.readonly?void 0:(e.preventDefault(),e.stopPropagation(),t._dragStart=(e.pageX||e.originalEvent.touches[0].pageX)-parseInt(t.$container.css("margin-left"),10),t.options.animate&&t.$wrapper.removeClass(t.options.baseClass+"-animate"),t.$element.trigger("focus.bootstrapSwitch"))}}(this),"mousemove.bootstrapSwitch touchmove.bootstrapSwitch":function(t){return function(e){var i;if(null!=t._dragStart&&(e.preventDefault(),i=(e.pageX||e.originalEvent.touches[0].pageX)-t._dragStart,!(i<-t._handleWidth||i>0)))return t._dragEnd=i,t.$container.css("margin-left",t._dragEnd+"px")}}(this),"mouseup.bootstrapSwitch touchend.bootstrapSwitch":function(t){return function(e){var i;if(t._dragStart)return e.preventDefault(),t.options.animate&&t.$wrapper.addClass(t.options.baseClass+"-animate"),t._dragEnd?(i=t._dragEnd>-(t._handleWidth/2),t._dragEnd=!1,t.state(t.options.inverse?!i:i)):t.state(!t.options.state),t._dragStart=!1}}(this),"mouseleave.bootstrapSwitch":function(t){return function(e){return t.$label.trigger("mouseup.bootstrapSwitch")}}(this)})},t.prototype._externalLabelHandler=function(){var t;return t=this.$element.closest("label"),t.on("click",function(e){return function(i){return i.preventDefault(),i.stopImmediatePropagation(),i.target===t[0]?e.toggleState():void 0}}(this))},t.prototype._formHandler=function(){var t;return t=this.$element.closest("form"),t.data("bootstrap-switch")?void 0:t.on("reset.bootstrapSwitch",function(){return i.setTimeout(function(){return t.find("input").filter(function(){return e(this).data("bootstrap-switch")}).each(function(){return e(this).bootstrapSwitch("state",this.checked)})},1)}).data("bootstrap-switch",!0)},t.prototype._getClasses=function(t){var i,n,o,s;if(!e.isArray(t))return[this.options.baseClass+"-"+t];for(n=[],o=0,s=t.length;s>o;o++)i=t[o],n.push(this.options.baseClass+"-"+i);return n},t}(),e.fn.bootstrapSwitch=function(){var i,o,s;return o=arguments[0],i=2<=arguments.length?t.call(arguments,1):[],s=this,this.each(function(){var t,a;return t=e(this),a=t.data("bootstrap-switch"),a||t.data("bootstrap-switch",a=new n(this,o)),"string"==typeof o?s=a[o].apply(a,i):void 0}),s},e.fn.bootstrapSwitch.Constructor=n,e.fn.bootstrapSwitch.defaults={state:!0,size:null,animate:!0,disabled:!1,readonly:!1,indeterminate:!1,inverse:!1,radioAllOff:!1,onColor:"primary",offColor:"default",onText:"ON",offText:"OFF",labelText:" ",handleWidth:"auto",labelWidth:"auto",baseClass:"bootstrap-switch",wrapperClass:"wrapper",onInit:function(){},onSwitchChange:function(){}}}(window.jQuery,window)}).call(this); | |
0 | 23 | \ No newline at end of file | ... | ... |