PageSourceSearch

https://www.prestonmazda.com/resources/components/navigation/hambu….9.1438c351f0114d50b33068f234773d29b19a5961

js prestonmazda.com collected 2026-10-04 13:29:59 UTC 14,754 bytes, 308 lines download raw bytes

1"use strict";
2var _a;
3var HamburgerNavigation = (function () {
4    function HamburgerNavigation() {
5        this.desktopBreakpoint = 1200;
6        this._enableMobile = function () {
7            document
8                .querySelectorAll(".hamburger-navbar .hideOnMobile")
9                .forEach(function (elem) { return elem.remove(); });
10        };
11        this._enableDesktop = function () {
12            document
13                .querySelectorAll(".hamburger-navbar .hideOnDesktop")
14                .forEach(function (elem) { return elem.remove(); });
15            var filteredElements = document.querySelectorAll(".hamburger-navbar .hamburger-horizontalItem");
16            Array.from(filteredElements)
17                .slice(4)
18                .forEach(function (elem) { return elem.remove(); });
19        };
20        this.hamburgerDropdownContainer = document.getElementById("hamburger-dropdownContainer");
21        this.hamburger = document.getElementById("hamburger-icon");
22        this.dropdownMenu = document.getElementById("hamburger-dropdownMenu");
23        this.horizontalMenu = document.getElementById("hamburger-horizontalMenu");
24        this.desktopBreakpoint = 1200;
25        this.bouncedToggleMenu = this.toggleMenu.bind(this);
26        this.bouncedHandleResize = this.handleResize.bind(this);
27        this.bouncedCloseHamburgerMenu = this.closeHamburgerMenu.bind(this);
28        this.bouncedHandleHorizontalOpenMenu =
29            this.handleHorizontalOpenMenu.bind(this);
30        this.bouncedHandleVerticalSubmenuClick =
31            this.handleVeriticalSubmenuClick.bind(this);
32        this.bouncedHandleLinkClick = this.handleLinkClick.bind(this);
33        this.bouncedHandleHorizontalLinkClick =
34            this.handleHorizontalLinkClick.bind(this);
35        this.initialize();
36    }
37    HamburgerNavigation.prototype.destroy = function () {
38        this.removeEventListeners();
39    };
40    HamburgerNavigation.prototype.initialize = function () {
41        if (!this.hamburger || !this.dropdownMenu)
42            return;
43        this._enableMenuForDeviceType();
44        this.removeBootstrapClasses();
45        this.setupEventListeners();
46    };
47    HamburgerNavigation.prototype._enableMenuForDeviceType = function () {
48        if (window.matchMedia("(max-width: 991px)").matches) {
49            this._enableMobile();
50        }
51        else {
52            this._enableDesktop();
53        }
54    };
55    HamburgerNavigation.prototype.removeBootstrapClasses = function () {
56        document
57            .querySelectorAll(".hamburger-horizontalItem > ul")
58            .forEach(function (ul) {
59            if (ul.classList.contains("dropdown-menu")) {
60                ul.classList.remove("dropdown-menu");
61            }
62        });
63        document.querySelectorAll(".hamburger-verticalItem > ul").forEach(function (ul) {
64            if (ul.classList.contains("dropdown-menu")) {
65                ul.classList.remove("dropdown-menu");
66            }
67        });
68    };
69    HamburgerNavigation.prototype.setupEventListeners = function () {
70        var _a;
71        (_a = this.hamburger) === null || _a === void 0 ? void 0 : _a.addEventListener("click", this.bouncedToggleMenu);
72        this.setupHorizontalMenuHover();
73        this.setupHorizontalLinkClickHandlers();
74        this.setupVerticalMenuClickHandlers();
75        this.setupLinkClickHandlers();
76        this.setupHamburgerDropdownContainerFocusoutHandler();
77        window.addEventListener("resize", this.bouncedHandleResize);
78    };
79    HamburgerNavigation.prototype.removeEventListeners = function () {
80        var _this = this;
81        var _a, _b;
82        (_a = this.hamburger) === null || _a === void 0 ? void 0 : _a.removeEventListener("click", this.bouncedToggleMenu);
83        window.removeEventListener("resize", this.bouncedHandleResize);
84        (_b = this.horizontalMenu) === null || _b === void 0 ? void 0 : _b.removeEventListener("mouseenter", this.bouncedCloseHamburgerMenu);
85        document
86            .querySelectorAll(".hamburger-verticalItem.hamburger-hasChildren > .hamburger-verticalLink")
87            .forEach(function (link) {
88            link.removeEventListener("click", _this.bouncedHandleVerticalSubmenuClick);
89        });
90        document.querySelectorAll(".hamburger-verticalMenu a").forEach(function (item) {
91            item.removeEventListener("click", _this.bouncedHandleLinkClick);
92        });
93        document
94            .querySelectorAll(".hamburger-horizontalItem > ul a")
95            .forEach(function (link) {
96            link.removeEventListener("click", _this.bouncedHandleHorizontalLinkClick);
97        });
98    };
99    HamburgerNavigation.prototype.toggleMenu = function () {
100        var links = this.dropdownMenu.querySelectorAll(".hamburger-verticalItem > .hamburger-verticalLink");
101        if (!this.hamburger || !this.dropdownMenu)
102            return;
103        var willOpen = !this.dropdownMenu.classList.contains("active");
104        if (!willOpen) {
105            this.closeAllSubmenus();
106            links.forEach(function (link) {
107                link.setAttribute("tabindex", "-1");
108            });
109        }
110        else {
111            links.forEach(function (link) {
112                link.setAttribute("tabindex", "0");
113            });
114            this.setDropdownMaxHeight(this.dropdownMenu);
115        }
116        this.dropdownMenu.classList.toggle("active");
117        this.hamburger.classList.toggle("active");
118        this.hamburger.setAttribute("aria-expanded", String(willOpen));
119        this.setBodyScrollLock(willOpen);
120    };
121    HamburgerNavigation.prototype.setDropdownMaxHeight = function (el) {
122        if (!el)
123            return;
124        var available = window.innerHeight - el.getBoundingClientRect().top;
125        el.style.setProperty("--hamburger-dropdown-max-height", "".concat(Math.max(available, 0), "px"));
126    };
127    HamburgerNavigation.prototype.setBodyScrollLock = function (locked) {
128        document.body.classList.toggle("hamburger-menu-open", locked);
129    };
130    HamburgerNavigation.prototype.closeHamburgerMenu = function () {
131        if (!this.hamburger || !this.dropdownMenu)
132            return;
133        if (this.dropdownMenu.classList.contains("active")) {
134            this.dropdownMenu.classList.remove("active");
135            this.hamburger.classList.remove("active");
136            this.hamburger.setAttribute("aria-expanded", "false");
137            this.closeAllSubmenus();
138            this.setBodyScrollLock(false);
139        }
140    };
141    HamburgerNavigation.prototype.closeAllSubmenus = function () {
142        document
143            .querySelectorAll(".hamburger-verticalItem > ul.active")
144            .forEach(function (sub) {
145            sub.classList.remove("active", "open");
146            sub.querySelectorAll("li > a").forEach(function (subLink) {
147                subLink.setAttribute("tabindex", "-1");
148            });
149        });
150        document
151            .querySelectorAll(".hamburger-verticalItem.active")
152            .forEach(function (sub) {
153            var _a;
154            sub.classList.remove("active", "open");
155            (_a = sub
156                .querySelector(":scope > .hamburger-verticalLink")) === null || _a === void 0 ? void 0 : _a.setAttribute("aria-expanded", "false");
157        });
158    };
159    HamburgerNavigation.prototype.setupHorizontalMenuHover = function () {
160        var _this = this;
161        if (!this.horizontalMenu)
162            return;
163        this.horizontalMenu.addEventListener("mouseenter", this.bouncedCloseHamburgerMenu);
164        document.querySelectorAll(".hamburger-horizontalItem").forEach(function (item) {
165            item.addEventListener("mouseenter", _this.bouncedCloseHamburgerMenu);
166        });
167        document.querySelectorAll(".hamburger-horizontalLink").forEach(function (link) {
168            link.addEventListener("mouseenter", _this.bouncedCloseHamburgerMenu);
169        });
170        var hamburgerHorizontalItemHasChildren = document.querySelectorAll(".hamburger-horizontalItem.hamburger-hasChildren");
171        hamburgerHorizontalItemHasChildren.forEach(function (link) {
172            link.removeEventListener("mouseenter", _this.bouncedHandleHorizontalOpenMenu);
173            link.removeEventListener("mouseleave", _this.bouncedHandleHorizontalOpenMenu);
174            link.addEventListener("mouseenter", _this.bouncedHandleHorizontalOpenMenu);
175            link.addEventListener("mouseleave", _this.bouncedHandleHorizontalOpenMenu);
176        });
177    };
178    HamburgerNavigation.prototype.setupHorizontalLinkClickHandlers = function () {
179        var _this = this;
180        document
181            .querySelectorAll(".hamburger-horizontalItem > ul a")
182            .forEach(function (link) {
183            link.removeEventListener("click", _this.bouncedHandleHorizontalLinkClick);
184            link.addEventListener("click", _this.bouncedHandleHorizontalLinkClick);
185        });
186    };
187    HamburgerNavigation.prototype.handleHorizontalLinkClick = function (e) {
188        var _a;
189        var target = e.currentTarget;
190        var parentItem = target.closest(".hamburger-horizontalItem.hamburger-hasChildren");
191        parentItem === null || parentItem === void 0 ? void 0 : parentItem.classList.remove("open");
192        (_a = parentItem === null || parentItem === void 0 ? void 0 : parentItem.querySelector(":scope > .hamburger-horizontalLink")) === null || _a === void 0 ? void 0 : _a.setAttribute("aria-expanded", "false");
193        target.blur();
194    };
195    HamburgerNavigation.prototype.setupVerticalMenuClickHandlers = function () {
196        var _this = this;
197        document
198            .querySelectorAll(".hamburger-verticalItem.hamburger-hasChildren > .hamburger-verticalLink")
199            .forEach(function (link) {
200            link.removeEventListener("click", _this.bouncedHandleVerticalSubmenuClick);
201            link.addEventListener("click", _this.bouncedHandleVerticalSubmenuClick);
202        });
203    };
204    HamburgerNavigation.prototype.handleHorizontalOpenMenu = function (e) {
205        e.preventDefault();
206        e.stopPropagation();
207        var target = e.currentTarget;
208        if (!(target === null || target === void 0 ? void 0 : target.classList.contains("hamburger-hasChildren")))
209            return;
210        var isEntering = e.type === "mouseenter";
211        var link = target.querySelector(":scope > .hamburger-horizontalLink");
212        var submenu = target.querySelector(":scope > ul");
213        if (isEntering) {
214            target.classList.add("open");
215            link === null || link === void 0 ? void 0 : link.setAttribute("aria-expanded", "true");
216            this.setDropdownMaxHeight(submenu);
217        }
218        else {
219            target.classList.remove("open");
220            link === null || link === void 0 ? void 0 : link.setAttribute("aria-expanded", "false");
221        }
222    };
223    HamburgerNavigation.prototype.handleVeriticalSubmenuClick = function (e) {
224        e.preventDefault();
225        e.stopPropagation();
226        var target = e.currentTarget;
227        var parentLi = target.closest(".hamburger-verticalItem");
228        if (!parentLi)
229            return;
230        var submenu = parentLi.querySelector("ul");
231        var links = submenu.querySelectorAll("li > a");
232        if (submenu) {
233            var isActive = submenu.classList.contains("active");
234            this.closeAllSubmenus();
235            if (!isActive) {
236                submenu.classList.add("active", "open");
237                parentLi.classList.add("active", "open");
238                target.setAttribute("aria-expanded", "true");
239                links.forEach(function (link) {
240                    link.setAttribute("tabindex", "0");
241                });
242            }
243        }
244    };
245    HamburgerNavigation.prototype.setupLinkClickHandlers = function () {
246        var _this = this;
247        document.querySelectorAll(".hamburger-verticalMenu a").forEach(function (link) {
248            link.removeEventListener("click", _this.bouncedHandleLinkClick);
249            link.addEventListener("click", _this.bouncedHandleLinkClick);
250        });
251    };
252    HamburgerNavigation.prototype.setupHamburgerDropdownContainerFocusoutHandler = function () {
253        var _this = this;
254        var _a;
255        var links = this.dropdownMenu.querySelectorAll(".hamburger-verticalItem > .hamburger-verticalLink");
256        (_a = this.hamburgerDropdownContainer) === null || _a === void 0 ? void 0 : _a.addEventListener("focusout", function () {
257            requestAnimationFrame(function () {
258                var _a;
259                if (!_this.hamburgerDropdownContainer.contains(document.activeElement)) {
260                    _this.closeAllSubmenus();
261                    (_a = _this.dropdownMenu) === null || _a === void 0 ? void 0 : _a.classList.remove("active");
262                    _this.hamburger.classList.remove("active");
263                    links.forEach(function (link) {
264                        link.setAttribute("tabindex", "-1");
265                    });
266                    _this.setBodyScrollLock(false);
267                }
268            });
269        });
270    };
271    HamburgerNavigation.prototype.handleLinkClick = function (e) {
272        var _a, _b;
273        var target = e.currentTarget;
274        var parentLi = target.closest("li");
275        if (parentLi === null || parentLi === void 0 ? void 0 : parentLi.classList.contains("hamburger-hasChildren")) {
276            e.preventDefault();
277            e.stopPropagation();
278            return;
279        }
280        (_a = this.dropdownMenu) === null || _a === void 0 ? void 0 : _a.classList.remove("active", "open");
281        (_b = this.hamburger) === null || _b === void 0 ? void 0 : _b.classList.remove("active", "open");
282        this.closeAllSubmenus();
283        this.setBodyScrollLock(false);
284    };
285    HamburgerNavigation.prototype.handleResize = function () {
286        var _a, _b;
287        this.closeAllSubmenus();
288        if ((_a = this.dropdownMenu) === null || _a === void 0 ? void 0 : _a.classList.contains("active")) {
289            this.dropdownMenu.classList.remove("active", "open");
290            (_b = this.hamburger) === null || _b === void 0 ? void 0 : _b.classList.remove("active", "open");
291            this.setBodyScrollLock(false);
292        }
293        this.setupVerticalMenuClickHandlers();
294        this.setupLinkClickHandlers();
295        this.setupHorizontalLinkClickHandlers();
296        this.removeBootstrapClasses();
297    };
298    return HamburgerNavigation;
299}());
300if (typeof window !== "undefined") {
301    window.HamburgerNavigation = HamburgerNavigation;
302    if ((_a = window.DoUtility) === null || _a === void 0 ? void 0 : _a.SelfInstantiateOnLoad) {
303        window.DoUtility.SelfInstantiateOnLoad(HamburgerNavigation);
304    }
305}
306if (typeof module !== "undefined" && module.exports) {
307    module.exports = { HamburgerNavigation: HamburgerNavigation };
308}

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.