3
3
* See COPYING.txt for license details.
4
4
*/
5
5
6
- /* eslint-disable strict */
7
-
8
6
define ( [
9
7
'jquery' ,
10
8
'matchMedia' ,
@@ -149,7 +147,7 @@ define([
149
147
} else if ( ! activeCategoryLink . parent ( ) . hasClass ( 'active' ) ) {
150
148
activeCategoryLink . parent ( ) . addClass ( 'active' ) ;
151
149
classes = activeCategoryLink . parent ( ) . attr ( 'class' ) ;
152
- classNav = classes . match ( / ( n a v \ -) [ 0 - 9 ] + ( \ -[ 0 - 9 ] + ) + / gi) ;
150
+ classNav = classes . match ( / ( n a v - ) [ 0 - 9 ] + ( - [ 0 - 9 ] + ) + / gi) ;
153
151
154
152
if ( classNav ) {
155
153
this . _setActiveParent ( classNav [ 0 ] ) ;
@@ -186,7 +184,8 @@ define([
186
184
187
185
/**
188
186
* Extracts the URL extension from the given URL.
189
- * It identifies the last segment of the URL after the last slash ('/') and returns the substring after the last dot ('.')
187
+ * It identifies the last segment of the URL after the last slash ('/')
188
+ * and returns the substring after the last dot ('.')
190
189
* If there's no dot in the last segment, it returns an empty string.
191
190
*
192
191
* @param {String } url - The URL from which to extract the extension.
@@ -195,6 +194,7 @@ define([
195
194
*/
196
195
_getUrlExtension : function ( url ) {
197
196
var lastSegment = url . slice ( url . lastIndexOf ( '/' ) + 1 ) ;
197
+
198
198
return lastSegment . includes ( '.' ) ? lastSegment . slice ( lastSegment . lastIndexOf ( '.' ) ) : '' ;
199
199
} ,
200
200
@@ -220,19 +220,22 @@ define([
220
220
* @private
221
221
*/
222
222
_setActiveMenuForProduct : function ( currentUrl ) {
223
- var firstCategoryUrl = this . element . find ( '> li a' ) . attr ( 'href' ) ;
223
+ var firstCategoryUrl = this . element . find ( '> li a' ) . attr ( 'href' ) ,
224
+ categoryUrlExtension ,
225
+ categoryUrl ,
226
+ isProductPage ,
227
+ currentHostname ;
224
228
225
229
if ( ! firstCategoryUrl ) {
226
230
this . _clearActiveState ( ) ;
227
231
return ;
228
232
}
229
233
230
- var categoryUrlExtension = this . _getUrlExtension ( firstCategoryUrl ) ;
231
- var categoryUrl ;
232
- var isProductPage = this . _isProductPage ( ) ;
234
+ categoryUrlExtension = this . _getUrlExtension ( firstCategoryUrl ) ;
235
+ isProductPage = this . _isProductPage ( ) ;
233
236
234
237
if ( isProductPage ) {
235
- var currentHostname = window . location . hostname ;
238
+ currentHostname = window . location . hostname ;
236
239
237
240
if ( document . referrer . includes ( currentHostname ) && document . referrer . endsWith ( categoryUrlExtension ) ) {
238
241
categoryUrl = document . referrer . split ( '?' ) [ 0 ] ;
@@ -290,172 +293,172 @@ define([
290
293
* @param {String } value
291
294
*/
292
295
function escape ( value ) {
293
- return value . replace ( / [ \- \ [\] { } ( ) * + ? . , \ \\^ $ | # \s ] / g, '\\$&' ) ;
296
+ return value . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, '\\$&' ) ;
294
297
}
295
298
296
299
if ( this . active . closest ( this . options . menus ) . attr ( 'aria-expanded' ) != 'true' ) { //eslint-disable-line eqeqeq
297
300
298
301
switch ( event . keyCode ) {
299
- case $ . ui . keyCode . PAGE_UP :
300
- this . previousPage ( event ) ;
301
- break ;
302
+ case $ . ui . keyCode . PAGE_UP :
303
+ this . previousPage ( event ) ;
304
+ break ;
302
305
303
- case $ . ui . keyCode . PAGE_DOWN :
304
- this . nextPage ( event ) ;
305
- break ;
306
+ case $ . ui . keyCode . PAGE_DOWN :
307
+ this . nextPage ( event ) ;
308
+ break ;
306
309
307
- case $ . ui . keyCode . HOME :
308
- this . _move ( 'first' , 'first' , event ) ;
309
- break ;
310
+ case $ . ui . keyCode . HOME :
311
+ this . _move ( 'first' , 'first' , event ) ;
312
+ break ;
310
313
311
- case $ . ui . keyCode . END :
312
- this . _move ( 'last' , 'last' , event ) ;
313
- break ;
314
+ case $ . ui . keyCode . END :
315
+ this . _move ( 'last' , 'last' , event ) ;
316
+ break ;
314
317
315
- case $ . ui . keyCode . UP :
316
- this . previous ( event ) ;
317
- break ;
318
+ case $ . ui . keyCode . UP :
319
+ this . previous ( event ) ;
320
+ break ;
318
321
319
- case $ . ui . keyCode . DOWN :
320
- if ( this . active && ! this . active . is ( '.ui-state-disabled' ) ) {
321
- this . expand ( event ) ;
322
- }
323
- break ;
324
-
325
- case $ . ui . keyCode . LEFT :
326
- this . previous ( event ) ;
327
- break ;
328
-
329
- case $ . ui . keyCode . RIGHT :
330
- this . next ( event ) ;
331
- break ;
332
-
333
- case $ . ui . keyCode . ENTER :
334
- case $ . ui . keyCode . SPACE :
335
- this . _activate ( event ) ;
336
- break ;
337
-
338
- case $ . ui . keyCode . ESCAPE :
339
- this . collapse ( event ) ;
340
- break ;
341
- default :
342
- preventDefault = false ;
343
- prev = this . previousFilter || '' ;
344
- character = String . fromCharCode ( event . keyCode ) ;
345
- skip = false ;
346
-
347
- clearTimeout ( this . filterTimer ) ;
322
+ case $ . ui . keyCode . DOWN :
323
+ if ( this . active && ! this . active . is ( '.ui-state-disabled' ) ) {
324
+ this . expand ( event ) ;
325
+ }
326
+ break ;
327
+
328
+ case $ . ui . keyCode . LEFT :
329
+ this . previous ( event ) ;
330
+ break ;
331
+
332
+ case $ . ui . keyCode . RIGHT :
333
+ this . next ( event ) ;
334
+ break ;
335
+
336
+ case $ . ui . keyCode . ENTER :
337
+ case $ . ui . keyCode . SPACE :
338
+ this . _activate ( event ) ;
339
+ break ;
340
+
341
+ case $ . ui . keyCode . ESCAPE :
342
+ this . collapse ( event ) ;
343
+ break ;
344
+ default :
345
+ preventDefault = false ;
346
+ prev = this . previousFilter || '' ;
347
+ character = String . fromCharCode ( event . keyCode ) ;
348
+ skip = false ;
349
+
350
+ clearTimeout ( this . filterTimer ) ;
351
+
352
+ if ( character === prev ) {
353
+ skip = true ;
354
+ } else {
355
+ character = prev + character ;
356
+ }
348
357
349
- if ( character === prev ) {
350
- skip = true ;
351
- } else {
352
- character = prev + character ;
353
- }
358
+ regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
359
+ match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
360
+ return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
361
+ } ) ;
362
+ match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
363
+ this . active . nextAll ( '.ui-menu-item' ) :
364
+ match ;
354
365
366
+ // If no matches on the current filter, reset to the last character pressed
367
+ // to move down the menu to the first item that starts with that character
368
+ if ( ! match . length ) {
369
+ character = String . fromCharCode ( event . keyCode ) ;
355
370
regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
356
371
match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
357
372
return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
358
373
} ) ;
359
- match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
360
- this . active . nextAll ( '.ui-menu-item' ) :
361
- match ;
362
-
363
- // If no matches on the current filter, reset to the last character pressed
364
- // to move down the menu to the first item that starts with that character
365
- if ( ! match . length ) {
366
- character = String . fromCharCode ( event . keyCode ) ;
367
- regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
368
- match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
369
- return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
370
- } ) ;
371
- }
374
+ }
372
375
373
- if ( match . length ) {
374
- this . focus ( event , match ) ;
376
+ if ( match . length ) {
377
+ this . focus ( event , match ) ;
375
378
376
- if ( match . length > 1 ) {
377
- this . previousFilter = character ;
378
- this . filterTimer = this . _delay ( function ( ) {
379
- delete this . previousFilter ;
380
- } , 1000 ) ;
381
- } else {
379
+ if ( match . length > 1 ) {
380
+ this . previousFilter = character ;
381
+ this . filterTimer = this . _delay ( function ( ) {
382
382
delete this . previousFilter ;
383
- }
383
+ } , 1000 ) ;
384
384
} else {
385
385
delete this . previousFilter ;
386
386
}
387
+ } else {
388
+ delete this . previousFilter ;
389
+ }
387
390
}
388
391
} else {
389
392
switch ( event . keyCode ) {
390
- case $ . ui . keyCode . DOWN :
391
- this . next ( event ) ;
392
- break ;
393
-
394
- case $ . ui . keyCode . UP :
395
- this . previous ( event ) ;
396
- break ;
393
+ case $ . ui . keyCode . DOWN :
394
+ this . next ( event ) ;
395
+ break ;
397
396
398
- case $ . ui . keyCode . RIGHT :
399
- if ( this . active && ! this . active . is ( '.ui-state-disabled' ) ) {
400
- this . expand ( event ) ;
401
- }
402
- break ;
403
-
404
- case $ . ui . keyCode . ENTER :
405
- case $ . ui . keyCode . SPACE :
406
- this . _activate ( event ) ;
407
- break ;
408
-
409
- case $ . ui . keyCode . LEFT :
410
- case $ . ui . keyCode . ESCAPE :
411
- this . collapse ( event ) ;
412
- break ;
413
- default :
414
- preventDefault = false ;
415
- prev = this . previousFilter || '' ;
416
- character = String . fromCharCode ( event . keyCode ) ;
417
- skip = false ;
397
+ case $ . ui . keyCode . UP :
398
+ this . previous ( event ) ;
399
+ break ;
418
400
419
- clearTimeout ( this . filterTimer ) ;
401
+ case $ . ui . keyCode . RIGHT :
402
+ if ( this . active && ! this . active . is ( '.ui-state-disabled' ) ) {
403
+ this . expand ( event ) ;
404
+ }
405
+ break ;
406
+
407
+ case $ . ui . keyCode . ENTER :
408
+ case $ . ui . keyCode . SPACE :
409
+ this . _activate ( event ) ;
410
+ break ;
411
+
412
+ case $ . ui . keyCode . LEFT :
413
+ case $ . ui . keyCode . ESCAPE :
414
+ this . collapse ( event ) ;
415
+ break ;
416
+ default :
417
+ preventDefault = false ;
418
+ prev = this . previousFilter || '' ;
419
+ character = String . fromCharCode ( event . keyCode ) ;
420
+ skip = false ;
421
+
422
+ clearTimeout ( this . filterTimer ) ;
423
+
424
+ if ( character === prev ) {
425
+ skip = true ;
426
+ } else {
427
+ character = prev + character ;
428
+ }
420
429
421
- if ( character === prev ) {
422
- skip = true ;
423
- } else {
424
- character = prev + character ;
425
- }
430
+ regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
431
+ match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
432
+ return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
433
+ } ) ;
434
+ match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
435
+ this . active . nextAll ( '.ui-menu-item' ) :
436
+ match ;
426
437
438
+ // If no matches on the current filter, reset to the last character pressed
439
+ // to move down the menu to the first item that starts with that character
440
+ if ( ! match . length ) {
441
+ character = String . fromCharCode ( event . keyCode ) ;
427
442
regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
428
443
match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
429
444
return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
430
445
} ) ;
431
- match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
432
- this . active . nextAll ( '.ui-menu-item' ) :
433
- match ;
434
-
435
- // If no matches on the current filter, reset to the last character pressed
436
- // to move down the menu to the first item that starts with that character
437
- if ( ! match . length ) {
438
- character = String . fromCharCode ( event . keyCode ) ;
439
- regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
440
- match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
441
- return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
442
- } ) ;
443
- }
446
+ }
444
447
445
- if ( match . length ) {
446
- this . focus ( event , match ) ;
448
+ if ( match . length ) {
449
+ this . focus ( event , match ) ;
447
450
448
- if ( match . length > 1 ) {
449
- this . previousFilter = character ;
450
- this . filterTimer = this . _delay ( function ( ) {
451
- delete this . previousFilter ;
452
- } , 1000 ) ;
453
- } else {
451
+ if ( match . length > 1 ) {
452
+ this . previousFilter = character ;
453
+ this . filterTimer = this . _delay ( function ( ) {
454
454
delete this . previousFilter ;
455
- }
455
+ } , 1000 ) ;
456
456
} else {
457
457
delete this . previousFilter ;
458
458
}
459
+ } else {
460
+ delete this . previousFilter ;
461
+ }
459
462
}
460
463
}
461
464
0 commit comments