33 * See COPYING.txt for license details.
44 */
55
6- /* eslint-disable strict */
7-
86define ( [
97 'jquery' ,
108 'matchMedia' ,
@@ -149,7 +147,7 @@ define([
149147 } else if ( ! activeCategoryLink . parent ( ) . hasClass ( 'active' ) ) {
150148 activeCategoryLink . parent ( ) . addClass ( 'active' ) ;
151149 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) ;
153151
154152 if ( classNav ) {
155153 this . _setActiveParent ( classNav [ 0 ] ) ;
@@ -186,7 +184,8 @@ define([
186184
187185 /**
188186 * 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 ('.')
190189 * If there's no dot in the last segment, it returns an empty string.
191190 *
192191 * @param {String } url - The URL from which to extract the extension.
@@ -195,6 +194,7 @@ define([
195194 */
196195 _getUrlExtension : function ( url ) {
197196 var lastSegment = url . slice ( url . lastIndexOf ( '/' ) + 1 ) ;
197+
198198 return lastSegment . includes ( '.' ) ? lastSegment . slice ( lastSegment . lastIndexOf ( '.' ) ) : '' ;
199199 } ,
200200
@@ -220,19 +220,22 @@ define([
220220 * @private
221221 */
222222 _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 ;
224228
225229 if ( ! firstCategoryUrl ) {
226230 this . _clearActiveState ( ) ;
227231 return ;
228232 }
229233
230- var categoryUrlExtension = this . _getUrlExtension ( firstCategoryUrl ) ;
231- var categoryUrl ;
232- var isProductPage = this . _isProductPage ( ) ;
234+ categoryUrlExtension = this . _getUrlExtension ( firstCategoryUrl ) ;
235+ isProductPage = this . _isProductPage ( ) ;
233236
234237 if ( isProductPage ) {
235- var currentHostname = window . location . hostname ;
238+ currentHostname = window . location . hostname ;
236239
237240 if ( document . referrer . includes ( currentHostname ) && document . referrer . endsWith ( categoryUrlExtension ) ) {
238241 categoryUrl = document . referrer . split ( '?' ) [ 0 ] ;
@@ -290,172 +293,172 @@ define([
290293 * @param {String } value
291294 */
292295 function escape ( value ) {
293- return value . replace ( / [ \- \ [\] { } ( ) * + ? . , \ \\^ $ | # \s ] / g, '\\$&' ) ;
296+ return value . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, '\\$&' ) ;
294297 }
295298
296299 if ( this . active . closest ( this . options . menus ) . attr ( 'aria-expanded' ) != 'true' ) { //eslint-disable-line eqeqeq
297300
298301 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 ;
302305
303- case $ . ui . keyCode . PAGE_DOWN :
304- this . nextPage ( event ) ;
305- break ;
306+ case $ . ui . keyCode . PAGE_DOWN :
307+ this . nextPage ( event ) ;
308+ break ;
306309
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 ;
310313
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 ;
314317
315- case $ . ui . keyCode . UP :
316- this . previous ( event ) ;
317- break ;
318+ case $ . ui . keyCode . UP :
319+ this . previous ( event ) ;
320+ break ;
318321
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+ }
348357
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 ;
354365
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 ) ;
355370 regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
356371 match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
357372 return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
358373 } ) ;
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+ }
372375
373- if ( match . length ) {
374- this . focus ( event , match ) ;
376+ if ( match . length ) {
377+ this . focus ( event , match ) ;
375378
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 ( ) {
382382 delete this . previousFilter ;
383- }
383+ } , 1000 ) ;
384384 } else {
385385 delete this . previousFilter ;
386386 }
387+ } else {
388+ delete this . previousFilter ;
389+ }
387390 }
388391 } else {
389392 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 ;
397396
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 ;
418400
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+ }
420429
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 ;
426437
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 ) ;
427442 regex = new RegExp ( '^' + escape ( character ) , 'i' ) ;
428443 match = this . activeMenu . children ( '.ui-menu-item' ) . filter ( function ( ) {
429444 return regex . test ( $ ( this ) . children ( 'a' ) . text ( ) ) ;
430445 } ) ;
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+ }
444447
445- if ( match . length ) {
446- this . focus ( event , match ) ;
448+ if ( match . length ) {
449+ this . focus ( event , match ) ;
447450
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 ( ) {
454454 delete this . previousFilter ;
455- }
455+ } , 1000 ) ;
456456 } else {
457457 delete this . previousFilter ;
458458 }
459+ } else {
460+ delete this . previousFilter ;
461+ }
459462 }
460463 }
461464
0 commit comments