PageSourceSearch

https://www.tunefm.net/content/plugins/megamenu/js/maxmegamenu.js?ver=3.4.1

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