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