@ecl/mega-menu 5.0.0-alpha.10 → 5.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -5
- package/mega-menu-featured-item.html.twig +7 -0
- package/mega-menu-item.html.twig +64 -50
- package/mega-menu.html.twig +23 -7
- package/mega-menu.js +98 -38
- package/mega-menu.scss +301 -64
- package/package.json +7 -7
package/mega-menu.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable class-methods-use-this */
|
|
2
|
-
|
|
3
1
|
import { queryOne, queryAll } from '@ecl/dom-utils';
|
|
4
2
|
import EventManager from '@ecl/event-manager';
|
|
5
3
|
import { createFocusTrap } from 'focus-trap';
|
|
@@ -507,6 +505,12 @@ export class MegaMenu {
|
|
|
507
505
|
menu.style.height = '';
|
|
508
506
|
});
|
|
509
507
|
|
|
508
|
+
if (subLists.length) {
|
|
509
|
+
subLists.forEach((list) => {
|
|
510
|
+
list.style.height = '';
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
510
514
|
// Reset top position and height of the wrappers
|
|
511
515
|
if (this.wrappers) {
|
|
512
516
|
this.wrappers.forEach((wrapper) => {
|
|
@@ -635,12 +639,12 @@ export class MegaMenu {
|
|
|
635
639
|
screenWidth > this.breakpointL ? 'desktop' : 'mobile',
|
|
636
640
|
);
|
|
637
641
|
}
|
|
638
|
-
if (this.prevScreenWidth
|
|
642
|
+
if (this.prevScreenWidth >= 1140 && screenWidth >= 996) {
|
|
639
643
|
this.resetStyles('desktop', true);
|
|
640
644
|
}
|
|
641
645
|
}
|
|
642
646
|
this.isDesktop = this.useDesktopDisplay();
|
|
643
|
-
this.isLarge = window.innerWidth
|
|
647
|
+
this.isLarge = window.innerWidth >= 1140;
|
|
644
648
|
// Update previous screen width
|
|
645
649
|
this.prevScreenWidth = screenWidth;
|
|
646
650
|
this.element.classList.remove('ecl-mega-menu--forced-mobile');
|
|
@@ -693,9 +697,11 @@ export class MegaMenu {
|
|
|
693
697
|
const heights = [];
|
|
694
698
|
let height = 0;
|
|
695
699
|
let featuredPanel = null;
|
|
700
|
+
let featuredPanelFirst = null;
|
|
696
701
|
let itemsHeight = 0;
|
|
697
702
|
let subItemsHeight = 0;
|
|
698
703
|
let featuredHeight = 0;
|
|
704
|
+
let featuredFirstHeight = 0;
|
|
699
705
|
|
|
700
706
|
if (infoPanel) {
|
|
701
707
|
infoPanel.style.height = '';
|
|
@@ -707,6 +713,7 @@ export class MegaMenu {
|
|
|
707
713
|
itemsHeight = infoPanelHeight;
|
|
708
714
|
subItemsHeight = infoPanelHeight;
|
|
709
715
|
featuredHeight = infoPanelHeight;
|
|
716
|
+
featuredFirstHeight = infoPanelHeight;
|
|
710
717
|
}
|
|
711
718
|
|
|
712
719
|
if (mainPanel) {
|
|
@@ -737,6 +744,25 @@ export class MegaMenu {
|
|
|
737
744
|
heights.push(itemsHeight);
|
|
738
745
|
}
|
|
739
746
|
}
|
|
747
|
+
featuredPanelFirst = queryOne(
|
|
748
|
+
':scope > .ecl-mega-menu__featured',
|
|
749
|
+
mainPanel,
|
|
750
|
+
);
|
|
751
|
+
if (featuredPanelFirst) {
|
|
752
|
+
// Get the elements inside the scrollable container and calculate their heights.
|
|
753
|
+
Array.from(featuredPanelFirst.firstElementChild.children).forEach(
|
|
754
|
+
(child) => {
|
|
755
|
+
const elStyle = window.getComputedStyle(child);
|
|
756
|
+
const marginHeight =
|
|
757
|
+
parseFloat(elStyle.marginTop) +
|
|
758
|
+
parseFloat(elStyle.marginBottom);
|
|
759
|
+
featuredFirstHeight += child.offsetHeight + marginHeight;
|
|
760
|
+
},
|
|
761
|
+
);
|
|
762
|
+
// Add 8px to the featured panel height to prevent scrollbar
|
|
763
|
+
featuredFirstHeight += 8;
|
|
764
|
+
heights.push(featuredFirstHeight);
|
|
765
|
+
}
|
|
740
766
|
}
|
|
741
767
|
|
|
742
768
|
if (secondPanel) {
|
|
@@ -797,6 +823,11 @@ export class MegaMenu {
|
|
|
797
823
|
} else if (secondPanel && this.isDesktop) {
|
|
798
824
|
secondPanel.style.height = `${height - infoPanelHeight}px`;
|
|
799
825
|
}
|
|
826
|
+
if (featuredPanelFirst && this.isLarge) {
|
|
827
|
+
featuredPanelFirst.style.height = `${height}px`;
|
|
828
|
+
} else if (featuredPanelFirst && this.isDesktop) {
|
|
829
|
+
featuredPanelFirst.style.height = `${height - infoPanelHeight}px`;
|
|
830
|
+
}
|
|
800
831
|
if (featuredPanel && this.isLarge) {
|
|
801
832
|
featuredPanel.style.height = `${height}px`;
|
|
802
833
|
} else if (featuredPanel && this.isDesktop) {
|
|
@@ -836,46 +867,63 @@ export class MegaMenu {
|
|
|
836
867
|
const item = queryOne('.ecl-mega-menu__item--expanded', this.element);
|
|
837
868
|
|
|
838
869
|
if (item) {
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
870
|
+
const hasFeatured = queryOne(
|
|
871
|
+
'.ecl-mega-menu__mega--has-featured',
|
|
872
|
+
item,
|
|
873
|
+
);
|
|
874
|
+
const info = queryOne('.ecl-mega-menu__info', item);
|
|
875
|
+
if (info && this.openPanel.num === 1) {
|
|
876
|
+
const bottomRect = info.getBoundingClientRect();
|
|
877
|
+
const bottomInfo = bottomRect.bottom;
|
|
878
|
+
availableHeight = window.innerHeight - bottomInfo - 16;
|
|
879
|
+
}
|
|
880
|
+
if (hasFeatured) {
|
|
881
|
+
const hasFeaturedRect = hasFeatured.getBoundingClientRect();
|
|
882
|
+
const hasFeaturedTop = hasFeaturedRect.top;
|
|
883
|
+
availableHeight =
|
|
884
|
+
availableHeight || window.innerHeight - hasFeaturedTop;
|
|
885
|
+
hasFeatured.style.height = `${availableHeight}px`;
|
|
886
|
+
} else {
|
|
887
|
+
const subList = queryOne('.ecl-mega-menu__sublist', item);
|
|
888
|
+
if (subList && this.openPanel.num === 1) {
|
|
889
|
+
console.log('dovrei...');
|
|
890
|
+
const subListRect = subList.getBoundingClientRect();
|
|
891
|
+
const subListRectTop = subListRect.top;
|
|
846
892
|
subList.classList.add('ecl-mega-menu__sublist--scrollable');
|
|
893
|
+
availableHeight =
|
|
894
|
+
availableHeight || window.innerHeight - subListRectTop;
|
|
847
895
|
subList.style.height = `${availableHeight}px`;
|
|
896
|
+
} else if (subList) {
|
|
897
|
+
subList.classList.remove('ecl-mega-menu__sublist--scrollable');
|
|
898
|
+
subList.style.height = '';
|
|
848
899
|
}
|
|
849
|
-
} else if (subList) {
|
|
850
|
-
subList.classList.remove('ecl-mega-menu__sublist--scrollable');
|
|
851
|
-
subList.style.height = '';
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
900
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
901
|
+
if (this.openPanel.num === 2) {
|
|
902
|
+
const subItem = queryOne(
|
|
903
|
+
'.ecl-mega-menu__subitem--expanded',
|
|
904
|
+
this.element,
|
|
905
|
+
);
|
|
906
|
+
if (subItem) {
|
|
907
|
+
const subMega = queryOne(
|
|
908
|
+
'.ecl-mega-menu__mega--level-2',
|
|
909
|
+
subItem,
|
|
910
|
+
);
|
|
911
|
+
if (subMega) {
|
|
912
|
+
const subMegaRect = subMega.getBoundingClientRect();
|
|
913
|
+
const subMegaTop = subMegaRect.top;
|
|
914
|
+
availableHeight = window.innerHeight - subMegaTop;
|
|
915
|
+
subMega.style.height = `${availableHeight}px`;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (this.wrappers) {
|
|
920
|
+
this.wrappers.forEach((wrapper) => {
|
|
921
|
+
wrapper.style.top = '';
|
|
922
|
+
wrapper.style.height = '';
|
|
923
|
+
});
|
|
870
924
|
}
|
|
871
925
|
}
|
|
872
926
|
}
|
|
873
|
-
if (this.wrappers) {
|
|
874
|
-
this.wrappers.forEach((wrapper) => {
|
|
875
|
-
wrapper.style.top = '';
|
|
876
|
-
wrapper.style.height = '';
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
927
|
}
|
|
880
928
|
}, 0);
|
|
881
929
|
} else {
|
|
@@ -1422,6 +1470,16 @@ export class MegaMenu {
|
|
|
1422
1470
|
item.classList.add('ecl-mega-menu__subitem--expanded');
|
|
1423
1471
|
}
|
|
1424
1472
|
item.classList.add('ecl-mega-menu__subitem--current');
|
|
1473
|
+
const hasFeatured = queryOne('.ecl-mega-menu__featured', item);
|
|
1474
|
+
if (hasFeatured) {
|
|
1475
|
+
this.element.classList.add(
|
|
1476
|
+
'ecl-mega-menu--has-secondary-featured',
|
|
1477
|
+
);
|
|
1478
|
+
} else {
|
|
1479
|
+
this.element.classList.remove(
|
|
1480
|
+
'ecl-mega-menu--has-secondary-featured',
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1425
1483
|
this.backItemLevel2 = item;
|
|
1426
1484
|
} else {
|
|
1427
1485
|
if (itemLink && itemLink.hasAttribute('aria-expanded')) {
|
|
@@ -1463,6 +1521,7 @@ export class MegaMenu {
|
|
|
1463
1521
|
|
|
1464
1522
|
case 'collapse':
|
|
1465
1523
|
this.element.classList.remove('ecl-mega-menu--two-panels');
|
|
1524
|
+
this.element.classList.remove('ecl-mega-menu--has-secondary-featured');
|
|
1466
1525
|
this.openPanel = { num: 1 };
|
|
1467
1526
|
// eslint-disable-next-line no-case-declarations
|
|
1468
1527
|
const itemLink = queryOne(this.subLinkSelector, menuItem);
|
|
@@ -1560,6 +1619,7 @@ export class MegaMenu {
|
|
|
1560
1619
|
* @fires MegaMenu#onFocusTrapToggle
|
|
1561
1620
|
*/
|
|
1562
1621
|
closeOpenDropdown(esc = false) {
|
|
1622
|
+
this.element.classList.remove('ecl-mega-menu--has-secondary-featured');
|
|
1563
1623
|
if (this.header) {
|
|
1564
1624
|
this.header.classList.remove(
|
|
1565
1625
|
'ecl-site-header--open-menu',
|
|
@@ -1625,7 +1685,7 @@ export class MegaMenu {
|
|
|
1625
1685
|
sublists.forEach((sublist) => {
|
|
1626
1686
|
sublist.classList.remove(
|
|
1627
1687
|
'ecl-mega-menu__sublist--no-border',
|
|
1628
|
-
'
|
|
1688
|
+
'ecl-mega-menu__sublist--scrollable',
|
|
1629
1689
|
);
|
|
1630
1690
|
});
|
|
1631
1691
|
}
|