Skip to content

Commit 014960c

Browse files
committed
Checkboxradio: move inital dom manipulation into its own method
Allows easy extension for mobiles enhanced option
1 parent 8378921 commit 014960c

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

ui/jquery.ui.checkboxradio.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ var baseClasses = "ui-button ui-widget ui-corner-all",
2222
}, 1 );
2323
},
2424
radioGroup = function( radio ) {
25-
var name = radio.name,
26-
form = radio.form,
27-
radios = $( [] );
28-
if ( name ) {
29-
name = name.replace( /'/g, "\\'" );
30-
if ( form ) {
31-
radios = $( form ).find( "[name='" + name + "']" );
32-
} else {
33-
radios = $( "[name='" + name + "']", radio.ownerDocument )
34-
.filter(function() {
35-
return !this.form;
36-
});
37-
}
38-
}
39-
return radios;
40-
};
25+
var name = radio.name,
26+
form = radio.form,
27+
radios = $( [] );
28+
if ( name ) {
29+
name = name.replace( /'/g, "\\'" );
30+
if ( form ) {
31+
radios = $( form ).find( "[name='" + name + "']" );
32+
} else {
33+
radios = $( "[name='" + name + "']", radio.ownerDocument )
34+
.filter(function() {
35+
return !this.form;
36+
});
37+
}
38+
}
39+
return radios;
40+
};
4141

4242
$.widget( "ui.checkboxradio", {
4343
version: "@VERSION",
@@ -78,6 +78,16 @@ $.widget( "ui.checkboxradio", {
7878

7979
this._getLabel();
8080

81+
this._enhance();
82+
83+
this._on({
84+
"change" : "_toggleClasses",
85+
"focus": "_handleFocus",
86+
"blur": "_handleBlur"
87+
});
88+
},
89+
90+
enhance: function() {
8191
this.element.addClass( "ui-helper-hidden-accessible ui-checkboxradio" );
8292

8393
this.label.addClass( baseClasses + " ui-" + this.type + "-label" );
@@ -98,12 +108,6 @@ $.widget( "ui.checkboxradio", {
98108
if ( this.options.label ){
99109
this.label.html( this.options.label );
100110
}
101-
102-
this._on({
103-
"change" : "_toggleClasses",
104-
"focus": "_handleFocus",
105-
"blur": "_handleBlur"
106-
});
107111
},
108112

109113
widget: function() {
@@ -124,7 +128,6 @@ $.widget( "ui.checkboxradio", {
124128
// Check control.labels first
125129
if ( this.element[ 0 ].labels !== undefined ){
126130
this.label = $( this.element[ 0 ].labels );
127-
console.log( this.element[ 0 ].labels );
128131
} else {
129132

130133
// we don't search against the document in case the element
@@ -154,7 +157,7 @@ $.widget( "ui.checkboxradio", {
154157
radioGroup( this.element[0] )
155158
.not( this.element )
156159
.map(function() {
157-
return $( this ).checkboxradio( "widget" )[ 0 ];
160+
return $( this ).checkboxradio( "widget" )[ 0 ];
158161
})
159162
.removeClass( "ui-state-active ui-radio-checked" );
160163
}

0 commit comments

Comments
 (0)