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