Skip to content

Commit b119f18

Browse files
committed
Controlgroup: Add extension points for special options and refresh
Methods of new widgets added via the items option.
1 parent 066e37c commit b119f18

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

ui/controlgroup.js

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,52 @@ $.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
});
9377
},
9478

79+
_button_options: function() {
80+
return {
81+
classes: {
82+
"ui-button": ""
83+
}
84+
};
85+
},
86+
87+
_checkboxradio_options: function() {
88+
return {
89+
classes: {
90+
"ui-checkbox-label": "",
91+
"ui-radio-label": ""
92+
}
93+
};
94+
},
95+
96+
_selectmenu_options: function() {
97+
return {
98+
classes: {
99+
"ui-selectmenu-button-open": "",
100+
"ui-selectmenu-button-closed": ""
101+
}
102+
};
103+
},
104+
95105
_setOption: function( key, value ) {
96106
var original = this.options[ key ];
97107

98108
this._super( key, value );
99109
if ( key === "direction" ) {
100-
this.element.removeClass( "ui-controlgroup-" + original )
101-
.addClass( "ui-controlgroup-" + value );
110+
this.element.removeClass( "ui-controlgroup-" + original );
102111
}
103112
if ( key === "disabled" ) {
104113
this._callChildMethod( value ? "disable" : "enable" );
@@ -108,21 +117,11 @@ $.widget( "ui.controlgroup", {
108117

109118
},
110119

111-
refresh: function() {
120+
_refresh_selectmenu: function() {
112121
var firstClasses = {},
113122
lastClasses = {},
114123
vertical = ( this.options.direction === "vertical" );
115-
this.element.addClass( this._classes( "ui-controlgroup ui-controlgroup-" +
116-
this.options.direction ) );
117-
this._callChildMethod( undefined );
118-
this.visible = this.element.children( ".ui-button" ).removeClass( function(index, css) {
119-
return ( css.match( /ui-corner-[a-z]*/g ) || [] ).join( " " );
120-
}).filter( this.options.excludeInvisible ? ":visible" : "*" );
121124

122-
this.first = this.visible.filter( ":first" )
123-
.addClass( "ui-corner-" + ( vertical ? "top" : "left" ) );
124-
this.last = this.visible.filter( ":last" )
125-
.addClass( "ui-corner-" + ( vertical ? "bottom" : "right" ) );
126125
if ( $.ui.selectmenu ) {
127126
if ( this.first.is( ".ui-selectmenu-button" ) && !vertical ) {
128127
firstClasses[ "ui-selectmenu-button-open" ] = "ui-corner-tl";
@@ -143,6 +142,28 @@ $.widget( "ui.controlgroup", {
143142
}
144143
this.element.find( this.options.items.selectmenu ).selectmenu( "refresh" );
145144
}
145+
},
146+
147+
refresh: function() {
148+
var that = this,
149+
vertical = ( this.options.direction === "vertical" );
150+
this.element.addClass( this._classes( "ui-controlgroup ui-controlgroup-" +
151+
this.options.direction ) );
152+
this._callChildMethod( undefined );
153+
this.visible = this.element.children( ".ui-button" ).removeClass( function(index, css) {
154+
return ( css.match( /ui-corner-[a-z]*/g ) || [] ).join( " " );
155+
}).filter( this.options.excludeInvisible ? ":visible" : "*" );
156+
157+
this.first = this.visible.eq( 0 )
158+
.addClass( "ui-corner-" + ( vertical ? "top" : "left" ) );
159+
this.last = this.visible.last()
160+
.addClass( "ui-corner-" + ( vertical ? "bottom" : "right" ) );
161+
162+
$.each( this.options.items, function( widget ) {
163+
if ( that[ "_refresh_" + widget ] ) {
164+
that[ "_refresh_" + widget ]();
165+
}
166+
});
146167
this._callChildMethod( "refresh" );
147168

148169
}

0 commit comments

Comments
 (0)