corrade-http-templates – Blame information for rev 57

Subversion Repositories:
Rev:
Rev Author Line No. Line
57 office 1 /*!
2 * jQuery UI Checkboxradio 1.12.1
3 * http://jqueryui.com
4 *
5 * Copyright jQuery Foundation and other contributors
6 * Released under the MIT license.
7 * http://jquery.org/license
8 */
9  
10 //>>label: Checkboxradio
11 //>>group: Widgets
12 //>>description: Enhances a form with multiple themeable checkboxes or radio buttons.
13 //>>docs: http://api.jqueryui.com/checkboxradio/
14 //>>demos: http://jqueryui.com/checkboxradio/
15 //>>css.structure: ../../themes/base/core.css
16 //>>css.structure: ../../themes/base/button.css
17 //>>css.structure: ../../themes/base/checkboxradio.css
18 //>>css.theme: ../../themes/base/theme.css
19  
20 ( function( factory ) {
21 if ( typeof define === "function" && define.amd ) {
22  
23 // AMD. Register as an anonymous module.
24 define( [
25 "jquery",
26 "../escape-selector",
27 "../form-reset-mixin",
28 "../labels",
29 "../widget"
30 ], factory );
31 } else {
32  
33 // Browser globals
34 factory( jQuery );
35 }
36 }( function( $ ) {
37  
38 $.widget( "ui.checkboxradio", [ $.ui.formResetMixin, {
39 version: "1.12.1",
40 options: {
41 disabled: null,
42 label: null,
43 icon: true,
44 classes: {
45 "ui-checkboxradio-label": "ui-corner-all",
46 "ui-checkboxradio-icon": "ui-corner-all"
47 }
48 },
49  
50 _getCreateOptions: function() {
51 var disabled, labels;
52 var that = this;
53 var options = this._super() || {};
54  
55 // We read the type here, because it makes more sense to throw a element type error first,
56 // rather then the error for lack of a label. Often if its the wrong type, it
57 // won't have a label (e.g. calling on a div, btn, etc)
58 this._readType();
59  
60 labels = this.element.labels();
61  
62 // If there are multiple labels, use the last one
63 this.label = $( labels[ labels.length - 1 ] );
64 if ( !this.label.length ) {
65 $.error( "No label found for checkboxradio widget" );
66 }
67  
68 this.originalLabel = "";
69  
70 // We need to get the label text but this may also need to make sure it does not contain the
71 // input itself.
72 this.label.contents().not( this.element[ 0 ] ).each( function() {
73  
74 // The label contents could be text, html, or a mix. We concat each element to get a
75 // string representation of the label, without the input as part of it.
76 that.originalLabel += this.nodeType === 3 ? $( this ).text() : this.outerHTML;
77 } );
78  
79 // Set the label option if we found label text
80 if ( this.originalLabel ) {
81 options.label = this.originalLabel;
82 }
83  
84 disabled = this.element[ 0 ].disabled;
85 if ( disabled != null ) {
86 options.disabled = disabled;
87 }
88 return options;
89 },
90  
91 _create: function() {
92 var checked = this.element[ 0 ].checked;
93  
94 this._bindFormResetHandler();
95  
96 if ( this.options.disabled == null ) {
97 this.options.disabled = this.element[ 0 ].disabled;
98 }
99  
100 this._setOption( "disabled", this.options.disabled );
101 this._addClass( "ui-checkboxradio", "ui-helper-hidden-accessible" );
102 this._addClass( this.label, "ui-checkboxradio-label", "ui-button ui-widget" );
103  
104 if ( this.type === "radio" ) {
105 this._addClass( this.label, "ui-checkboxradio-radio-label" );
106 }
107  
108 if ( this.options.label && this.options.label !== this.originalLabel ) {
109 this._updateLabel();
110 } else if ( this.originalLabel ) {
111 this.options.label = this.originalLabel;
112 }
113  
114 this._enhance();
115  
116 if ( checked ) {
117 this._addClass( this.label, "ui-checkboxradio-checked", "ui-state-active" );
118 if ( this.icon ) {
119 this._addClass( this.icon, null, "ui-state-hover" );
120 }
121 }
122  
123 this._on( {
124 change: "_toggleClasses",
125 focus: function() {
126 this._addClass( this.label, null, "ui-state-focus ui-visual-focus" );
127 },
128 blur: function() {
129 this._removeClass( this.label, null, "ui-state-focus ui-visual-focus" );
130 }
131 } );
132 },
133  
134 _readType: function() {
135 var nodeName = this.element[ 0 ].nodeName.toLowerCase();
136 this.type = this.element[ 0 ].type;
137 if ( nodeName !== "input" || !/radio|checkbox/.test( this.type ) ) {
138 $.error( "Can't create checkboxradio on element.nodeName=" + nodeName +
139 " and element.type=" + this.type );
140 }
141 },
142  
143 // Support jQuery Mobile enhanced option
144 _enhance: function() {
145 this._updateIcon( this.element[ 0 ].checked );
146 },
147  
148 widget: function() {
149 return this.label;
150 },
151  
152 _getRadioGroup: function() {
153 var group;
154 var name = this.element[ 0 ].name;
155 var nameSelector = "input[name='" + $.ui.escapeSelector( name ) + "']";
156  
157 if ( !name ) {
158 return $( [] );
159 }
160  
161 if ( this.form.length ) {
162 group = $( this.form[ 0 ].elements ).filter( nameSelector );
163 } else {
164  
165 // Not inside a form, check all inputs that also are not inside a form
166 group = $( nameSelector ).filter( function() {
167 return $( this ).form().length === 0;
168 } );
169 }
170  
171 return group.not( this.element );
172 },
173  
174 _toggleClasses: function() {
175 var checked = this.element[ 0 ].checked;
176 this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
177  
178 if ( this.options.icon && this.type === "checkbox" ) {
179 this._toggleClass( this.icon, null, "ui-icon-check ui-state-checked", checked )
180 ._toggleClass( this.icon, null, "ui-icon-blank", !checked );
181 }
182  
183 if ( this.type === "radio" ) {
184 this._getRadioGroup()
185 .each( function() {
186 var instance = $( this ).checkboxradio( "instance" );
187  
188 if ( instance ) {
189 instance._removeClass( instance.label,
190 "ui-checkboxradio-checked", "ui-state-active" );
191 }
192 } );
193 }
194 },
195  
196 _destroy: function() {
197 this._unbindFormResetHandler();
198  
199 if ( this.icon ) {
200 this.icon.remove();
201 this.iconSpace.remove();
202 }
203 },
204  
205 _setOption: function( key, value ) {
206  
207 // We don't allow the value to be set to nothing
208 if ( key === "label" && !value ) {
209 return;
210 }
211  
212 this._super( key, value );
213  
214 if ( key === "disabled" ) {
215 this._toggleClass( this.label, null, "ui-state-disabled", value );
216 this.element[ 0 ].disabled = value;
217  
218 // Don't refresh when setting disabled
219 return;
220 }
221 this.refresh();
222 },
223  
224 _updateIcon: function( checked ) {
225 var toAdd = "ui-icon ui-icon-background ";
226  
227 if ( this.options.icon ) {
228 if ( !this.icon ) {
229 this.icon = $( "<span>" );
230 this.iconSpace = $( "<span> </span>" );
231 this._addClass( this.iconSpace, "ui-checkboxradio-icon-space" );
232 }
233  
234 if ( this.type === "checkbox" ) {
235 toAdd += checked ? "ui-icon-check ui-state-checked" : "ui-icon-blank";
236 this._removeClass( this.icon, null, checked ? "ui-icon-blank" : "ui-icon-check" );
237 } else {
238 toAdd += "ui-icon-blank";
239 }
240 this._addClass( this.icon, "ui-checkboxradio-icon", toAdd );
241 if ( !checked ) {
242 this._removeClass( this.icon, null, "ui-icon-check ui-state-checked" );
243 }
244 this.icon.prependTo( this.label ).after( this.iconSpace );
245 } else if ( this.icon !== undefined ) {
246 this.icon.remove();
247 this.iconSpace.remove();
248 delete this.icon;
249 }
250 },
251  
252 _updateLabel: function() {
253  
254 // Remove the contents of the label ( minus the icon, icon space, and input )
255 var contents = this.label.contents().not( this.element[ 0 ] );
256 if ( this.icon ) {
257 contents = contents.not( this.icon[ 0 ] );
258 }
259 if ( this.iconSpace ) {
260 contents = contents.not( this.iconSpace[ 0 ] );
261 }
262 contents.remove();
263  
264 this.label.append( this.options.label );
265 },
266  
267 refresh: function() {
268 var checked = this.element[ 0 ].checked,
269 isDisabled = this.element[ 0 ].disabled;
270  
271 this._updateIcon( checked );
272 this._toggleClass( this.label, "ui-checkboxradio-checked", "ui-state-active", checked );
273 if ( this.options.label !== null ) {
274 this._updateLabel();
275 }
276  
277 if ( isDisabled !== this.options.disabled ) {
278 this._setOptions( { "disabled": isDisabled } );
279 }
280 }
281  
282 } ] );
283  
284 return $.ui.checkboxradio;
285  
286 } ) );