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 (plugin.isDesktopView() && $(this).parent().hasClass("mega-toggle-on") && $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 254 if (plugin.settings.second_click === "go") { 255 return; 256 } else { 257 e.preventDefault(); 258 return; 259 } 260 } 261 if (dragging) { 262 return; 263 } 264 if (plugin.isMobileView() && $(this).parent().hasClass("mega-hide-sub-menu-on-mobile")) { 265 return; // allow all clicks on parent items when sub menu is hidden on mobile 266 } 267 if ((plugin.settings.second_click === "go" || $(this).parent().hasClass("mega-click-click-go")) && $(this).attr("href") !== undefined) { // check for second click 268 if (!$(this).parent().hasClass("mega-toggle-on")) { 269 e.preventDefault(); 270 plugin.showPanel($(this)); 271 } 272 } else { 273 e.preventDefault(); 274 275 if ($(this).parent().hasClass("mega-toggle-on")) { 276 plugin.hidePanel($(this), false); 277 } else { 278 plugin.showPanel($(this)); 279 } 280 } 281 }); 282 283 collapse_children_parents.each(function() { 284 $(this).attr("data-has-click-event", "true"); 285 }); 286 287 if ( plugin.settings.second_click === "disabled" ) { 288 clickable_parents.off("click.megamenu"); 289 } 290 291 $(".mega-close-after-click:not(.mega-menu-item-has-children) > a.mega-menu-link", menu).on("click", function() { 292 plugin.hideAllPanels(); 293 plugin.hideMobileMenu(); 294 }); 295 }; 296 297 plugin.bindHoverEvents = function() { 298 items_with_submenus.on({ 299 "mouseenter.megamenu" : function() { 300 plugin.unbindClickEvents(); 301 if (! $(this).hasClass("mega-toggle-on")) { 302 plugin.showPanel($(this).children("a.mega-menu-link")); 303 } 304 }, 305 "mouseleave.megamenu" : function() { 306 if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) { 307 plugin.hidePanel($(this).children("a.mega-menu-link"), false); 308 } 309 } 310 }); 311 }; 312 313 plugin.bindHoverIntentEvents = function() { 314 items_with_submenus.hoverIntent({ 315 over: function () { 316 plugin.unbindClickEvents(); 317 if (! $(this).hasClass("mega-toggle-on")) { 318 plugin.showPanel($(this).children("a.mega-menu-link")); 319 } 320 }, 321 out: function () { 322 if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) { 323 plugin.hidePanel($(this).children("a.mega-menu-link"), false); 324 } 325 }, 326 timeout: plugin.settings.hover_intent_timeout, 327 interval: plugin.settings.hover_intent_interval 328 }); 329 }; 330 331 plugin.bindKeyboardEvents = function() { 332 var tab_key = 9; 333 var escape_key = 27; 334 var enter_key = 13; 335 var left_arrow_key = 37; 336 var up_arrow_key = 38; 337 var right_arrow_key = 39; 338 var down_arrow_key = 40; 339 var space_key = 32; 340 341 $menu.parent().on("keyup.megamenu", ".max-mega-menu, .mega-menu-toggle", function(e) { 342 var keyCode = e.keyCode || e.which; 343 var active_link = $(e.target); 344 345 if (keyCode === tab_key) { 346 $menu.parent().addClass("mega-keyboard-navigation"); 347 } 348 }); 349 350 $menu.parent().on("keydown.megamenu", "a.mega-menu-link, .mega-indicator, .mega-menu-toggle-block, .mega-menu-toggle-animated-block button", function(e) { 351 352 if ( ! $menu.parent().hasClass("mega-keyboard-navigation") ) { 353 return; 354 } 355 356 var keyCode = e.keyCode || e.which; 357 var active_link = $(e.target); 358 359 if ( keyCode === space_key && active_link.is(".mega-menu-link") ) { 360 e.preventDefault(); 361 362 // pressing space on a parent item will always toggle the sub menu 363 if ( active_link.parent().is(items_with_submenus) ) { 364 if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 365 plugin.hidePanel(active_link); 366 } else { 367 plugin.showPanel(active_link); 368 } 369 } 370 } 371 372 if ( keyCode === space_key && active_link.is("mega-indicator") ) { 373 e.preventDefault(); 374 375 if ( active_link.parent().parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 376 plugin.hidePanel(active_link.parent()); 377 } else { 378 plugin.showPanel(active_link.parent()); 379 } 380 } 381 382 if ( keyCode === escape_key ) { 383 var submenu_open = $("> .mega-toggle-on", $menu).length !== 0; 384 385 $("> .mega-toggle-on", $menu).find("[tabindex]:visible").first().focus(); 386 387 plugin.hideAllPanels(); 388 389 if ( plugin.isMobileView() && ! submenu_open ) { 390 plugin.hideMobileMenu(); 391 $(".mega-menu-toggle-block, button.mega-toggle-animated", $toggle_bar).first().focus(); 392 } 393 } 394 395 if ( keyCode === space_key ) { 396 e.preventDefault(); 397 398 if ( active_link.is(".mega-menu-toggle-block, .mega-menu-toggle-animated-block button") ) { 399 if ( $toggle_bar.hasClass("mega-menu-open") ) { 400 plugin.hideMobileMenu(); 401 } else { 402 plugin.showMobileMenu(); 403 } 404 } 405 } 406 407 if ( keyCode === enter_key ) { 408 if ( active_link.is(".mega-menu-toggle-block") ) { 409 if ( $toggle_bar.hasClass("mega-menu-open") ) { 410 plugin.hideMobileMenu(); 411 } else { 412 plugin.showMobileMenu(); 413 } 414 } 415 416 // pressing enter on an arrow will toggle the sub menu 417 if ( active_link.is(".mega-indicator") ) { 418 if ( active_link.closest("li.mega-menu-item").hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 419 plugin.hidePanel(active_link.parent()); 420 } else { 421 plugin.showPanel(active_link.parent()); 422 } 423 424 return; 425 } 426 427 // pressing enter on a parent link 428 if ( active_link.parent().is(items_with_submenus) ) { 429 // when the arrow has been moved (i.e. it is clickable and visible, don't show the sub menu - just follow the link) 430 if ( active_link.is("[href]") && active_link.siblings(".mega-indicator[tabindex]:visible").length !== 0 ) { 431 return; 432 } 433 434 // pressing enter on a parent item without a link
434will toggle the sub menu 435 if ( active_link.is("[href]") === false ) { 436 if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 437 plugin.hidePanel(active_link); 438 } else { 439 plugin.showPanel(active_link); 440 } 441 442 return; 443 } 444 445 // pressing enter on a parent item will first open the sub menu, then follow the link 446 if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { 447 return; 448 } else { 449 e.preventDefault(); 450 plugin.showPanel(active_link); 451 } 452 } 453 } 454 455 if ( ( ( keyCode === right_arrow_key && plugin.isDesktopView() ) || ( keyCode === down_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal") ) { 456 e.preventDefault(); 457 458 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(); 459 460 if (next_top_level_item.length === 0) { 461 next_top_level_item = $(":focus", $menu).parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); 462 } 463 464 if (next_top_level_item.length === 0) { 465 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(); 466 } 467 468 plugin.hideAllPanels(); 469 next_top_level_item.focus(); 470 } 471 472 if ( ( ( keyCode === left_arrow_key && plugin.isDesktopView() ) || ( keyCode === up_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal") ) { 473 e.preventDefault(); 474 475 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(); 476 477 if (prev_top_level_item.length === 0) { 478 prev_top_level_item = $(":focus", $menu).parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last(); 479 } 480 481 if (prev_top_level_item.length === 0) { 482 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(); 483 } 484 485 plugin.hideAllPanels(); 486 prev_top_level_item.focus(); 487 } 488 }); 489 490 $menu.parent().on("focusout.megamenu", function(e) { 491 if ( $menu.parent().hasClass("mega-keyboard-navigation") ) { 492 setTimeout(function() { 493 var menu_has_focus = $menu.parent().find(":focus").length > 0; 494 if (! menu_has_focus) { 495 $menu.parent().removeClass("mega-keyboard-navigation"); 496 plugin.hideAllPanels(); 497 plugin.hideMobileMenu(); 498 } 499 }, 10); 500 } 501 }); 502 }; 503 504 plugin.unbindAllEvents = function() { 505 $("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(); 506 }; 507 508 plugin.unbindClickEvents = function() { 509 // collapsable parents always have a click event 510 $("> a.mega-menu-link", items_with_submenus).not(collapse_children_parents).off("click.megamenu touchend.megamenu"); 511 }; 512 513 plugin.unbindHoverEvents = function() {
514 items_with_submenus.unbind("mouseenter.megamenu mouseleave.megamenu"); 515 }; 516 517 plugin.unbindHoverIntentEvents = function() { 518 items_with_submenus.unbind("mouseenter mouseleave").removeProp("hoverIntent_t").removeProp("hoverIntent_s"); // hoverintent does not allow namespaced events 519 }; 520 521 plugin.unbindKeyboardEvents = function() { 522 $menu.parent().off("keyup.megamenu keydown.megamenu focusout.megamenu"); 523 }; 524 525 plugin.unbindMegaMenuEvents = function() { 526 if (plugin.settings.event === "hover_intent") { 527 plugin.unbindHoverIntentEvents(); 528 } 529 530 if (plugin.settings.event === "hover") { 531 plugin.unbindHoverEvents(); 532 } 533 534 plugin.unbindClickEvents(); 535 plugin.unbindKeyboardEvents(); 536 }; 537 538 plugin.bindMegaMenuEvents = function() { 539 plugin.unbindMegaMenuEvents(); 540 541 if (plugin.isDesktopView() && plugin.settings.event === "hover_intent") { 542 plugin.bindHoverIntentEvents(); 543 } 544 545 if (plugin.isDesktopView() && plugin.settings.event === "hover") { 546 plugin.bindHoverEvents(); 547 } 548 549 plugin.bindClickEvents(); // always bind click events for touch screen devices 550 plugin.bindKeyboardEvents(); 551 }; 552 553 plugin.checkWidth = function() { 554 if ( plugin.isMobileView() && $menu.data("view") === "desktop" ) { 555 plugin.switchToMobile(); 556 } 557 558 if ( plugin.isDesktopView() && $menu.data("view") === "mobile" ) { 559 plugin.switchToDesktop(); 560 } 561 562 plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu)); 563 }; 564 565 plugin.reverseRightAlignedItems = function() { 566 if ( ! $("body").hasClass("rtl") && $menu.hasClass("mega-menu-horizontal") ) { 567 $menu.append($menu.children("li.mega-item-align-right").get().reverse()); 568 } 569 }; 570 571 plugin.addClearClassesToMobileItems = function() { 572 $(".mega-menu-row", $menu).each(function() { 573 $("> .mega-sub-menu > .mega-menu-column:not(.mega-hide-on-mobile)", $(this)).filter(":even").addClass("mega-menu-clear"); // :even is 0 based 574 }); 575 }; 576 577 plugin.initDesktop = function() { 578 $menu.data("view", "desktop"); 579 plugin.bindMegaMenuEvents(); 580 plugin.initIndicators(); 581 }; 582 583 plugin.switchToDesktop = function() { 584 $menu.data("view", "desktop"); 585 plugin.bindMegaMenuEvents(); 586 plugin.reverseRightAlignedItems(); 587 plugin.hideAllPanels(); 588 plugin.hideMobileMenu(true); 589 }; 590 591 plugin.initMobile = function() { 592 plugin.switchToMobile(); 593 }; 594 595 plugin.switchToMobile = function() { 596 $menu.data("view", "mobile"); 597 plugin.bindMegaMenuEvents(); 598 plugin.initIndicators(); 599 plugin.reverseRightAlignedItems(); 600 plugin.addClearClassesToMobileItems(); 601 plugin.hideAllPanels(); 602 plugin.expandMobileSubMenus(); 603 }; 604 605 plugin.initToggleBar = function() { 606 $toggle_bar.on("click", function(e) { 607 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") ) { 608 e.preventDefault(); 609 610 if ($(this).hasClass("mega-menu-open")) { 611 plugin.hideMobileMenu(); 612 } else { 613 plugin.showMobileMenu(); 614 } 615 } 616 }); 617 }; 618 619 plugin.initIndicators = function() { 620 $(".mega-indicator", $menu).not("[data-has-click-event]").on("click.megamenu", function(e) { 621 e.preventDefault(); 622 e.stopPropagation(); 623 624 if ( $(this).closest(".mega-menu-item").hasClass("mega-toggle-on") ) { 625 if ( ! $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") || plugin.isMobileView() ) { 626 plugin.hidePanel($(this).parent(), false); 627 } 628 } else { 629 plugin.showPanel($(this).parent(), false); 630 } 631 }); 632 633 $(".mega-indicator", $menu).each(function() { 634 $(this).attr('data-has-click-event', 'true'); 635 }); 636 } 637 638 plugin.hideMobileMenu = function(force) { 639 force = force || false; 640 641 if ( ! $toggle_bar.is(":visible") && ! force ) { 642 return; 643 } 644 645 html_body_class_timeout = setTimeout(function() { 646 $("body").removeClass($menu.attr("id") + "-mobile-open"); 647 $("html").removeClass($menu.attr("id") + "-off-canvas-open"); 648 }, plugin.settings.effect_speed_mobile); 649 650 $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "false"); 651 652 if (plugin.settings.effect_mobile === "slide" && ! force ) { 653 $menu.animate({"height":"hide"}, plugin.settings.effect_speed_mobile, function() { 654 $menu.css({ 655 width: "", 656 left: "", 657 display: "" 658 }); 659 660 $toggle_bar.removeClass("mega-menu-open"); 661 }); 662 } else { 663 $menu.css({ 664 width: "", 665 left: "", 666 display: "" 667 }); 668 669 $toggle_bar.removeClass("mega-menu-open"); 670 } 671 672 $menu.triggerHandler("mmm:hideMobileMenu"); 673 }; 674 675 plugin.showMobileMenu = function() { 676 if ( ! $toggle_bar.is(":visible")) { 677 return; 678 } 679 680 clearTimeout(html_body_class_timeout); 681 682 $("body").addClass($menu.attr("id") + "-mobile-open"); 683 684 plugin.expandMobileSubMenus(); 685 686 if ( plugin.settings.effect_mobile === "slide_left" || plugin.settings.effect_mobile === "slide_right" ) { 687 $("html").addClass($menu.attr("id") + "-off-canvas-open"); 688 } 689 690 $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "true"); 691 692 if (plugin.settings.effect_mobile === "slide") { 693 $menu.animate({"height":"show"}, plugin.settings.effect_speed_mobile, function() { 694 $(this).css("display", ""); 695 }); 696 } 697 698 $toggle_bar.addClass("mega-menu-open"); 699 700 plugin.toggleBarForceWidth(); 701 702 $menu.triggerHandler("mmm:showMobileMenu"); 703 }; 704 705 plugin.toggleBarForceWidth = function() { 706 if ($(plugin.settings.mobile_force_width).length && ( plugin.settings.effect_mobile === "slide" || plugin.settings.effect_mobile === "disabled" ) ) { 707 var submenu_offset = $toggle_bar.offset(); 708 var target_offset = $(plugin.settings.mobile_force_width).offset(); 709 710 $menu.css({ 711 width: $(plugin.settings.mobile_force_width).outerWidth(), 712 left: (target_offset.left - submenu_offset.left) + "px" 713 }); 714 } 715 }; 716 717 plugin.init = function() { 718 $menu.triggerHandler("before_mega_menu_init"); 719 plugin.settings = $.extend({}, defaults, options); 720 $menu.removeClass("mega-no-js"); 721 722 plugin.initToggleBar(); 723 724 if (plugin.settings.unbind_events === "true") { 725 plugin.unbindAllEvents(); 726 } 727 728 $(window).on("load", function() { 729 plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu)); 730 }); 731 732 if ( plugin.isDesktopView() ) { 733 plugin.initDesktop(); 734 } else { 735 plugin.initMobile(); 736 } 737 738 $(window).resize(function() { 739 plugin.checkWidth(); 740 }); 741 742 $menu.triggerHandler("after_mega_menu_init"); 743 }; 744 745 plugin.init(); 746 }; 747 748 $.fn.maxmegamenu = function(options) { 749 return this.each(function() { 750 if (undefined === $(this).data("maxmegamenu")) { 751 var plugin = new $.maxmegamenu(this, options); 752 $(this).data("maxmegamenu", plugin); 753 } 754 }); 755 }; 756 757 $(function() { 758 $(".max-mega-menu").maxmegamenu(); 759 }); 760}( 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.