15
15
16
16
var idIncrement = 0 ;
17
17
18
- $ . widget ( "ui.menu" , {
18
+ $ . widget ( "ui.menu" , {
19
19
version : "@VERSION" ,
20
20
defaultElement : "<ul>" ,
21
21
delay : 150 ,
@@ -29,8 +29,8 @@ $.widget("ui.menu", {
29
29
var self = this ;
30
30
this . activeMenu = this . element ;
31
31
this . menuId = this . element . attr ( "id" ) || "ui-menu-" + idIncrement ++ ;
32
- if ( this . element . find ( ".ui-icon" ) . length ) {
33
- this . element . addClass ( "ui-menu-icons" ) ;
32
+ if ( this . element . find ( ".ui-icon" ) . length ) {
33
+ this . element . addClass ( "ui-menu-icons" ) ;
34
34
}
35
35
this . element
36
36
. addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" )
@@ -61,7 +61,7 @@ $.widget("ui.menu", {
61
61
self . focus ( event , target ) ;
62
62
}
63
63
} )
64
- . bind ( "mouseout.menu" , function ( event ) {
64
+ . bind ( "mouseout.menu" , function ( event ) {
65
65
if ( self . options . disabled ) {
66
66
return ;
67
67
}
@@ -110,8 +110,8 @@ $.widget("ui.menu", {
110
110
event . preventDefault ( ) ;
111
111
break ;
112
112
case $ . ui . keyCode . ENTER :
113
- if ( self . active . children ( "a[aria-haspopup='true']" ) . length ) {
114
- if ( self . right ( event ) ) {
113
+ if ( self . active . children ( "a[aria-haspopup='true']" ) . length ) {
114
+ if ( self . right ( event ) ) {
115
115
event . stopImmediatePropagation ( ) ;
116
116
}
117
117
}
@@ -129,7 +129,7 @@ $.widget("ui.menu", {
129
129
break ;
130
130
default :
131
131
event . stopPropagation ( ) ;
132
- clearTimeout ( self . filterTimer ) ;
132
+ clearTimeout ( self . filterTimer ) ;
133
133
var match ,
134
134
prev = self . previousFilter || "" ,
135
135
character = String . fromCharCode ( event . keyCode ) ,
@@ -140,26 +140,28 @@ $.widget("ui.menu", {
140
140
} else {
141
141
character = prev + character ;
142
142
}
143
- function escape ( value ) {
144
- return value . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, "\\$&" ) ;
143
+ function escape ( value ) {
144
+ return value . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g , "\\$&" ) ;
145
145
}
146
- match = self . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
147
- return new RegExp ( "^" + escape ( character ) , "i" ) . test ( $ ( this ) . children ( "a" ) . text ( ) ) ;
146
+ match = self . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
147
+ return new RegExp ( "^" + escape ( character ) , "i" )
148
+ . test ( $ ( this ) . children ( "a" ) . text ( ) ) ;
148
149
} ) ;
149
150
match = skip && match . index ( self . active . next ( ) ) != - 1 ? self . active . nextAll ( ".ui-menu-item" ) : match ;
150
- if ( ! match . length ) {
151
+ if ( ! match . length ) {
151
152
character = String . fromCharCode ( event . keyCode ) ;
152
- match = self . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
153
- return new RegExp ( "^" + escape ( character ) , "i" ) . test ( $ ( this ) . children ( "a" ) . text ( ) ) ;
153
+ match = self . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) {
154
+ return new RegExp ( "^" + escape ( character ) , "i" )
155
+ . test ( $ ( this ) . children ( "a" ) . text ( ) ) ;
154
156
} ) ;
155
157
}
156
- if ( match . length ) {
157
- self . focus ( event , match ) ;
158
+ if ( match . length ) {
159
+ self . focus ( event , match ) ;
158
160
if ( match . length > 1 ) {
159
161
self . previousFilter = character ;
160
- self . filterTimer = setTimeout ( function ( ) {
162
+ self . filterTimer = setTimeout ( function ( ) {
161
163
delete self . previousFilter ;
162
- } , 1000 ) ;
164
+ } , 1000 ) ;
163
165
} else {
164
166
delete self . previousFilter ;
165
167
}
@@ -174,11 +176,11 @@ $.widget("ui.menu", {
174
176
//destroy (sub)menus
175
177
this . element
176
178
. removeAttr ( "aria-activedescendant" )
177
- . find ( "ul" )
179
+ . find ( "ul" )
178
180
. andSelf ( )
179
181
. removeClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" )
180
182
. removeAttr ( "role" )
181
- . removeAttr ( "tabIndex" )
183
+ . removeAttr ( "tabIndex" )
182
184
. removeAttr ( "aria-labelledby" )
183
185
. removeAttr ( "aria-expanded" )
184
186
. removeAttr ( "aria-hidden" )
@@ -195,24 +197,25 @@ $.widget("ui.menu", {
195
197
. removeAttr ( "role" )
196
198
. removeAttr ( "aria-haspopup" )
197
199
. removeAttr ( "id" )
198
- . children ( ".ui-icon" ) . remove ( ) ;
200
+ . children ( ".ui-icon" )
201
+ . remove ( ) ;
199
202
} ,
200
203
201
204
refresh : function ( ) {
202
- var self = this ;
203
- // initialize nested menus
204
- var submenus = this . element . find ( "ul:not(.ui-menu)" )
205
- . addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all " )
206
- . attr ( "role" , " menu" )
207
- . hide ( )
208
- . attr ( "aria-hidden" , "true" )
209
- . attr ( "aria-expanded " , "false " )
210
- ;
205
+ var self = this ,
206
+
207
+ // initialize nested menus
208
+ submenus = this . element . find ( "ul:not(. ui-menu) " )
209
+ . addClass ( "ui- menu ui-widget ui-widget-content ui-corner-all " )
210
+ . attr ( "role" , "menu" )
211
+ . hide ( )
212
+ . attr ( "aria-hidden " , "true " )
213
+ . attr ( "aria-expanded" , "false" ) ,
211
214
212
215
// don't refresh list items that are already adapted
213
- var items = submenus . add ( this . element ) . children ( "li:not(.ui-menu-item):has(a)" )
214
- . addClass ( "ui-menu-item" )
215
- . attr ( "role" , "presentation" ) ;
216
+ items = submenus . add ( this . element ) . children ( "li:not(.ui-menu-item):has(a)" )
217
+ . addClass ( "ui-menu-item" )
218
+ . attr ( "role" , "presentation" ) ;
216
219
217
220
items . children ( "a" )
218
221
. addClass ( "ui-corner-all" )
@@ -233,17 +236,19 @@ $.widget("ui.menu", {
233
236
} ,
234
237
235
238
focus : function ( event , item ) {
236
- var nested , self = this ;
239
+ var nested ,
240
+ self = this ;
237
241
238
242
this . blur ( ) ;
239
243
240
244
if ( this . _hasScroll ( ) ) {
241
- var borderTop = parseFloat ( $ . curCSS ( this . element [ 0 ] , "borderTopWidth" , true ) ) || 0 ,
242
- paddingTop = parseFloat ( $ . curCSS ( this . element [ 0 ] , "paddingTop" , true ) ) || 0 ,
245
+ var borderTop = parseFloat ( $ . curCSS ( this . element [ 0 ] , "borderTopWidth" , true ) ) || 0 ,
246
+ paddingTop = parseFloat ( $ . curCSS ( this . element [ 0 ] , "paddingTop" , true ) ) || 0 ,
243
247
offset = item . offset ( ) . top - this . element . offset ( ) . top - borderTop - paddingTop ,
244
248
scroll = this . element . scrollTop ( ) ,
245
249
elementHeight = this . element . height ( ) ,
246
250
itemHeight = item . height ( ) ;
251
+
247
252
if ( offset < 0 ) {
248
253
this . element . scrollTop ( scroll + offset ) ;
249
254
} else if ( offset + itemHeight > elementHeight ) {
@@ -273,67 +278,90 @@ $.widget("ui.menu", {
273
278
this . _trigger ( "focus" , event , { item : item } ) ;
274
279
} ,
275
280
276
- blur : function ( event ) {
277
- if ( ! this . active ) {
281
+ blur : function ( event ) {
282
+ if ( ! this . active ) {
278
283
return ;
279
284
}
280
285
281
- clearTimeout ( this . timer ) ;
286
+ clearTimeout ( this . timer ) ;
282
287
283
288
this . active . children ( "a" ) . removeClass ( "ui-state-focus" ) ;
284
289
this . active = null ;
285
290
} ,
286
291
287
- _startOpening : function ( submenu ) {
288
- clearTimeout ( this . timer ) ;
292
+ _startOpening : function ( submenu ) {
293
+ clearTimeout ( this . timer ) ;
289
294
var self = this ;
290
- self . timer = setTimeout ( function ( ) {
295
+ self . timer = setTimeout ( function ( ) {
291
296
self . _close ( ) ;
292
- self . _open ( submenu ) ;
293
- } , self . delay ) ;
297
+ self . _open ( submenu ) ;
298
+ } , self . delay ) ;
294
299
} ,
295
300
296
- _open : function ( submenu ) {
297
- clearTimeout ( this . timer ) ;
298
- this . element . find ( ".ui-menu" ) . not ( submenu . parents ( ) ) . hide ( ) . attr ( "aria-hidden" , "true" ) ;
301
+ _open : function ( submenu ) {
302
+ clearTimeout ( this . timer ) ;
303
+ this . element
304
+ . find ( ".ui-menu" )
305
+ . not ( submenu . parents ( ) )
306
+ . hide ( )
307
+ . attr ( "aria-hidden" , "true" ) ;
308
+
299
309
var position = $ . extend ( { } , {
300
- of : this . active
301
- } , $ . type ( this . options . position ) == "function"
302
- ? this . options . position ( this . active )
303
- : this . options . position
304
- ) ;
305
- submenu . show ( ) . removeAttr ( "aria-hidden" ) . attr ( "aria-expanded" , "true" ) . position ( position ) ;
310
+ of : this . active
311
+ } , $ . type ( this . options . position ) == "function"
312
+ ? this . options . position ( this . active )
313
+ : this . options . position
314
+ ) ;
315
+
316
+ submenu . show ( )
317
+ . removeAttr ( "aria-hidden" )
318
+ . attr ( "aria-expanded" , "true" )
319
+ . position ( position ) ;
306
320
} ,
307
321
308
322
closeAll : function ( ) {
309
323
this . element
310
- . find ( "ul" ) . hide ( ) . attr ( "aria-hidden" , "true" ) . attr ( "aria-expanded" , "false" ) . end ( )
311
- . find ( "a.ui-state-active" ) . removeClass ( "ui-state-active" ) ;
324
+ . find ( "ul" )
325
+ . hide ( )
326
+ . attr ( "aria-hidden" , "true" )
327
+ . attr ( "aria-expanded" , "false" )
328
+ . end ( )
329
+ . find ( "a.ui-state-active" )
330
+ . removeClass ( "ui-state-active" ) ;
331
+
312
332
this . blur ( ) ;
313
333
this . activeMenu = this . element ;
314
334
} ,
315
335
316
336
_close : function ( ) {
317
337
this . active . parent ( )
318
- . find ( "ul" ) . hide ( ) . attr ( "aria-hidden" , "true" ) . attr ( "aria-expanded" , "false" ) . end ( )
319
- . find ( "a.ui-state-active" ) . removeClass ( "ui-state-active" ) ;
338
+ . find ( "ul" )
339
+ . hide ( )
340
+ . attr ( "aria-hidden" , "true" )
341
+ . attr ( "aria-expanded" , "false" )
342
+ . end ( )
343
+ . find ( "a.ui-state-active" )
344
+ . removeClass ( "ui-state-active" ) ;
320
345
} ,
321
346
322
- left : function ( event ) {
347
+ left : function ( event ) {
323
348
var newItem = this . active && this . active . parents ( "li:not(.ui-menubar-item)" ) . first ( ) ;
324
- if ( newItem && newItem . length ) {
325
- this . active . parent ( ) . attr ( "aria-hidden" , "true" ) . attr ( "aria-expanded" , "false" ) . hide ( ) ;
326
- this . focus ( event , newItem ) ;
349
+ if ( newItem && newItem . length ) {
350
+ this . active . parent ( )
351
+ . attr ( "aria-hidden" , "true" )
352
+ . attr ( "aria-expanded" , "false" )
353
+ . hide ( ) ;
354
+ this . focus ( event , newItem ) ;
327
355
return true ;
328
356
}
329
357
} ,
330
358
331
- right : function ( event ) {
332
- var self = this ;
333
- var newItem = this . active && this . active . children ( "ul" ) . children ( "li" ) . first ( ) ;
334
- if ( newItem && newItem . length ) {
335
- this . _open ( newItem . parent ( ) ) ;
336
- var current = this . active ;
359
+ right : function ( event ) {
360
+ var self = this ,
361
+ newItem = this . active && this . active . children ( "ul" ) . children ( "li" ) . first ( ) ;
362
+
363
+ if ( newItem && newItem . length ) {
364
+ this . _open ( newItem . parent ( ) ) ;
337
365
338
366
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
339
367
setTimeout ( function ( ) {
@@ -359,16 +387,16 @@ $.widget("ui.menu", {
359
387
return this . active && ! this . active . nextAll ( ".ui-menu-item" ) . length ;
360
388
} ,
361
389
362
- _move : function ( direction , edge , filter , event ) {
390
+ _move : function ( direction , edge , filter , event ) {
363
391
if ( ! this . active ) {
364
- this . focus ( event , this . activeMenu . children ( edge ) [ filter ] ( ) ) ;
392
+ this . focus ( event , this . activeMenu . children ( edge ) [ filter ] ( ) ) ;
365
393
return ;
366
394
}
367
395
var next = this . active [ direction + "All" ] ( ".ui-menu-item" ) . eq ( 0 ) ;
368
396
if ( next . length ) {
369
397
this . focus ( event , next ) ;
370
398
} else {
371
- this . focus ( event , this . activeMenu . children ( edge ) [ filter ] ( ) ) ;
399
+ this . focus ( event , this . activeMenu . children ( edge ) [ filter ] ( ) ) ;
372
400
}
373
401
} ,
374
402
0 commit comments