PageSourceSearch

https://internetretailing.net/wp-content/plugins/megamenu/js/maxmegamenu.js?ver=3.3.1

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