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