@@ -448,40 +448,25 @@ define(
448
448
* Custom widgets can be added to this object like [attribute]: function(facet, templates)
449
449
* Function must return an array [<widget name>: string, <widget options>: object]
450
450
**/
451
- var customAttributeFacet = {
451
+ const customAttributeFacet = {
452
452
categories : function ( facet , templates ) {
453
- var hierarchical_levels = [ ] ;
454
- for ( var l = 0 ; l < 10 ; l ++ ) {
453
+ const hierarchical_levels = [ ] ;
454
+ for ( let l = 0 ; l < 10 ; l ++ ) {
455
455
hierarchical_levels . push ( 'categories.level' + l . toString ( ) ) ;
456
456
}
457
457
458
-
459
- //return array of items starting from root based on category
460
- const findRoot = ( items ) => {
461
- const root = items . find ( element => algoliaConfig . request . path . startsWith ( element . value ) ) ;
462
-
463
- if ( ! root ) {
464
- return items ;
465
- }
466
- if ( ! root . data ) {
467
- return [ ] ;
468
- }
469
-
470
- return findRoot ( root . data ) ;
471
-
472
- } ;
473
-
474
- var hierarchicalMenuParams = {
458
+ const hierarchicalMenuParams = {
475
459
container : facet . wrapper . appendChild ( createISWidgetContainer ( facet . attribute ) ) ,
476
460
attributes : hierarchical_levels ,
477
461
separator : algoliaConfig . instant . categorySeparator ,
478
462
templates : templates ,
479
463
showParentLevel : true ,
480
464
limit : algoliaConfig . maxValuesPerFacet ,
465
+ rootPath : algoliaConfig . request . path ,
481
466
sortBy : [ 'name:asc' ] ,
482
467
transformItems ( items ) {
483
468
return ( algoliaConfig . isCategoryPage )
484
- ? findRoot ( items ) . map (
469
+ ? items . map (
485
470
item => {
486
471
return {
487
472
...item ,
0 commit comments