@@ -67,7 +67,11 @@ return $.widget( "ui.selectmenu", {
67
67
} ,
68
68
69
69
_drawButton : function ( ) {
70
- var that = this ;
70
+ var that = this ,
71
+ item = this . _parseOption (
72
+ this . element . find ( "option:selected" ) ,
73
+ this . element [ 0 ] . selectedIndex
74
+ ) ;
71
75
72
76
// Associate existing label with the new button
73
77
this . label = $ ( "label[for='" + this . ids . element + "']" ) . attr ( "for" , this . ids . button ) ;
@@ -99,12 +103,12 @@ return $.widget( "ui.selectmenu", {
99
103
} )
100
104
. prependTo ( this . button ) ;
101
105
102
- this . buttonText = $ ( "<span>" , {
106
+ this . buttonItem = $ ( "<span>" , {
103
107
"class" : "ui-selectmenu-text"
104
108
} )
105
109
. appendTo ( this . button ) ;
106
110
107
- this . _setText ( this . buttonText , this . element . find ( "option:selected" ) . text ( ) ) ;
111
+ this . _renderButtonItem ( this . buttonItem , item ) ;
108
112
this . _resizeButton ( ) ;
109
113
110
114
this . _on ( this . button , this . _buttonEvents ) ;
@@ -190,7 +194,7 @@ return $.widget( "ui.selectmenu", {
190
194
191
195
refresh : function ( ) {
192
196
this . _refreshMenu ( ) ;
193
- this . _setText ( this . buttonText , this . _getSelectedItem ( ) . text ( ) ) ;
197
+ this . _renderButtonItem ( this . buttonItem , this . _getSelectedItem ( ) . data ( "ui-selectmenu-item" ) ) ;
194
198
if ( ! this . options . width ) {
195
199
this . _resizeButton ( ) ;
196
200
}
@@ -275,6 +279,10 @@ return $.widget( "ui.selectmenu", {
275
279
return this . menu ;
276
280
} ,
277
281
282
+ _renderButtonItem : function ( buttonItem , item ) {
283
+ this . _setText ( buttonItem , item . label ) ;
284
+ } ,
285
+
278
286
_renderMenu : function ( ul , items ) {
279
287
var that = this ,
280
288
currentOptgroup = "" ;
@@ -480,7 +488,7 @@ return $.widget( "ui.selectmenu", {
480
488
481
489
// Change native select element
482
490
this . element [ 0 ] . selectedIndex = item . index ;
483
- this . _setText ( this . buttonText , item . label ) ;
491
+ this . _renderButtonItem ( this . buttonItem , item ) ;
484
492
this . _setAria ( item ) ;
485
493
this . _trigger ( "select" , event , { item : item } ) ;
486
494
@@ -590,22 +598,27 @@ return $.widget( "ui.selectmenu", {
590
598
} ,
591
599
592
600
_parseOptions : function ( options ) {
593
- var data = [ ] ;
601
+ var that = this ,
602
+ data = [ ] ;
594
603
options . each ( function ( index , item ) {
595
- var option = $ ( item ) ,
596
- optgroup = option . parent ( "optgroup" ) ;
597
- data . push ( {
598
- element : option ,
599
- index : index ,
600
- value : option . attr ( "value" ) ,
601
- label : option . text ( ) ,
602
- optgroup : optgroup . attr ( "label" ) || "" ,
603
- disabled : optgroup . prop ( "disabled" ) || option . prop ( "disabled" )
604
- } ) ;
604
+ data . push ( that . _parseOption ( $ ( item ) , index ) ) ;
605
605
} ) ;
606
606
this . items = data ;
607
607
} ,
608
608
609
+ _parseOption : function ( option , index ) {
610
+ var optgroup = option . parent ( "optgroup" ) ;
611
+
612
+ return {
613
+ element : option ,
614
+ index : index ,
615
+ value : option . attr ( "value" ) ,
616
+ label : option . text ( ) ,
617
+ optgroup : optgroup . attr ( "label" ) || "" ,
618
+ disabled : optgroup . prop ( "disabled" ) || option . prop ( "disabled" )
619
+ } ;
620
+ } ,
621
+
609
622
_destroy : function ( ) {
610
623
this . menuWrap . remove ( ) ;
611
624
this . button . remove ( ) ;
0 commit comments