Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/static/js/frontend/entry-points/menus.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + import ctEvents from 'ct-events'
2 + import { getCurrentScreen } from '../helpers/current-screen'
3 +
4 + const loadMenuEntry = () => import('../header/menu')
5 +
6 + const onlyWithSubmenus = (menu) =>
7 + menu.querySelector('.menu-item-has-children') ||
8 + menu.querySelector('.page_item_has_children')
9 +
10 + export const menuEntryPoints = [
11 + {
12 + els: () =>
13 + [
14 + ...document.querySelectorAll(
15 + 'header [data-device="desktop"] [data-id*="menu"] > .menu'
16 + ),
17 + ...document.querySelectorAll('.ct-header-account > ul'),
18 + ].filter((menu) => onlyWithSubmenus(menu)),
19 + load: () => import('../header/sub-menu-open-logic'),
20 + events: ['ct:header:refresh-menu-submenus'],
21 + },
22 +
23 + {
24 + els: () => [
25 + ...document.querySelectorAll(
26 + 'header [data-device="desktop"] [data-id^="menu"][data-responsive]'
27 + ),
28 + ],
29 + load: () => import('../header/responsive-desktop-menu'),
30 + events: ['ct:header:responsive-menu:refresh'],
31 + condition: () => {
32 + if (getCurrentScreen() !== 'desktop') {
33 + return false
34 + }
35 +
36 + return [
37 + ...document.querySelectorAll(
38 + 'header [data-device="desktop"] [data-id^="menu"][data-responsive]'
39 + ),
40 + ].some((menu) => {
41 + if (!menu.firstElementChild) {
42 + return false
43 + }
44 +
45 + const menuRect = menu.firstElementChild.getBoundingClientRect()
46 +
47 + const allEls = [
48 + ...menu
49 + .closest('[data-row]')
50 + .querySelectorAll('[data-items] > [data-id]'),
51 + ]
52 + .filter((el) => el !== menu)
53 + .filter((el) => {
54 + const elRect = el.getBoundingClientRect()
55 +
56 + return [
57 + menuRect,
58 +
59 + ...[...menu.firstElementChild.children].map(
60 + (child) => child.getBoundingClientRect()
61 + ),
62 + ].some((rect) => {
63 + const intersectsLeftEdge =
64 + elRect.left < rect.left &&
65 + elRect.right > rect.left
66 +
67 + const intersectsRightEdge =
68 + elRect.right > rect.right &&
69 + elRect.left < rect.right
70 +
71 + const isInside =
72 + elRect.left > rect.left &&
73 + elRect.right < rect.right
74 +
75 + return (
76 + intersectsLeftEdge ||
77 + intersectsRightEdge ||
78 + isInside
79 + )
80 + })
81 + })
82 +
83 + const parentRect = menu.parentElement.getBoundingClientRect()
84 +
85 + const fitsLeftSide = menuRect.left > parentRect.left
86 + const fitsRightSide = menuRect.right < parentRect.right
87 +
88 + const fits =
89 + fitsLeftSide && fitsRightSide && allEls.length === 0
90 +
91 + if (fits) {
92 + menu.dataset.responsive = 'yes'
93 + }
94 +
95 + return !fits
96 + })
97 + },
98 + },
99 + ]
100 +