PageSourceSearch

https://www.ccmb.res.in/wp-content/plugins/megamenu/js/maxmegamenu.js?ver=3.5

js ccmb.res.in collected 2026-09-24 08:54:54 UTC 37,996 bytes, 865 lines download raw bytes

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