aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.selectmenu.js
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2012-12-14 18:03:49 +0100
committerFelix Nagel <info@felixnagel.com>2012-12-14 18:04:51 +0100
commite2b5123f37449bacb01e564bfc17897f07537ffa (patch)
treea52aeac14b484a5bb72e15cfc16a60db4f59cf54 /ui/jquery.ui.selectmenu.js
parent21e46b8bc6cf09cb22ac041074275507539d9d80 (diff)
downloadjquery-ui-e2b5123f37449bacb01e564bfc17897f07537ffa.tar.gz
jquery-ui-e2b5123f37449bacb01e564bfc17897f07537ffa.zip
Selectmenu: introduce _setText helper function to improve handling of empty strings
Diffstat (limited to 'ui/jquery.ui.selectmenu.js')
-rw-r--r--ui/jquery.ui.selectmenu.js29
1 files changed, 17 insertions, 12 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js
index 2e21391bd..6427b6080 100644
--- a/ui/jquery.ui.selectmenu.js
+++ b/ui/jquery.ui.selectmenu.js
@@ -84,10 +84,10 @@ $.widget( "ui.selectmenu", {
}));
this.buttonText = $( "<span>", {
- "class": "ui-selectmenu-text" ,
- html: this.element.find( "option:selected" ).text() || "&#160;"
+ "class": "ui-selectmenu-text"
})
.appendTo( this.button );
+ this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
// wrap and insert new button
this.buttonWrap = $( "<span>", {
@@ -260,17 +260,23 @@ $.widget( "ui.selectmenu", {
},
_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 ) {
li.addClass( "ui-state-disabled" );
}
- li.append( $( "<a />", {
- html: item.label,
- href: "#"
- })
- );
+ this._setText( a, item.label );
+
+ return li.append( a ).appendTo( ul );
+ },
- return li.appendTo( ul );
+ _setText: function( element, value ) {
+ if ( value ) {
+ element.text( value );
+ } else {
+ element.html( "&#160;" );
+ }
},
_move: function( direction, event ) {
@@ -388,8 +394,7 @@ $.widget( "ui.selectmenu", {
},
_setSelected: function( item ) {
- // update button text
- this.buttonText.html( item.label );
+ this._setText( this.buttonText, item.label );
// change ARIA attr
this.menuItems.find( "a" ).attr( "aria-selected", false );
this.menuItems.eq( item.index ).find( "a" ).attr( "aria-selected", true );
@@ -437,7 +442,7 @@ $.widget( "ui.selectmenu", {
element: option,
index: index,
value: option.attr( "value" ),
- label: option.text() || "&#160;",
+ label: option.text(),
optgroup: optgroup.attr( "label" ) || "",
disabled: optgroup.attr( "disabled" ) || option.attr( "disabled" )
});