@@ -68,7 +68,11 @@ return $.widget( "ui.selectmenu", {
68
68
69
69
_drawButton : function ( ) {
70
70
var that = this ,
71
- tabindex = this . element . attr ( "tabindex" ) ;
71
+ tabindex = this . element . attr ( "tabindex" ) ,
72
+ item = this . _parseOption (
73
+ this . element . find ( "option:selected" ) ,
74
+ this . element [ 0 ] . selectedIndex
75
+ ) ;
72
76
73
77
// Associate existing label with the new button
74
78
this . label = $ ( "label[for='" + this . ids . element + "']" ) . attr ( "for" , this . ids . button ) ;
@@ -100,12 +104,12 @@ return $.widget( "ui.selectmenu", {
100
104
} )
101
105
. prependTo ( this . button ) ;
102
106
103
- this . buttonText = $ ( "<span>" , {
107
+ this . buttonItem = $ ( "<span>" , {
104
108
"class" : "ui-selectmenu-text"
105
109
} )
106
110
. appendTo ( this . button ) ;
107
111
108
- this . _setText ( this . buttonText , this . element . find ( "option:selected" ) . text ( ) ) ;
112
+ this . _renderButtonItem ( this . buttonItem , item ) ;
109
113
this . _resizeButton ( ) ;
110
114
111
115
this . _on ( this . button , this . _buttonEvents ) ;
@@ -185,7 +189,7 @@ return $.widget( "ui.selectmenu", {
185
189
186
190
refresh : function ( ) {
187
191
this . _refreshMenu ( ) ;
188
- this . _setText ( this . buttonText , this . _getSelectedItem ( ) . text ( ) ) ;
192
+ this . _renderButtonItem ( this . buttonItem , this . _getSelectedItem ( ) . data ( "ui-selectmenu-item" ) ) ;
189
193
if ( ! this . options . width ) {
190
194
this . _resizeButton ( ) ;
191
195
}
@@ -267,6 +271,10 @@ return $.widget( "ui.selectmenu", {
267
271
return this . menu ;
268
272
} ,
269
273
274
+ _renderButtonItem : function ( buttonItem , item ) {
275
+ this . _setText ( buttonItem , item . label ) ;
276
+ } ,
277
+
270
278
_renderMenu : function ( ul , items ) {
271
279
var that = this ,
272
280
currentOptgroup = "" ;
@@ -434,7 +442,7 @@ return $.widget( "ui.selectmenu", {
434
442
435
443
// Change native select element
436
444
this . element [ 0 ] . selectedIndex = item . index ;
437
- this . _setText ( this . buttonText , item . label ) ;
445
+ this . _renderButtonItem ( this . buttonItem , item ) ;
438
446
this . _setAria ( item ) ;
439
447
this . _trigger ( "select" , event , { item : item } ) ;
440
448
@@ -544,22 +552,27 @@ return $.widget( "ui.selectmenu", {
544
552
} ,
545
553
546
554
_parseOptions : function ( options ) {
547
- var data = [ ] ;
555
+ var that = this ,
556
+ data = [ ] ;
548
557
options . each ( function ( index , item ) {
549
- var option = $ ( item ) ,
550
- optgroup = option . parent ( "optgroup" ) ;
551
- data . push ( {
552
- element : option ,
553
- index : index ,
554
- value : option . attr ( "value" ) ,
555
- label : option . text ( ) ,
556
- optgroup : optgroup . attr ( "label" ) || "" ,
557
- disabled : optgroup . prop ( "disabled" ) || option . prop ( "disabled" )
558
- } ) ;
558
+ data . push ( that . _parseOption ( $ ( item ) , index ) ) ;
559
559
} ) ;
560
560
this . items = data ;
561
561
} ,
562
562
563
+ _parseOption : function ( option , index ) {
564
+ var optgroup = option . parent ( "optgroup" ) ;
565
+
566
+ return {
567
+ element : option ,
568
+ index : index ,
569
+ value : option . attr ( "value" ) ,
570
+ label : option . text ( ) ,
571
+ optgroup : optgroup . attr ( "label" ) || "" ,
572
+ disabled : optgroup . prop ( "disabled" ) || option . prop ( "disabled" )
573
+ } ;
574
+ } ,
575
+
563
576
_destroy : function ( ) {
564
577
this . menuWrap . remove ( ) ;
565
578
this . button . remove ( ) ;
0 commit comments