@@ -131,7 +131,7 @@ $.widget("ui.menu", {
131
131
this . element . attr ( "scrollTop" , scroll + offset - elementHeight + item . height ( ) ) ;
132
132
}
133
133
}
134
- this . active = item . eq ( 0 )
134
+ this . active = item . first ( )
135
135
. children ( "a" )
136
136
. addClass ( "ui-state-hover" )
137
137
. attr ( "id" , "ui-active-menuitem" )
@@ -150,11 +150,11 @@ $.widget("ui.menu", {
150
150
} ,
151
151
152
152
next : function ( event ) {
153
- this . _move ( "next" , ".ui-menu-item: first" , event ) ;
153
+ this . _move ( "next" , ".ui-menu-item" , " first", event ) ;
154
154
} ,
155
155
156
156
previous : function ( event ) {
157
- this . _move ( "prev" , ".ui-menu-item: last" , event ) ;
157
+ this . _move ( "prev" , ".ui-menu-item" , " last", event ) ;
158
158
} ,
159
159
160
160
first : function ( ) {
@@ -165,69 +165,73 @@ $.widget("ui.menu", {
165
165
return this . active && ! this . active . nextAll ( ".ui-menu-item" ) . length ;
166
166
} ,
167
167
168
- _move : function ( direction , edge , event ) {
168
+ _move : function ( direction , edge , filter , event ) {
169
169
if ( ! this . active ) {
170
- this . activate ( event , this . element . children ( edge ) ) ;
170
+ this . activate ( event , this . element . children ( edge ) [ filter ] ( ) ) ;
171
171
return ;
172
172
}
173
173
var next = this . active [ direction + "All" ] ( ".ui-menu-item" ) . eq ( 0 ) ;
174
174
if ( next . length ) {
175
175
this . activate ( event , next ) ;
176
176
} else {
177
- this . activate ( event , this . element . children ( edge ) ) ;
177
+ this . activate ( event , this . element . children ( edge ) [ filter ] ( ) ) ;
178
178
}
179
179
} ,
180
180
181
181
// TODO merge with previousPage
182
182
nextPage : function ( event ) {
183
183
if ( this . _hasScroll ( ) ) {
184
- // TODO merge with no-scroll-else
185
184
if ( ! this . active || this . last ( ) ) {
186
- this . activate ( event , this . element . children ( ":first" ) ) ;
185
+ this . activate ( event , this . element . children ( ".ui-menu-item" ) . first ( ) ) ;
187
186
return ;
188
187
}
189
188
var base = this . active . offset ( ) . top ,
190
189
height = this . element . height ( ) ,
191
- result = this . element . children ( "li" ) . filter ( function ( ) {
190
+ // TODO replace children with nextAll
191
+ // TODO replace filter with each, break once close > 0 and use that item as the result
192
+ result = this . element . children ( ".ui-menu-item" ) . filter ( function ( ) {
192
193
var close = $ ( this ) . offset ( ) . top - base - height + $ ( this ) . height ( ) ;
193
- // TODO improve approximation
194
+ // TODO replace with check close > 0
194
195
return close < 10 && close > - 10 ;
195
196
} ) ;
196
197
197
198
// TODO try to catch this earlier when scrollTop indicates the last page anyway
198
199
if ( ! result . length ) {
199
- result = this . element . children ( ":last" ) ;
200
+ result = this . element . children ( ".ui-menu-item" ) . last ( ) ;
200
201
}
201
202
this . activate ( event , result ) ;
202
203
} else {
203
- this . activate ( event , this . element . children ( ! this . active || this . last ( ) ? ":first" : ":last" ) ) ;
204
+ this . activate ( event , this . element . children ( ".ui-menu-item" )
205
+ // TODO use .first()/.last()
206
+ . filter ( ! this . active || this . last ( ) ? ":first" : ":last" ) ) ;
204
207
}
205
208
} ,
206
209
207
210
// TODO merge with nextPage
208
211
previousPage : function ( event ) {
209
212
if ( this . _hasScroll ( ) ) {
210
- // TODO merge with no-scroll-else
211
213
if ( ! this . active || this . first ( ) ) {
212
- this . activate ( event , this . element . children ( ":last" ) ) ;
214
+ this . activate ( event , this . element . children ( ".ui-menu-item" ) . last ( ) ) ;
213
215
return ;
214
216
}
215
217
216
218
var base = this . active . offset ( ) . top ,
217
219
height = this . element . height ( ) ;
218
- result = this . element . children ( "li " ) . filter ( function ( ) {
220
+ result = this . element . children ( ".ui-menu-item " ) . filter ( function ( ) {
219
221
var close = $ ( this ) . offset ( ) . top - base + height - $ ( this ) . height ( ) ;
220
222
// TODO improve approximation
221
223
return close < 10 && close > - 10 ;
222
224
} ) ;
223
225
224
226
// TODO try to catch this earlier when scrollTop indicates the last page anyway
225
227
if ( ! result . length ) {
226
- result = this . element . children ( ":first" ) ;
228
+ result = this . element . children ( ".ui-menu-item" ) . first ( ) ;
227
229
}
228
230
this . activate ( event , result ) ;
229
231
} else {
230
- this . activate ( event , this . element . children ( ! this . active || this . first ( ) ? ":last" : ":first" ) ) ;
232
+ this . activate ( event , this . element . children ( ".ui-menu-item" )
233
+ // TODO use .first()/.last()
234
+ . filter ( ! this . active || this . first ( ) ? ":last" : ":first" ) ) ;
231
235
}
232
236
} ,
233
237
0 commit comments