mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Selectmenu: introduce _setText helper function to improve handling of empty strings
This commit is contained in:
parent
21e46b8bc6
commit
e2b5123f37
29
ui/jquery.ui.selectmenu.js
vendored
29
ui/jquery.ui.selectmenu.js
vendored
@ -84,10 +84,10 @@ $.widget( "ui.selectmenu", {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this.buttonText = $( "<span>", {
|
this.buttonText = $( "<span>", {
|
||||||
"class": "ui-selectmenu-text" ,
|
"class": "ui-selectmenu-text"
|
||||||
html: this.element.find( "option:selected" ).text() || " "
|
|
||||||
})
|
})
|
||||||
.appendTo( this.button );
|
.appendTo( this.button );
|
||||||
|
this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
|
||||||
|
|
||||||
// wrap and insert new button
|
// wrap and insert new button
|
||||||
this.buttonWrap = $( "<span>", {
|
this.buttonWrap = $( "<span>", {
|
||||||
@ -260,17 +260,23 @@ $.widget( "ui.selectmenu", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_renderItem: function( ul, item ) {
|
_renderItem: function( ul, item ) {
|
||||||
var li = $( "<li />" ).data( "ui-selectmenu-item", item );
|
var li = $( "<li />" ).data( "ui-selectmenu-item", item ),
|
||||||
|
a = $( "<a />", { href: "#" });
|
||||||
|
|
||||||
if ( item.disabled ) {
|
if ( item.disabled ) {
|
||||||
li.addClass( "ui-state-disabled" );
|
li.addClass( "ui-state-disabled" );
|
||||||
}
|
}
|
||||||
li.append( $( "<a />", {
|
this._setText( a, item.label );
|
||||||
html: item.label,
|
|
||||||
href: "#"
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return li.appendTo( ul );
|
return li.append( a ).appendTo( ul );
|
||||||
|
},
|
||||||
|
|
||||||
|
_setText: function( element, value ) {
|
||||||
|
if ( value ) {
|
||||||
|
element.text( value );
|
||||||
|
} else {
|
||||||
|
element.html( " " );
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_move: function( direction, event ) {
|
_move: function( direction, event ) {
|
||||||
@ -388,8 +394,7 @@ $.widget( "ui.selectmenu", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_setSelected: function( item ) {
|
_setSelected: function( item ) {
|
||||||
// update button text
|
this._setText( this.buttonText, item.label );
|
||||||
this.buttonText.html( item.label );
|
|
||||||
// change ARIA attr
|
// change ARIA attr
|
||||||
this.menuItems.find( "a" ).attr( "aria-selected", false );
|
this.menuItems.find( "a" ).attr( "aria-selected", false );
|
||||||
this.menuItems.eq( item.index ).find( "a" ).attr( "aria-selected", true );
|
this.menuItems.eq( item.index ).find( "a" ).attr( "aria-selected", true );
|
||||||
@ -437,7 +442,7 @@ $.widget( "ui.selectmenu", {
|
|||||||
element: option,
|
element: option,
|
||||||
index: index,
|
index: index,
|
||||||
value: option.attr( "value" ),
|
value: option.attr( "value" ),
|
||||||
label: option.text() || " ",
|
label: option.text(),
|
||||||
optgroup: optgroup.attr( "label" ) || "",
|
optgroup: optgroup.attr( "label" ) || "",
|
||||||
disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
|
disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user