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