PageSourceSearch

https://iiit.org/blog/wp-content/plugins/megamenu/js/maxmegamenu.js?ver=2.9.7

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