@@ -39,38 +39,38 @@ $.widget( "ui.selectmenu", {
3939 _create : function ( ) {
4040 // set a default id value, generate a new random one if not set by developer
4141 var selectmenuId = this . element . attr ( 'id' ) || 'ui-selectmenu-' + Math . random ( ) . toString ( 16 ) . slice ( 2 , 10 ) ;
42-
42+
4343 // array of button and menu id's
4444 this . ids = { id : selectmenuId , button : selectmenuId + '-button' , menu : selectmenuId + '-menu' } ;
45-
45+
4646 // set current value
4747 if ( this . options . value ) {
4848 this . element [ 0 ] . value = this . options . value ;
4949 } else {
5050 this . options . value = this . element [ 0 ] . value ;
5151 }
52-
52+
5353 // catch click event of the label
5454 this . _bind ( {
5555 'click' : function ( event ) {
5656 this . button . focus ( ) ;
5757 event . preventDefault ( ) ;
5858 }
5959 } ) ;
60-
60+
6161 this . _drawButton ( ) ;
6262 this . _bind ( this . button , this . _buttonEvents ) ;
63-
63+
6464 this . _drawMenu ( ) ;
65- this . refresh ( ) ;
65+ this . refresh ( ) ;
6666 } ,
67-
67+
6868 _drawButton : function ( ) {
69- var tabindex = this . element . attr ( 'tabindex' ) ;
70-
69+ var tabindex = this . element . attr ( 'tabindex' ) ;
70+
7171 // hide original select tag
7272 this . element . hide ( ) ;
73-
73+
7474 // create button
7575 this . button = $ ( '<a />' , {
7676 href : '#' + this . ids . id ,
@@ -81,34 +81,34 @@ $.widget( "ui.selectmenu", {
8181 } ,
8282 'aria-disabled' : this . options . disabled ,
8383 'aria-owns' : this . ids . menu ,
84- 'aria-haspopup' : true
84+ 'aria-haspopup' : true
8585 } )
8686 . button ( {
8787 label : this . element . find ( "option:selected" ) . text ( ) ,
8888 icons : {
8989 primary : ( this . options . dropdown ? 'ui-icon-triangle-1-s' : 'ui-icon-triangle-2-n-s' )
9090 }
9191 } ) ;
92-
92+
9393 // wrap and insert new button
9494 this . buttonWrap = $ ( '<span />' )
9595 . addClass ( 'ui-selectmenu-button' )
9696 . append ( this . button )
97- . insertAfter ( this . element ) ;
97+ . insertAfter ( this . element ) ;
9898 } ,
99-
99+
100100 _drawMenu : function ( ) {
101101 var that = this ;
102-
103- // create menu portion, append to body
102+
103+ // create menu portion, append to body
104104 this . menu = $ ( '<ul />' , {
105105 'class' : 'ui-widget ui-widget-content' ,
106106 'aria-hidden' : true ,
107107 'aria-labelledby' : this . ids . button ,
108108 role : 'menubox' ,
109109 id : this . ids . menu
110110 } ) ;
111-
111+
112112 // set width
113113 if ( this . options . dropdown ) {
114114 var setWidth = this . button . outerWidth ( ) ;
@@ -123,142 +123,142 @@ $.widget( "ui.selectmenu", {
123123 . width ( setWidth )
124124 . append ( this . menu )
125125 . appendTo ( this . options . appendTo ) ;
126-
126+
127127 // init menu widget
128128 this . menu . menu ( {
129129 select : function ( event , ui ) {
130130 var flag = false ,
131131 item = ui . item . data ( "item.selectmenu" ) ,
132132 oldIndex = that . element [ 0 ] . selectedIndex ;
133-
133+
134134 that . _setOption ( "value" , item . value ) ;
135135 that . _trigger ( "select" , event , { item : item } ) ;
136-
136+
137137 if ( item . index != oldIndex ) {
138138 that . _trigger ( "change" , event , { item : item } ) ;
139139 }
140-
140+
141141 if ( that . isOpen ) {
142142 event . preventDefault ( ) ;
143143 that . close ( event , true ) ;
144144 }
145145 } ,
146146 focus : function ( event , ui ) {
147147 var item = ui . item . data ( "item.selectmenu" ) ;
148-
148+
149149 if ( that . focus !== undefined && item . index != that . focus ) {
150150 that . _trigger ( "focus" , event , { item : item } ) ;
151151 }
152-
152+
153153 that . focus = item . index ;
154154 }
155155 } ) ;
156-
156+
157157 // document click closes menu
158158 this . _bind ( document , {
159159 'click' : function ( event ) {
160160 if ( this . isOpen && ! $ ( event . target ) . closest ( "#" + this . ids . button ) . length ) {
161161 this . close ( event ) ;
162162 }
163163 }
164- } ) ;
164+ } ) ;
165165 } ,
166-
166+
167167 refresh : function ( ) {
168168 this . menu . empty ( ) ;
169-
169+
170170 this . _readOptions ( ) ;
171171 this . _renderMenu ( this . menu , this . items ) ;
172-
172+
173173 this . menu . menu ( "refresh" ) ;
174-
175- // adjust ARIA
174+
175+ // adjust ARIA
176176 this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . find ( 'a' ) . attr ( 'role' , 'option' ) ;
177-
177+
178178 if ( this . options . dropdown ) {
179179 this . menu
180180 . addClass ( 'ui-corner-bottom' )
181181 . removeClass ( 'ui-corner-all' ) ;
182182 }
183-
183+
184184 // transfer disabled state
185185 if ( this . element . attr ( 'disabled' ) ) {
186186 this . disable ( ) ;
187187 } else {
188188 this . enable ( )
189189 }
190- } ,
191-
192- open : function ( event ) {
190+ } ,
191+
192+ open : function ( event ) {
193193 var currentItem = this . _getSelectedItem ( ) ;
194-
195- if ( ! this . options . disabled ) {
194+
195+ if ( ! this . options . disabled ) {
196196 if ( this . options . dropdown ) {
197197 this . button
198198 . addClass ( 'ui-corner-top' )
199199 . removeClass ( 'ui-corner-all' ) ;
200- }
201-
200+ }
201+
202202 this . menuWrap . addClass ( 'ui-selectmenu-open' ) ;
203203 // needs to be fired after the document click event has closed all other Selectmenus
204204 // otherwise the current item is not indicated
205205 // TODO check if this should be handled by Menu
206206 this . _delay ( function ( ) {
207207 this . menu . menu ( "focus" , event , currentItem ) ;
208208 } , 1 ) ;
209-
209+
210210 if ( ! this . options . dropdown ) {
211211 // center current item
212212 if ( this . menu . css ( "overflow" ) == "auto" ) {
213213 this . menu . scrollTop ( this . menu . scrollTop ( ) + currentItem . position ( ) . top - this . menu . outerHeight ( ) / 2 + currentItem . outerHeight ( ) / 2 ) ;
214- }
214+ }
215215 // calculate offset
216- var _offset = ( this . menu . offset ( ) . top - currentItem . offset ( ) . top + ( this . button . outerHeight ( ) - currentItem . outerHeight ( ) ) / 2 ) ;
216+ var _offset = ( this . menu . offset ( ) . top - currentItem . offset ( ) . top + ( this . button . outerHeight ( ) - currentItem . outerHeight ( ) ) / 2 ) ;
217217 $ . extend ( this . options . position , {
218218 my : "left top" ,
219219 at : "left top" ,
220220 offset : "0 " + _offset
221221 } ) ;
222222 }
223-
224- this . menuWrap
223+
224+ this . menuWrap
225225 . zIndex ( this . element . zIndex ( ) + 1 )
226226 . position ( $ . extend ( {
227227 of : this . button
228228 } , this . options . position ) ) ;
229-
229+
230230 this . isOpen = true ;
231231 this . _trigger ( "open" , event ) ;
232232 }
233- } ,
234-
233+ } ,
234+
235235 close : function ( event , focus ) {
236236 if ( this . isOpen ) {
237237 if ( this . options . dropdown ) {
238238 this . button
239239 . addClass ( 'ui-corner-all' )
240240 . removeClass ( 'ui-corner-top' ) ;
241241 }
242-
242+
243243 this . menuWrap . removeClass ( 'ui-selectmenu-open' ) ;
244244 this . isOpen = false ;
245-
245+
246246 if ( focus ) {
247247 this . button . focus ( ) ;
248248 }
249-
249+
250250 this . _trigger ( "close" , event ) ;
251251 }
252252 } ,
253-
253+
254254 widget : function ( ) {
255255 return this . buttonWrap . add ( this . menuWrap ) ;
256256 } ,
257-
257+
258258 _renderMenu : function ( ul , items ) {
259259 var that = this ,
260260 currentOptgroup = "" ;
261-
261+
262262 $ . each ( items , function ( index , item ) {
263263 if ( item . optgroup != currentOptgroup ) {
264264 var optgroup = $ ( '<li class="ui-selectmenu-optgroup">' + item . optgroup + '</li>' ) ;
@@ -269,7 +269,7 @@ $.widget( "ui.selectmenu", {
269269 that . _renderItem ( ul , item ) ;
270270 } ) ;
271271 } ,
272-
272+
273273 _renderItem : function ( ul , item ) {
274274 var li = $ ( "<li />" ) . data ( "item.selectmenu" , item ) ;
275275 if ( item . disabled ) {
@@ -280,35 +280,35 @@ $.widget( "ui.selectmenu", {
280280 href : '#'
281281 } )
282282 ) ;
283- }
284-
283+ }
284+
285285 return li . appendTo ( ul ) ;
286286 } ,
287-
287+
288288 _move : function ( key , event ) {
289289 if ( ! this . isOpen ) {
290290 this . menu . menu ( "focus" , event , this . _getSelectedItem ( ) ) ;
291291 }
292-
293- this . menu . menu ( key , event ) ;
294-
292+
293+ this . menu . menu ( key , event ) ;
294+
295295 if ( ! this . isOpen ) {
296296 this . menu . menu ( "select" , event ) ;
297297 }
298298 } ,
299-
299+
300300 _getSelectedItem : function ( ) {
301- return this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . eq ( this . element [ 0 ] . selectedIndex ) ;
301+ return this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . eq ( this . element [ 0 ] . selectedIndex ) ;
302302 } ,
303-
303+
304304 _toggle : function ( event ) {
305- if ( this . isOpen ) {
305+ if ( this . isOpen ) {
306306 this . close ( event ) ;
307- } else {
307+ } else {
308308 this . open ( event ) ;
309309 }
310310 } ,
311-
311+
312312 _buttonEvents : {
313313 click : function ( event ) {
314314 this . _toggle ( event ) ;
@@ -324,7 +324,7 @@ $.widget( "ui.selectmenu", {
324324 case $ . ui . keyCode . ENTER :
325325 if ( this . isOpen ) {
326326 this . menu . menu ( "select" , this . _getSelectedItem ( ) ) ;
327- }
327+ }
328328 event . preventDefault ( ) ;
329329 break ;
330330 case $ . ui . keyCode . SPACE :
@@ -358,11 +358,11 @@ $.widget( "ui.selectmenu", {
358358 this . menu . trigger ( event ) ;
359359 }
360360 }
361- } ,
362-
361+ } ,
362+
363363 _setOption : function ( key , value ) {
364364 this . _super ( "_setOption" , key , value ) ;
365-
365+
366366 if ( key === "appendTo" ) {
367367 this . menuWrap . appendTo ( $ ( value || "body" , this . element [ 0 ] . ownerDocument ) [ 0 ] ) ;
368368 }
@@ -385,7 +385,7 @@ $.widget( "ui.selectmenu", {
385385 } ,
386386
387387 _readOptions : function ( ) {
388- var data = [ ] ;
388+ var data = [ ] ;
389389 $ . each ( this . element . find ( 'option' ) , function ( index , item ) {
390390 var option = $ ( item ) ,
391391 optgroup = option . parent ( "optgroup" ) ;
@@ -400,7 +400,7 @@ $.widget( "ui.selectmenu", {
400400 } ) ;
401401 this . items = data ;
402402 } ,
403-
403+
404404 _destroy : function ( ) {
405405 this . menuWrap . remove ( ) ;
406406 this . buttonWrap . remove ( ) ;
0 commit comments