Skip to content

Commit 3e1478a

Browse files
committed
Controlgroup: Add extension points for special options and refresh
Methods of new widgets added via the items option.
1 parent 35697d4 commit 3e1478a

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

ui/controlgroup.js

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,15 @@ $.widget( "ui.controlgroup", {
6262
" ui-corner-bottom ui-corner-left ui-corner-tl ui-corner-tr" );
6363
},
6464

65-
_callChildMethod: function( method, filter ) {
65+
_callChildMethod: function( method ) {
6666
var that = this;
6767
$.each( this.options.items, function( widget, selector ) {
6868
var options = {};
69-
switch ( widget ) {
70-
case "button":
71-
options.classes = {
72-
"ui-button": null
73-
};
74-
break;
75-
case "checkboxradio":
76-
options.classes = {
77-
"ui-checkbox-label": null,
78-
"ui-radio-label": null
79-
};
80-
break;
81-
case "selectmenu":
82-
options.classes = {
83-
"ui-selectmenu-button-open": null,
84-
"ui-selectmenu-button-closed": null
85-
};
86-
break;
69+
if ( that[ "_" + widget + "_options" ] ) {
70+
options = that[ "_" + widget + "_options" ]();
8771
}
8872
if ( $.fn[ widget ] && selector ) {
89-
that.element.children( selector ).not( filter )[ widget ]( method ?
73+
that.element.children( selector )[ widget ]( method ?
9074
method : options );
9175
}
9276
});
@@ -130,8 +114,7 @@ $.widget( "ui.controlgroup", {
130114

131115
this._super( key, value );
132116
if ( key === "direction" ) {
133-
this.element.removeClass( "ui-controlgroup-" + original )
134-
.addClass( "ui-controlgroup-" + value );
117+
this.element.removeClass( "ui-controlgroup-" + original );
135118
}
136119
if ( key === "disabled" ) {
137120
this._callChildMethod( value ? "disable" : "enable" );
@@ -141,21 +124,11 @@ $.widget( "ui.controlgroup", {
141124

142125
},
143126

144-
refresh: function() {
127+
_refresh_selectmenu: function() {
145128
var firstClasses = {},
146129
lastClasses = {},
147130
vertical = ( this.options.direction === "vertical" );
148-
this.element.addClass( this._classes( "ui-controlgroup ui-controlgroup-" +
149-
this.options.direction ) );
150-
this._callChildMethod( undefined );
151-
this.visible = this.element.children( ".ui-button" ).removeClass( function(index, css) {
152-
return ( css.match( /ui-corner-[a-z]*/g ) || [] ).join( " " );
153-
}).filter( this.options.excludeInvisible ? ":visible" : "*" );
154131

155-
this.first = this.visible.filter( ":first" )
156-
.addClass( "ui-corner-" + ( vertical ? "top" : "left" ) );
157-
this.last = this.visible.filter( ":last" )
158-
.addClass( "ui-corner-" + ( vertical ? "bottom" : "right" ) );
159132
if ( $.ui.selectmenu ) {
160133
if ( this.first.is( ".ui-selectmenu-button" ) && !vertical ) {
161134
firstClasses[ "ui-selectmenu-button-open" ] = "ui-corner-tl";
@@ -176,6 +149,28 @@ $.widget( "ui.controlgroup", {
176149
}
177150
this.element.find( this.options.items.selectmenu ).selectmenu( "refresh" );
178151
}
152+
},
153+
154+
refresh: function() {
155+
var that = this,
156+
vertical = ( this.options.direction === "vertical" );
157+
this.element.addClass( this._classes( "ui-controlgroup ui-controlgroup-" +
158+
this.options.direction ) );
159+
this._callChildMethod( undefined );
160+
this.visible = this.element.children( ".ui-button" ).removeClass( function(index, css) {
161+
return ( css.match( /ui-corner-[a-z]*/g ) || [] ).join( " " );
162+
}).filter( this.options.excludeInvisible ? ":visible" : "*" );
163+
164+
this.first = this.visible.eq( 0 )
165+
.addClass( "ui-corner-" + ( vertical ? "top" : "left" ) );
166+
this.last = this.visible.last()
167+
.addClass( "ui-corner-" + ( vertical ? "bottom" : "right" ) );
168+
169+
$.each( this.options.items, function( widget ) {
170+
if ( that[ "_refresh_" + widget ] ) {
171+
that[ "_refresh_" + widget ]();
172+
}
173+
});
179174
this._callChildMethod( "refresh" );
180175

181176
}

0 commit comments

Comments
 (0)