PageSourceSearch

https://drugnews.se/wp-content/themes/Drugnews/assets/js/nav-position.js

js drugnews.se collected 2026-10-09 05:04:06 UTC 2,126 bytes, 72 lines download raw bytes

1// Menu positioning module
2export const MenuPositioning = {
3  init() {
4    this.menuItems = document.querySelectorAll('.menu-item-has-children');
5    this.setupEventListeners();
6    this.recalculateAllSubmenus();
7  },
8
9  setupEventListeners() {
10    // Mouseover events
11    this.menuItems.forEach(item => {
12      item.addEventListener('mouseover', () => this.handleMenuHover(item));
13    });
14
15    // Resize event with debounce
16    window.addEventListener('resize', this.debounce(() => this.recalculateAllSubmenus(), 250));
17  },
18
19  handleMenuHover(menuItem) {
20    const submenu = menuItem.querySelector('.sub-menu');
21    if (submenu) {
22      this.adjustSubmenuPosition(submenu);
23    }
24  },
25
26  recalculateAllSubmenus() {
27    this.menuItems.forEach(item => {
28      const submenu = item.querySelector('.sub-menu');
29      if (submenu) {
30        submenu.classList.remove('left', 'left-nudged');
31        this.adjustSubmenuPosition(submenu);
32      }
33    });
34  },
35
36  adjustSubmenuPosition(submenu) {
37    const { rect, windowWidth, isNested, parentIsLeft, parentIsLeftNudged } = this.getSubmenuInfo(submenu);
38    
39    if (rect.right > windowWidth) {
40      submenu.classList.add(isNested ? 'left' : 'left-nudged');
41    } else if (parentIsLeft || parentIsLeftNudged) {
42      submenu.classList.add('left');
43    }
44
45    // Handle nested submenus
46    submenu.querySelectorAll('.sub-menu').forEach(nestedSubmenu => {
47      this.adjustSubmenuPosition(nestedSubmenu);
48    });
49  },
50
51  getSubmenuInfo(submenu) {
52    return {
53      rect: submenu.getBoundingClientRect(),
54      windowWidth: window.innerWidth,
55      isNested: submenu.parentElement.parentElement.classList.contains('sub-menu'),
56      parentIsLeft: submenu.parentElement.parentElement.classList.contains('left'),
57      parentIsLeftNudged: submenu.parentElement.parentElement.classList.contains('left-nudged')
58    };
59  },
60
61  debounce(func, wait) {
62    let timeout;
63    return function executedFunction(...args) {
64      const later = () => {
65        clearTimeout(timeout);
66        func(...args);
67      };
68      clearTimeout(timeout);
69      timeout = setTimeout(later, wait);
70    };
71  }
72};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.