PageSourceSearch

https://learningmate.com/wp-content/plugins/megamenu/js/maxmegamenu.js?ver=3.7

js learningmate.com collected 2026-10-01 11:45:57 UTC 39,897 bytes, 903 lines download raw bytes

1/*jslint browser: true, white: true, this: true, long: true */
2/*global console,jQuery,megamenu,window,navigator*/
3
4/*! Max Mega Menu jQuery Plugin */
5(function ( $ ) {
6    "use strict";
7
8    $.maxmegamenu = function(menu, options) {
9        var plugin = this;
10        var $menu = $(menu);
11        var $wrap = $(menu).parent();
12        var $toggle_bar = $menu.siblings(".mega-menu-toggle");
13        var html_body_class_timeout;
14
15        var defaults = {
16            event: $menu.attr("data-event"),
17            effect: $menu.attr("data-effect"),
18            effect_speed: parseInt($menu.attr("data-effect-speed")),
19            effect_mobile: $menu.attr("data-effect-mobile"),
20            effect_speed_mobile: parseInt($menu.attr("data-effect-speed-mobile")),
21            panel_width: $menu.attr("data-panel-width"),
22            panel_inner_width: $menu.attr("data-panel-inner-width"),
23            mobile_force_width: $menu.attr("data-mobile-force-width"),
24            mobile_overlay: $menu.attr("data-mobile-overlay"),
25            mobile_state: $menu.attr("data-mobile-state"),
26            mobile_direction: $menu.attr("data-mobile-direction"),
27            second_click: $menu.attr("data-second-click"),
28            vertical_behaviour: $menu.attr("data-vertical-behaviour"),
29            document_click: $menu.attr("data-document-click"),
30            breakpoint: $menu.attr("data-breakpoint"),
31            unbind_events: $menu.attr("data-unbind"),
32            hover_intent_timeout: $menu.attr("data-hover-intent-timeout"),
33            hover_intent_interval: $menu.attr("data-hover-intent-interval")
34        };
35
36        plugin.settings = {};
37
38        var items_with_submenus = $("li.mega-menu-megamenu.mega-menu-item-has-children," +
39                                    "li.mega-menu-flyout.mega-menu-item-has-children," +
40                                    "li.mega-menu-tabbed > ul.mega-sub-menu > li.mega-menu-item-has-children," +
41                                    "li.mega-menu-flyout li.mega-menu-item-has-children", $menu);
42
43        var collapse_children_parents = $("li.mega-menu-megamenu li.mega-menu-item-has-children.mega-collapse-children > a.mega-menu-link", $menu);
44
45        plugin.addAnimatingClass = function(element) {
46            if (plugin.settings.effect === "disabled") {
47                return;
48            }
49
50            $(".mega-animating").removeClass("mega-animating");
51
52            var timeout = plugin.settings.effect_speed + parseInt(plugin.settings.hover_intent_timeout, 10);
53
54            element.addClass("mega-animating");
55
56            setTimeout(function() {
57               element.removeClass("mega-animating");
58            }, timeout );
59        };
60
61        plugin.hideAllPanels = function() {
62            $(".mega-toggle-on > a.mega-menu-link", $menu).each(function() {
63                plugin.hidePanel($(this), false);
64            });
65        };
66
67        plugin.expandMobileSubMenus = function() {
68            if (plugin.settings.mobile_direction !== 'vertical') {
69                return;
70            }
71            
72            $(".mega-menu-item-has-children.mega-expand-on-mobile > a.mega-menu-link", $menu).each(function() {
73                plugin.showPanel($(this), true);
74            });
75
76            if ( plugin.settings.mobile_state == 'expand_all' ) {
77                $(".mega-menu-item-has-children:not(.mega-toggle-on) > a.mega-menu-link", $menu).each(function() {
78                    plugin.showPanel($(this), true);
79                });
80            }
81
82            if ( plugin.settings.mobile_state == 'expand_active' ) {
83                const activeItemSelectors = [
84                    "li.mega-current-menu-ancestor.mega-menu-item-has-children > a.mega-menu-link",
85                    "li.mega-current-menu-item.mega-menu-item-has-children > a.mega-menu-link",
86                    "li.mega-current-menu-parent.mega-menu-item-has-children > a.mega-menu-link",
87                    "li.mega-current_page_ancestor.mega-menu-item-has-children > a.mega-menu-link",
88                    "li.mega-current_page_item.mega-menu-item-has-children > a.mega-menu-link"
89                ];
90
91                $menu.find(activeItemSelectors.join(', ')).each(function() {
92                    plugin.showPanel($(this), true);
93                });
94            }
95        }
96
97        plugin.hideSiblingPanels = function(anchor, immediate) {
98            anchor.parent().parent().find(".mega-toggle-on").children("a.mega-menu-link").each(function() { // all open children of open siblings
99                plugin.hidePanel($(this), immediate);
100            });
101        };
102
103        plugin.isDesktopView = function() {
104            var width = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
105            return width > plugin.settings.breakpoint;
106        };
107
108        plugin.isMobileView = function() {
109            return !plugin.isDesktopView();
110        };
111
112        plugin.showPanel = function(anchor, immediate) {
113            if ( $.isNumeric(anchor) ) {
114                anchor = $("li.mega-menu-item-" + anchor, $menu).find("a.mega-menu-link").first();
115            } else if ( anchor.is("li.mega-menu-item") ) {
116                anchor = anchor.find("a.mega-menu-link").first();
117            }
118
119            anchor.parent().triggerHandler("before_open_panel");
120
121            anchor.parent().find("[aria-expanded]").first().attr("aria-expanded", "true");
122
123            $(".mega-animating").removeClass("mega-animating");
124
125            if (plugin.isMobileView() && anchor.parent().hasClass("mega-hide-sub-menu-on-mobile")) {
126                return;
127            }
128
129            if (plugin.isDesktopView() && ( $menu.hasClass("mega-menu-horizontal") || $menu.hasClass("mega-menu-vertical") ) && !anchor.parent().hasClass("mega-collapse-children")) {
130                plugin.hideSiblingPanels(anchor, true);
131            }
132
133            if ((plugin.isMobileView() && $wrap.hasClass("mega-keyboard-navigation")) || plugin.settings.vertical_behaviour === "accordion") {
134                plugin.hideSiblingPanels(anchor, false);
135            }
136
137            plugin.calculateDynamicSubmenuWidths(anchor);
138
139            // apply jQuery transition (only if the effect is set to "slide", other transitions are CSS based)
140            if ( plugin.shouldUseSlideAnimation(anchor, immediate) ) {
141                var speed = plugin.isMobileView() ? plugin.settings.effect_speed_mobile : plugin.settings.effect_speed;
142
143                anchor.siblings(".mega-sub-menu").css("display", "none").animate({"height":"show", "paddingTop":"show", "paddingBottom":"show", "minHeight":"show"}, speed, function() {
144                    $(this).css("display", "");
145                });
146            }
147
148            anchor.parent().addClass("mega-toggle-on").triggerHandler("open_panel");
149        };
150        
151
152        plugin.shouldUseSlideAnimation = function(anchor, immediate) {
153
154            if (immediate == true) {
155                return false;
156            }
157
158            if (anchor.parent().hasClass("mega-collapse-children")) {
159                return true;
160            }
161
162            if (plugin.isDesktopView() && plugin.settings.effect === "slide") {
163                return true;
164            }
165
166            if (plugin.isMobileView()) {
167                if (plugin.settings.effect_mobile === "slide") {
168                    return true;
169                }
170
171                if (plugin.settings.effect_mobile === "slide_left" || plugin.settings.effect_mobile === "slide_right") {
172                    return plugin.settings.mobile_direction !== "horizontal";
173                }
174            }
175
176            return false;
177        };
178
179
180        plugin.hidePanel = function(anchor, immediate) {
181            if ( $.isNumeric(anchor) ) {
182                anchor = $("li.mega-menu-item-" + anchor, $menu).find("a.mega-menu-link").first();
183            } else if ( anchor.is("li.mega-menu-item") ) {
184                anchor = anchor.find("a.mega-menu-link").first();
185            }
186
187            anchor.parent().triggerHandler("before_close_panel");
188
189            anchor.parent().find("[aria-expanded]").first().attr("aria-expanded", "false");
190
191            if ( plugin.shouldUseSlideAnimation(anchor) ) {
192                var speed = plugin.isMobileView() ? plugin.settings.effect_speed_mobile : plugin.settings.effect_speed;
193
194                anchor.siblings(".mega-sub-menu").animate({"height":"hide", "paddingTop":"hide", "paddingBottom":"hide", "minHeight":"hide"}, speed, function() {
195                    anchor.siblings(".mega-sub-menu").css("display", "");
196                    anchor.parent().removeClass("mega-toggle-on").triggerHandler("close_panel");
197                });
198
199                return;
200            }
201
202            if (immediate) {
203                anchor.siblings(".mega-sub-menu").css("display", "none").delay(plugin.settings.effect_speed).queue(function(){
204                    $(this).css("display", "").dequeue();
205                });
206            }
207
208            // pause video widget videos
209            anchor.siblings(".mega-sub-menu").find(".widget_media_video video").each(function() {
210                this.player.pause();
211            });
212
213            anchor.parent().removeClass("mega-toggle-on").triggerHandler("close_panel");
214            plugin.addAnimatingClass(anchor.parent());
215        };
216
217        plugin.calculateDynamicSubmenuWidths = function(anchor) {
218            // apply dynamic width and sub menu position (only to top level mega menus)
219            if (anchor.parent().hasClass("mega-menu-megamenu") && anchor.parent().parent().hasClass("max-mega-menu") && plugin.settings.panel_width ) {
220                if (plugin.isDesktopView()) {
221                    var submenu_offset = $menu.offset();
222                    var target_offset = $(plugin.settings.panel_width).offset();
223
224                    if ( plugin.settings.panel_width == '100vw' ) {
225                        target_offset = $('body').offset();
226
227                        anchor.siblings(".mega-sub-menu").css({
228                            left: (target_offset.left - submenu_offset.left) + "px"
229                        });
230                    } else if ( $(plugin.settings.panel_width).length > 0 ) {
231                        anchor.siblings(".mega-sub-menu").css({
232                            width: $(plugin.settings.panel_width).outerWidth(),
233                            left: (target_offset.left - submenu_offset.left) + "px"
234                        });
235                    }
236                } else {
237                    anchor.siblings(".mega-sub-menu").css({
238                        width: "",
239                        left: ""
240                    });
241                }
242            }
243
244            // apply inner width to sub menu by adding padding to the left and right of the mega menu
245            if (anchor.parent().hasClass("mega-menu-megamenu") && anchor.parent().parent().hasClass("max-mega-menu") && plugin.settings.panel_inner_width && $(plugin.settings.panel_inner_width).length > 0) {
246                var target_width = 0;
247
248                if ($(plugin.settings.panel_inner_width).length) {
249                    // jQuery selector
250                    target_width = parseInt($(plugin.settings.panel_inner_width).width(), 10);
251                } else {
252                    // we"re using a pixel width
253                    target_width = parseInt(plugin.settings.panel_inner_width, 10);
254                }
255
256                anchor.siblings(".mega-sub-menu").css({
257                    "paddingLeft": "",
258                    "paddingRight": ""
259                });
260
261                var submenu_width = parseInt(anchor.siblings(".mega-sub-menu").innerWidth(), 10);
262
263                if (plugin.isDesktopView() && target_width > 0 && target_width < submenu_width) {
264                    anchor.siblings(".mega-sub-menu").css({
265                        "paddingLeft": (submenu_width - target_width) / 2 + "px",
266                        "paddingRight": (submenu_width - target_width) / 2 + "px"
267                    });
268                }
269            }
270        };
271
272        plugin.bindClickEvents = function() {
273
274            if ( $wrap.data('has-click-events') === true ) {
275                return;
276            }
277
278            $wrap.data('has-click-events', true);
279
280            var dragging = false;
281
282            $(document).on({
283                "touchmove": function(e) { dragging = true; },
284                "touchstart": function(e) { dragging = false; }
285            });
286
287            $(document).on("click touchend", function(e) { // hide menu when clicked away from
288                if (!dragging && plugin.settings.document_click === "collapse" && ! $(e.target).closest(".mega-menu-wrap").length ) {
289                    plugin.hideAllPanels();
290                    plugin.hideMobileMenu();
291                }
292                dragging = false;
293            });
294
295            var clickable_parents = $("> a.mega-menu-link", items_with_submenus).add(collapse_children_parents);
296
297            clickable_parents.on("touchend.megamenu", function(e) {
298                if (plugin.settings.event === "hover_intent") {
299                    plugin.unbindHoverIntentEvents();
300                }
301
302                if (plugin.settings.event === "hover") {
303                    plugin.unbindHoverEvents();
304                }
305            });
306
307            clickable_parents.on("click.megamenu", function(e) {
308                if ( $(e.target).hasClass('mega-indicator') ) {
309                    return;
310                }
311
312                if (plugin.isDesktopView() && $(this).parent().hasClass("mega-toggle-on") && $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
313                    if (plugin.settings.second_click === "go") {
314                        return;
315                    } else {
316                        e.preventDefault();
317                        return;
318                    }
319                }
320                if (dragging) {
321                    return;
322                }
323                if (plugin.isMobileView() && $(this).parent().hasClass("mega-hide-sub-menu-on-mobile")) {
324                    return; // allow all clicks on parent items when sub menu is hidden on mobile
325                }
326                if ((plugin.settings.second_click === "go" || $(this).parent().hasClass("mega-click-click-go")) && $(this).attr("href") !== undefined) { // check for second click
327                    if (!$(this).parent().hasClass("mega-toggle-on")) {
328                        e.preventDefault();
329                        plugin.showPanel($(this));
330                    }
331                } else {
332                    e.preventDefault();
333
334                    if ($(this).parent().hasClass("mega-toggle-on")) {
335                        plugin.hidePanel($(this), false);
336                    } else {
337                        plugin.showPanel($(this));
338                    }
339                }
340            });
341
342            if ( plugin.settings.second_click === "disabled" ) {
343                clickable_parents.off("click.megamenu");
344            }
345
346            $(".mega-close-after-click:not(.mega-menu-item-has-children) > a.mega-menu-link", $menu).on("click", function() {
347                plugin.hideAllPanels();
348                plugin.hideMobileMenu();
349            });
350
351            $("button.mega-close", $wrap).on("click", function(e) {
352                plugin.hideMobileMenu();
353            });
354        };
355
356        plugin.bindHoverEvents = function() {
357            items_with_submenus.on({
358                "mouseenter.megamenu" : function() {
359                    plugin.unbindClickEvents();
360                    if (! $(this).hasClass("mega-toggle-on")) {
361                        plugin.showPanel($(this).children("a.mega-menu-link"));
362                    }
363                },
364                "mouseleave.megamenu" : function() {
365                    if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) {
366                        plugin.hidePanel($(this).children("a.mega-menu-link"), false);
367                    }
368                }
369            });
370        };
371
372        plugin.bindHoverIntentEvents = function() {
373            items_with_submenus.hoverIntent({
374                over: function () {
375                    plugin.unbindClickEvents();
376                    if (! $(this).hasClass("mega-toggle-on")) {
377                        plugin.showPanel($(this).children("a.mega-menu-link"));
378                    }
379                },
380                out: function () {
381                    if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) {
382                        plugin.hidePanel($(this).children("a.mega-menu-link"), false);
383                    }
384                },
385                timeout: plugin.settings.hover_intent_timeout,
386                interval: plugin.settings.hover_intent_interval
387            });
388        };
389
390        plugin.bindKeyboardEvents = function() {
391            var tab_key = 9;
392            var escape_key = 27;
393            var enter_key = 13;
394            var left_arrow_key = 37;
395            var up_arrow_key = 38;
396            var right_arrow_key = 39;
397            var down_arrow_key = 40;
398            var space_key = 32;
399
400            var isMobileOffCanvasHorizontal = function() {
401                return plugin.isMobileView() && ( plugin.settings.effect_mobile === 'slide_right' || plugin.settings.effect_mobile === '' )  && plugin.settings.mobile_direction === 'horizontal';
402            }
403
404            var shouldTrapFocusInCurrentSubMenu = function() {
405                return isMobileOffCanvasHorizontal() && ( keyCode === up_arrow_key || keyCode === down_arrow_key || keyCode === tab_key );
406            }
407
408            $wrap.on("keyup.megamenu", ".max-mega-menu, .mega-menu-toggle", function(e) {
409                var keyCode = e.keyCode || e.which;
410                var active_link = $(e.target);
411
412                if (keyCode === tab_key) {
413                    $wrap.addClass("mega-keyboard-navigation");
414                    plugin.bindClickEvents(); // Windows Narrator ignores the Enter keypress, so ensure click events are available when pressing tab
415                }
416            });
417
418            $wrap.on("keydown.megamenu", "a.mega-menu-link, .mega-indicator, .mega-menu-toggle-block, .mega-menu-toggle-animated-block button", function(e) {
419
420                if ( ! $wrap.hasClass("mega-keyboard-navigation") ) {
421                    return;
422                }
423
424                var keyCode = e.keyCode || e.which;
425                var active_link = $(e.target);
426
427                if ( keyCode === space_key && active_link.is(".mega-menu-link") ) {
428                    e.preventDefault();
429
430                    // pressing space on a parent item will always toggle the sub menu
431                    if ( active_link.parent().is(items_with_submenus) ) {
432                        if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
433                            plugin.hidePanel(active_link);
434                        } else {
435                            plugin.showPanel(active_link);
436                        }
437                    }
438                }
439
440                if ( keyCode === space_key && active_link.is("mega-indicator") ) {
441                    e.preventDefault();
442
443                    if ( active_link.parent().parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
444                        plugin.hidePanel(active_link.parent());
445                    } else {
446                        plugin.showPanel(active_link.parent());
447                    }
448                }
449
450                if ( keyCode === escape_key ) {
451                    var submenu_open = $(".mega-toggle-on", $menu).length !== 0;
452
453                    if ( submenu_open ) {
454                        var focused_menu_item = $menu.find(":focus");
455
456                        if ( focused_menu_item.closest('.mega-menu-flyout.mega-toggle-on').length !== 0 ) {
457                            var nearest_parent_of_focused_item_li = focused_menu_item.closest('.mega-toggle-on');
458                            var nearest_parent_of_focused_item_a = $("> a.mega-menu-link", nearest_parent_of_focused_item_li);
459                            plugin.hidePanel(nearest_parent_of_focused_item_a);
460                            nearest_parent_of_focused_item_a.focus();
461                        }
462
463                        if ( focused_menu_item.closest('.mega-menu-megamenu.mega-toggle-on').length !== 0 ) {
464                            var nearest_parent_of_focused_item_li = focused_menu_item.closest('.mega-menu-megamenu.mega-toggle-on');
465                            var nearest_parent_of_focused_item_a = $("> a.mega-menu-link", nearest_parent_of_focused_item_li);
466                            plugin.hidePanel(nearest_parent_of_focused_item_a);
467                            nearest_parent_of_focused_item_a.focus();
468                        }
469                    }
470
471                    if ( plugin.isMobileView() && ! submenu_open ) {
472                        plugin.hideMobileMenu();
473                        $(".mega-menu-toggle-block, button.mega-toggle-animated", $toggle_bar).first().focus();
474                    }
475                }
476
477                if ( keyCode === space_key || keyCode === enter_key ) {
478                    if ( active_link.is(".mega-menu-toggle-block, .mega-menu-toggle-animated-block button") ) {
479                        e.preventDefault();
480                        
481                        if ( $toggle_bar.hasClass("mega-menu-open") ) {
482                            plugin.hideMobileMenu();
483                        } else {
484                            plugin.showMobileMenu();
485                        }
486                    }
487                }
488
489                if ( keyCode === enter_key ) { // ignored by windows narrator
490
491                    // pressing enter on an arrow will toggle the sub menu
492                    if ( active_link.is(".mega-indicator") ) {
493                        if ( active_link.closest("li.mega-menu-item").hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
494                            plugin.hidePanel(active_link.parent());
495                        } else {
496                            plugin.showPanel(active_link.parent());
497                        }
498
499                        return;
500                    }
501                    // pressing enter on a parent link
502                    if ( active_link.parent().is(items_with_submenus) ) {
503
504                        // when clicking on the parent of a hidden submenu, follow the link
505                        if ( plugin.isMobileView() && active_link.parent().is(".mega-hide-sub-menu-on-mobile") ) {
506                            return;
507                        }
508
509                        // pressing enter on a parent item without a link will toggle the sub menu
510                        if ( active_link.is("[href]") === false ) {
511                            if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
512                                plugin.hidePanel(active_link);
513                            } else {
514                                plugin.showPanel(active_link);
515                            }
516
517                            return;
518                        }
519
520                        // pressing enter on a parent item will first open the sub menu, then follow the link
521                        if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) {
522                            return;
523                        } else {
524                            e.preventDefault();
525                            plugin.showPanel(active_link);
526                        }
527                    }
528                }
529
530                if ( shouldTrapFocusInCurrentSubMenu() ) {
531                    var focused_item = $(":focus", $menu);
532
533                    // if the menu doesn't have focus, focus the first menu item
534                    if ( focused_item.length === 0) {
535                        e.preventDefault();
536                        $("> li.mega-menu-item:visible", $menu).find("> a.mega-menu-link, .mega-search span[role=button]").first().focus();
537                        return;
538                    }
539
540                    // try to find the next item at the same level
541                    var next_item_to_focus = focused_item.parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first();
542
543                    // can't find another item in the same level, attempt to skip back to the top
544                    if ( next_item_to_focus.length === 0 && focused_item.closest(".mega-menu-megamenu").length !== 0 ) {
545                        // are we inside a megamenu? find the 'back' button and focus on that
546                        var all_li_parents = focused_item.parentsUntil(".mega-menu-megamenu");
547
548                        if ( focused_item.is(all_li_parents.find("a.mega-menu-link").last()) ) {
549                            next_item_to_focus = all_li_parents.find(".mega-back-button:visible > a.mega-menu-link").first();
550                        }
551                    }
552
553                    // skip back to the top of non-megamenu menus
554                    if ( next_item_to_focus.length === 0 ) {
555                        next_item_to_focus = focused_item.parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first();
556                    }
557
558                    if ( next_item_to_focus.length !== 0 ) {
559                        e.preventDefault();
560                        next_item_to_focus.focus();
561                    }
562                    
563                }
564
565                var shouldGoToNextTopLevelItem = function() {
566                    return ( ( keyCode === right_arrow_key && plugin.isDesktopView() ) || ( keyCode === down_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal");
567                }
568
569                var shouldGoToPreviousTopLevelItem = function() {
570                    return ( ( keyCode === left_arrow_key && plugin.isDesktopView() ) || ( keyCode === up_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal");
571                }
572
573                if ( shouldGoToNextTopLevelItem() ) {
574                    e.preventDefault();
575
576                    var next_top_level_item = $("> .mega-toggle-on", $menu).nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first();
577
578                    if (next_top_level_item.length === 0) {
579                        next_top_level_item = $(":focus", $menu).parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first();
580                    }
581
582                    if (next_top_level_item.length === 0) {
583                        next_top_level_item = $(":focus", $menu).parent().parent().parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first();
584                    }
585
586                    plugin.hideAllPanels();
587                    next_top_level_item.focus();
588                }
589
590                if ( shouldGoToPreviousTopLevelItem() ) {
591                    e.preventDefault();
592
593                    var prev_top_level_item = $("> .mega-toggle-on", $menu).prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last();
594
595                    if (prev_top_level_item.length === 0) {
596                        prev_top_level_item = $(":focus", $menu).parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last();
597                    }
598
599                    if (prev_top_level_item.length === 0) {
600                        prev_top_level_item = $(":focus", $menu).parent().parent().parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last();
601                    }
602
603                    plugin.hideAllPanels();
604                    prev_top_level_item.focus();
605                }
606            });
607
608            $wrap.on("focusout.megamenu", function(e) {
609                if ( $wrap.hasClass("mega-keyboard-navigation") ) {
610                    setTimeout(function() {
611                        var menu_has_focus = $wrap.find(":focus").length > 0;
612                        if (! menu_has_focus) {
613                            $wrap.removeClass("mega-keyboard-navigation");
614                            plugin.hideAllPanels();
615                            plugin.hideMobileMenu();
616                        }
617                    }, 10);
618                }
619            });
620        };
621
622        plugin.unbindAllEvents = function() {
623            $("ul.mega-sub-menu, li.mega-menu-item, li.mega-menu-row, li.mega-menu-column, a.mega-menu-link, .mega-indicator", $menu).off().unbind();
624        };
625
626        plugin.unbindClickEvents = function() {
627            if ( $wrap.hasClass('mega-keyboard-navigation') ) {
628                return;
629            }
630
631            // collapsable parents always have a click event
632            $("> a.mega-menu-link", items_with_submenus).not(collapse_children_parents).off("click.megamenu touchend.megamenu");
633
634            $wrap.data('has-click-events', false);
635        };
636
637        plugin.unbindHoverEvents = function() {
638            items_with_submenus.off("mouseenter.megamenu mouseleave.megamenu");
639        };
640
641        plugin.unbindHoverIntentEvents = function() {
642            items_with_submenus.off("mouseenter mouseleave").removeProp("hoverIntent_t").removeProp("hoverIntent_s"); // hoverintent does not allow namespaced events
643        };
644
645        plugin.unbindKeyboardEvents = function() {
646            $wrap.off("keyup.megamenu keydown.megamenu focusout.megamenu");
647        };
648
649        plugin.unbindMegaMenuEvents = function() {
650            if (plugin.settings.event === "hover_intent") {
651                plugin.unbindHoverIntentEvents();
652            }
653
654            if (plugin.settings.event === "hover") {
655                plugin.unbindHoverEvents();
656            }
657
658            plugin.unbindClickEvents();
659            plugin.unbindKeyboardEvents();
660        };
661
662        plugin.bindMegaMenuEvents = function() {
663            plugin.unbindMegaMenuEvents();
664
665            if (plugin.isDesktopView() && plugin.settings.event === "hover_intent") {
666                plugin.bindHoverIntentEvents();
667            }
668
669            if (plugin.isDesktopView() && plugin.settings.event === "hover") {
670                plugin.bindHoverEvents();
671            }
672
673            plugin.bindClickEvents(); // always bind click events for touch screen devices
674            plugin.bindKeyboardEvents();
675        };
676
677        plugin.checkWidth = function() {
678            if ( plugin.isMobileView() && $menu.data("view") === "desktop" ) {
679                plugin.switchToMobile();
680            }
681
682            if ( plugin.isDesktopView() && $menu.data("view") === "mobile" ) {
683                plugin.switchToDesktop();
684            }
685
686            plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu));
687        };
688
689        plugin.reverseRightAlignedItems = function() {
690            if ( ! $("body").hasClass("rtl") && $menu.hasClass("mega-menu-horizontal") && $menu.css("display") !== 'flex' ) {
691                $menu.append($menu.children("li.mega-item-align-right").get().reverse());
692            }
693        };
694
695        plugin.addClearClassesToMobileItems = function() {
696            $(".mega-menu-row", $menu).each(function() {
697                $("> .mega-sub-menu > .mega-menu-column:not(.mega-hide-on-mobile)", $(this)).filter(":even").addClass("mega-menu-clear"); // :even is 0 based
698            });
699        };
700
701        plugin.initDesktop = function() {
702            $menu.data("view", "desktop");
703            plugin.bindMegaMenuEvents();
704            plugin.initIndicators();
705        };
706
707        plugin.initMobile = function() {
708            plugin.switchToMobile();
709        };
710
711        plugin.switchToDesktop = function() {
712            $menu.data("view", "desktop");
713            plugin.bindMegaMenuEvents();
714            plugin.reverseRightAlignedItems();
715            plugin.hideAllPanels();
716            plugin.hideMobileMenu(true);
717        };
718
719        plugin.switchToMobile = function() {
720            $menu.data("view", "mobile");
721            plugin.bindMegaMenuEvents();
722            plugin.initIndicators();
723            plugin.reverseRightAlignedItems();
724            plugin.addClearClassesToMobileItems();
725            plugin.hideAllPanels();
726            plugin.expandMobileSubMenus();
727        };
728
729        plugin.initToggleBar = function() {
730            $toggle_bar.on("click", function(e) {
731                if ( $(e.target).is(".mega-menu-toggle, .mega-menu-toggle-custom-block *, .mega-menu-toggle-block, .mega-menu-toggle-animated-block, .mega-menu-toggle-animated-block *, .mega-toggle-blocks-left, .mega-toggle-blocks-center, .mega-toggle-blocks-right, .mega-toggle-label, .mega-toggle-label span") ) {
732                    e.preventDefault();
733                    
734                    if ($(this).hasClass("mega-menu-open")) {
735                        plugin.hideMobileMenu();
736                    } else {
737                        plugin.showMobileMenu();
738                    }
739                }
740            });
741        };
742
743        plugin.initIndicators = function() {
744             $menu.off('click.megamenu', '.mega-indicator');
745
746             $menu.on('click.megamenu', '.mega-indicator', function(e) {
747                e.preventDefault();
748                e.stopPropagation();
749
750                if ( $(this).closest(".mega-menu-item").hasClass("mega-toggle-on") ) {
751                    if ( ! $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") || plugin.isMobileView() ) {
752                        plugin.hidePanel($(this).parent(), false);
753                    }
754                } else {
755                    plugin.showPanel($(this).parent(), false);
756                }
757             });
758        };
759
760        plugin.hideMobileMenu = function(force) {
761            force = force || false;
762
763            if ( ! $toggle_bar.is(":visible") && ! force ) {
764                return;
765            }
766
767            html_body_class_timeout = setTimeout(function() {
768                $("body").removeClass($menu.attr("id") + "-mobile-open");
769                $("html").removeClass($menu.attr("id") + "-off-canvas-open");
770            }, plugin.settings.effect_speed_mobile);
771
772            $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "false");
773
774            if (plugin.settings.effect_mobile === "slide" && ! force ) {
775                $menu.animate({"height":"hide"}, plugin.settings.effect_speed_mobile, function() {
776                    $menu.css({
777                        width: "",
778                        left: "",
779                        display: ""
780                    });
781
782                    $toggle_bar.removeClass("mega-menu-open");
783                });
784            } else {
785                $menu.css({
786                    width: "",
787                    left: "",
788                    display: ""
789                });
790                    
791                $toggle_bar.removeClass("mega-menu-open");
792            }
793
794            $menu.triggerHandler("mmm:hideMobileMenu");
795        };
796
797        plugin.showMobileMenu = function() {
798            if ( ! $toggle_bar.is(":visible")) {
799                return;
800            }
801
802            clearTimeout(html_body_class_timeout);
803
804            $("body").addClass($menu.attr("id") + "-mobile-open");
805
806            plugin.expandMobileSubMenus();
807
808            if ( plugin.settings.effect_mobile === "slide_left" || plugin.settings.effect_mobile === "slide_right" ) {
809                $("html").addClass($menu.attr("id") + "-off-canvas-open");
810            }
811
812            $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "true");
813
814            if (plugin.settings.effect_mobile === "slide") {
815                $menu.animate({"height":"show"}, plugin.settings.effect_speed_mobile, function() {
816                    $(this).css("display", "");
817                });
818            }
819
820            $toggle_bar.addClass("mega-menu-open");
821
822            plugin.toggleBarForceWidth();
823
824            $menu.triggerHandler("mmm:showMobileMenu");
825        };
826
827        plugin.toggleBarForceWidth = function() {
828            if ($(plugin.settings.mobile_force_width).length && ( plugin.settings.effect_mobile === "slide" || plugin.settings.effect_mobile === "disabled" ) ) {
829                var submenu_offset = $toggle_bar.offset();
830                var target_offset = $(plugin.settings.mobile_force_width).offset();
831
832                $menu.css({
833                    width: $(plugin.settings.mobile_force_width).outerWidth(),
834                    left: (target_offset.left - submenu_offset.left) + "px"
835                });
836            }
837        };
838
839        plugin.doConsoleChecks = function() {
840            if (plugin.settings.mobile_force_width != "false" && ! $(plugin.settings.mobile_force_width).length && ( plugin.settings.effect_mobile === "slide" || plugin.settings.effect_mobile === "disabled" ) ) {
841                console.warn('Max Mega Menu #' + $wrap.attr('id') + ': Mobile Force Width element (' + plugin.settings.mobile_force_width + ') not found');
842            }
843
844            const cssWidthRegex = /^((\d+(\.\d+)?(px|%|em|rem|vw|vh|ch|ex|cm|mm|in|pt|pc))|auto)$/i;
845
846            if (plugin.settings.panel_width !== undefined && ! cssWidthRegex.test(plugin.settings.panel_width) && ! $(plugin.settings.panel_width).length ) {
847                console.warn('Max Mega Menu #' + $wrap.attr('id') + ': Panel Width (Outer) element (' + plugin.settings.panel_width + ') not found');
848            }
849
850            if (plugin.settings.panel_inner_width !== undefined && ! cssWidthRegex.test(plugin.settings.panel_inner_width) && ! $(plugin.settings.panel_inner_width).length ) {
851                console.warn('Max Mega Menu #' + $wrap.attr('id') + ': Panel Width (Inner) element (' + plugin.settings.panel_inner_width + ') not found');
852            }
853        }
854
855        plugin.init = function() {
856            $menu.triggerHandler("before_mega_menu_init");
857            plugin.settings = $.extend({}, defaults, options);
858
859            if (window.console) {
860                plugin.doConsoleChecks();
861            }
862
863            $menu.removeClass("mega-no-js");
864
865            plugin.initToggleBar();
866            
867            if (plugin.settings.unbind_events === "true") {
868                plugin.unbindAllEvents();
869            }
870
871            $(window).on("load", function() {
872                plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu));
873            });
874
875            if ( plugin.isDesktopView() ) {
876                plugin.initDesktop();
877            } else {
878                plugin.initMobile();
879            }
880
881            $(window).on("resize", function() {
882                plugin.checkWidth();
883            });
884
885            $menu.triggerHandler("after_mega_menu_init");
886        };
887
888        plugin.init();
889    };
890
891    $.fn.maxmegamenu = function(options) {
892        return this.each(function() {
893            if (undefined === $(this).data("maxmegamenu")) {
894                var plugin = new $.maxmegamenu(this, options);
895                $(this).data("maxmegamenu", plugin);
896            }
897        });
898    };
899
900    $(function() {
901        $(".max-mega-menu").maxmegamenu();
902    });
903}( jQuery ));

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.