1(function ($) { 2 3 'use strict'; 4 5 let $body, $header, $wrapper, $navigate, menuLockedTimeout; 6 7 const pageOffset = $('#page').offset(); 8 const pageWidth = $('#page').width(); 9 10 const _helpers = { 11 setMobMenuDefaultLeftPosition: (wrap, elem) => { 12 let item = wrap.getBoundingClientRect(); 13 let itemLeftPosition = item.x + pageXOffset; 14 15 $(elem).css({ 16 left: -itemLeftPosition 17 }); 18 }, 19 setMobMenuDefaultMaxHeight: (elem) => { 20 let headerHeight = $wrapper.outerHeight(), 21 windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 22 23 $(elem).css({ 24 maxHeight: windowHeight - headerHeight 25 }); 26 }, 27 getScrollY: () => { 28 return window.pageYOffset || document.documentElement.scrollTop; 29 }, 30 setBodyLocked: (elem) => { 31 $body.data('scroll-position', _helpers.getScrollY()); 32 clearTimeout(menuLockedTimeout); 33 $body.addClass('menu-scroll-locked'); 34 35 let isNoStickyItem = $(elem).closest("#site-header").length; 36 let $vcRow = $(elem).closest(".vc_row"); 37 38 if (isNoStickyItem) { 39 $body.addClass('is-no-sticky'); 40 } else { 41 $body.removeClass('is-no-sticky'); 42 } 43 44 $vcRow.addClass('set-index'); 45 }, 46 unsetBodyLocked: () => { 47 menuLockedTimeout = setTimeout(function () { 48 $body.removeClass('menu-scroll-locked is-no-sticky'); 49 $('.vc_row', $wrapper).removeClass('set-index'); 50 }, 1000); 51 52 if ($body.data('scroll-position')) { 53 window.scrollTo(0, $body.data('scroll-position')) 54 } 55 }, 56 isMobMenuSlidingInit: ($item) => { 57 let result = false;
58 if ($item.hasClass('mobile-view')) { 59 result = true; 60 } 61 62 return result; 63 }, 64 isResponsiveMenuVisible: (elem) => { 65 return elem.parents('.thegem-te-menu').find('.menu-toggle:not(.hamburger-toggle)').is(':visible'); 66 }, 67 isBody: (elem) => { 68 return (/^(?:body|html)$/i).test(elem.tagName); 69 }, 70 getScroll: () => { 71 return { 72 x: window.pageXOffset || document.documentElement.scrollLeft, 73 y: window.pageYOffset || document.documentElement.scrollTop 74 }; 75 }, 76 getScrolls: (elem) => { 77 let element = elem.parentNode, position = {x: 0, y: 0}; 78 while (element && !_helpers.isBody(element)) { 79 position.x += element.scrollLeft; 80 position.y += element.scrollTop; 81 element = element.parentNode; 82 } 83 return position; 84 }, 85 styleString: (elem, style) => { 86 return $(elem).css(style); 87 }, 88 styleNumber: (elem, style) => { 89 return parseInt(_helpers.styleString(elem, style)) || 0; 90 }, 91 topBorder: (elem) => { 92 return _helpers.styleNumber(elem, 'border-top-width'); 93 }, 94 leftBorder: (elem) => { 95 return _helpers.styleNumber(elem, 'border-left-width'); 96 }, 97 getOffset: (elem) => { 98 if (elem.getBoundingClientRect && window.gemBrowser.platform.name != 'ios') { 99 let bound = elem.getBoundingClientRect(), 100 html = elem.ownerDocument.documentElement, 101 htmlScroll = _helpers.getScroll(html), 102 elemScrolls = _helpers.getScrolls(elem), 103 isFixed = (_helpers.styleString(elem, 'position') == 'fixed'); 104 return {
105 x: bound.left + elemScrolls.x + ((isFixed) ? 0 : htmlScroll.x) - html.clientLeft, 106 y: bound.top + elemScrolls.y + ((isFixed) ? 0 : htmlScroll.y) - html.clientTop 107 }; 108 } 109 110 let element = elem, position = {x: 0, y: 0}; 111 if (_helpers.isBody(elem)) return position; 112 113 while (element && !_helpers.isBody(element)) { 114 position.x += element.offsetLeft; 115 position.y += element.offsetTop; 116 117 if (window.gemBrowser.name == 'firefox') { 118 if (!borderBox(element)) { 119 position.x += _helpers.leftBorder(element); 120 position.y += _helpers.topBorder(element); 121 } 122 let parent = element.parentNode; 123 if (parent && _helpers.styleString(parent, 'overflow') != 'visible') { 124 position.x += _helpers.leftBorder(parent); 125 position.y += _helpers.topBorder(parent); 126 } 127 } else if (element != elem && window.gemBrowser.name == 'safari') { 128 position.x += _helpers.leftBorder(element); 129 position.y += _helpers.topBorder(element); 130 } 131 132 element = element.offsetParent; 133 } 134 if (window.gemBrowser.name == 'firefox' && !borderBox(elem)) { 135 position.x -= _helpers.leftBorder(elem); 136 position.y -= _helpers.topBorder(elem); 137 } 138 return position; 139 }, 140 setTranslateValues: (elem) => { 141 if (!elem.length) return; 142 $('.mobile-menu-slide-wrapper', elem).css('transform', ''); 143 elem.css('transform', '').css('margin-left', '').css('margin-top', ''); 144 const style = window.getComputedStyle(elem[0]); 145 const matrix = style['transform'] || style.webkitTransform || style.mozTransform; 146 let x = 0, y = 0; 147 148 // No transform property. Simply return 0 values. 149 if (matrix === 'none' || typeof matrix === 'undefined') { 150 return; 151 } 152 153 // Can either be 2d or 3d transform 154 const matrixType = matrix.includes('3d') ? '3d' : '2d'; 155 const matrixValues = matrix.match(/matrix.*\((.+)\)/)[1].split(', '); 156 157 // 2d matrices have 6 values 158 // Last 2 values are X and Y. 159 // 2d matrices does not have Z value. 160 if (matrixType === '2d') { 161 x = matrixValues[4]; 162 y = matrixValues[5]; 163 } 164 165 // 3d matrices have 16 values 166 // The 13th, 14th, and 15th values are X, Y, and Z 167 if (matrixType === '3d') { 168 x = matrixValues[12]; 169 y = matrixValues[13]; 170 } 171 172 elem.css('transform', 'none').css('margin-left', x + 'px').css('margin-top', y + 'px'); 173 } 174 }; 175 176 const menuScripts = { 177 init: () => { 178 $body = $('body'); 179 $header = $('#site-header'); 180 $wrapper = $('.thegem-template-header'); 181 $navigate = $('.thegem-te-menu > nav'); 182 183 menuScripts.setLayoutView(); 184 menuScripts.onResize(); 185 menuScripts.menuAbsoluteTranslate(); 186 menuScripts.menuDefault(); 187 menuScripts.menuOverlay(); 188 menuScripts.menuHamburger(); 189 menuScripts.mobMenuDefault(); 190 menuScripts.mobMenuSliding(); 191 menuScripts.menuMegaMenu(); 192 menuScripts.menuMegaMenuTemplate(); 193 194 $navigate.addClass('inited'); 195 }, 196 197 setLayoutView: () => { 198 let viewportWidth = window.innerWidth; 199 document.documentElement.style.setProperty('--scrollbar-width', -(window.innerWidth - document.body.clientWidth) + "px"); 200 201 $navigate.each(function (i, nav) { 202 const tabletLandscapeMaxWidth = $(nav).data("desktop-breakpoint"); 203 const tabletLandscapeMinWidth = $(nav).data("tablet-breakpoint"); 204 const tabletPortraitMaxWidth = $(nav).data("tablet-breakpoint") - 1; 205 const tabletPortraitMinWidth = $(nav).data("mobile-breakpoint"); 206 207 if ($(this).data("tablet-landscape") === 'default' && viewportWidth >= tabletLandscapeMinWidth && viewportWidth <= tabletLandscapeMaxWidth) { 208 $(this).removeClass('mobile-view').addClass('desktop-view'); 209 } else if ($(this).data("tablet-portrait") === 'default' && viewportWidth >= tabletPortraitMinWidth && viewportWidth <= tabletPortraitMaxWidth) { 210 $(this).removeClass('mobile-view').addClass('desktop-view'); 211 } else if (viewportWidth <= tabletLandscapeMaxWidth) { 212 $(this).removeClass('desktop-view').addClass('mobile-view'); 213 } else { 214 $(this).removeClass('mobile-view').addClass('desktop-view'); 215 } 216 217 if ($('.menu-id-'+$(this).attr('id')).length) { 218 if ($(this).hasClass('desktop-view')) { 219 $('.menu-id-'+$(this).attr('id')).removeClass('mobile-view').addClass('desktop-view'); 220 } else { 221 $('.menu-id-'+$(this).attr('id')).removeClass('desktop-view').addClass('mobile-view'); 222 } 223 } 224 }); 225 }, 226 227 menuDefault: () => { 228 let $menu = $('.thegem-te-menu__default'); 229
230 $('.nav-menu > li:not(.megamenu-template-enable)', $menu).hover(function () { 231 let $items = $(this).find('ul'); 232 233 let getLevelULByMenu = (item) => { 234 let parentUL = $(item).parent('li').parent('ul'); 235 let level = 0; 236 237 while (!parentUL.is('.nav-menu')) { 238 parentUL = parentUL.parent('li').parent('ul'); 239 level++; 240 } 241 242 return level; 243 }; 244 245 let offset = $header.offset().top + $header.outerHeight() - $(this).offset().top - $(this).outerHeight(); 246 // $item.css('top', 'calc(100% + ' + offset + 'px)'); 247 248 $items.removeClass('invert'); 249 250 if (!$(this).hasClass('megamenu-enable')) { 251 $items.css({top: ''}); 252 } 253 254 if ($(this).hasClass('megamenu-enable') || 255 $(this).closest('.header-layout-overlay').length || 256 $(this).closest('.mobile-menu-layout-overlay').length && _helpers.isResponsiveMenuVisible($(this))) { 257 return; 258 } 259 260 $items.each(function () { 261 let $item = $(this), self = this, $parentList = $item.parent().closest('ul'); 262 263 let itemOffset = $item.offset(), 264 itemOffsetLeft = itemOffset.left; 265 266 let leftItemTranslate = 0; 267 if ($item.css('transform')) { 268 leftItemTranslate = parseInt(getComputedStyle(this).transform.split(',')[4]); 269 let levelUL = getLevelULByMenu(self); 270 if (levelUL > 0) { 271 leftItemTranslate = leftItemTranslate * levelUL; 272 } 273 } 274 if (isNaN(leftItemTranslate)) leftItemTranslate = 0; 275 276 if ($parentList.hasClass('invert')) { 277 if ($parentList.offset().left - $item.outerWidth() > pageOffset.left) { 278 $item.addClass('invert'); 279 } 280 } else { 281 if (itemOffsetLeft - leftItemTranslate - pageOffset.left + $item.outerWidth() > pageWidth) { 282 $item.addClass('invert'); 283 } 284 } 285 }); 286 }); 287 }, 288 289 menuOverlay: () => { 290 let $menus = $('.thegem-te-menu__overlay, .thegem-te-menu-mobile__overlay'); 291 292 $menus.each(function (i, el) { 293 let $menuItem = $(el); 294 let $menuWrap = $('.overlay-menu-wrapper', $menuItem); 295 let $overlay = $('.overlay-menu-back', $menuItem); 296 let $toggle = $('.overlay-toggle', $menuItem); 297 298 // Toggle overlay menu 299 $menuItem.on('click', '.overlay-toggle', function (e) { 300 e.preventDefault(); 301 302 if ($overlay.hasClass('active')) { 303 _helpers.unsetBodyLocked(); 304 $overlay.removeClass('active'); 305 $menuItem.addClass('close'); 306 $menuItem.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function (e) { 307 $menuItem.removeClass('overlay-active close'); 308 $menuWrap.removeClass('active'); 309 }); 310 } else { 311 _helpers.setBodyLocked(this); 312 $menuWrap.addClass('active'); 313 $overlay.addClass('active'); 314 $menuItem.off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend'); 315 $menuItem.addClass('overlay-active').removeClass('close'); 316 } 317 }); 318 319 // Close overlay menu ESC click 320 $(document).on('keydown', function (event) { 321 if (event.keyCode === 27 && $overlay.hasClass('active')) { 322 $toggle.click(); 323 } 324 }); 325 326 // Close overlay menu overlay click 327 $overlay.on('click', function (e) { 328 $toggle.click(); 329 }); 330 331 $menuWrap.on('click', function (e) { 332 let $notClick = $menuWrap.find('li'); 333 if ($notClick.has(e.target).length === 0) { 334 //$toggle.click(); 335 } 336 }); 337 338 // Toggle overlay menu list 339 $('.menu-item-parent-toggle', $menuWrap).on('click', function (e) { 340 e.preventDefault(); 341 e.stopPropagation(); 342 343 let $itemLink = $(this); 344 let $item = $itemLink.closest('li'); 345 346 if ($item.hasClass('menu-item-parent') && ($item.closest('ul').hasClass('nav-menu') || $item.parent().closest('li').hasClass('menu-overlay-item-open'))) { 347 e.preventDefault(); 348 349 if ($item.hasClass('menu-overlay-item-open')) { 350 $(' > ul, .menu-overlay-item-open > ul', $item).each(function () { 351 $(this).css({height: $(this).outerHeight() + 'px'}); 352 }); 353 354 setTimeout(function () { 355 $(' > ul, .menu-overlay-item-open > ul', $item).css({height: ''}); 356 $('.menu-overlay-item-open', $item).add($item).removeClass('menu-overlay-item-open'); 357 }, 50); 358 } else { 359 let $oldActive = $('.nav-menu .menu-overlay-item-open').not($item.parents()); 360 $('> ul', $oldActive).not($item.parents()).each(function () { 361 $(this).css({height: $(this).outerHeight() + 'px'}); 362 }); 363 setTimeout(function () { 364 $('> ul', $oldActive).not($item.parents()).css({height: ''}); 365 $oldActive.removeClass('menu-overlay-item-open'); 366 }, 50); 367 368 $('> ul', $item).css({height: 'auto'}); 369 let itemHeight = $('> ul', $item).outerHeight(); 370 $('> ul', $item).css({height: ''}); 371 setTimeout(function () { 372 $('> ul', $item).css({height: itemHeight + 'px'}); 373 $item.addClass('menu-overlay-item-open'); 374 $('> ul', $item).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () { 375 $('> ul', $item).css({height: 'auto'}); 376 }); 377 }, 50); 378 } 379 } 380 }); 381 382 $(document).on('click', '.menu-item.mobile-collapsible > a', function(e) { 383 if (!_helpers.isResponsiveMenuVisible($menuItem)) { 384 return; 385 } 386 387 if($(this).next('.menu-item-parent-toggle').length) { 388 e.preventDefault(); 389 $(this).next('.menu-item-parent-toggle').trigger('click'); 390 } 391 }); 392 393 // Toggle search widget 394 $('.menu-item-type-search-widget', $menuWrap).on('click', 'a', function(e) { 395 e.preventDefault(); 396 if ($(this).closest('.menu-item-fullscreen-search-mobile').length) return; 397 398 if($(this).closest('.overlay-menu-wrapper.active').length) { 399 let $primaryMenu = $('.nav-menu'); 400 $primaryMenu.addClass('overlay-search-form-show animated-minisearch'); 401 $('.sf-input', $primaryMenu).focus(); 402 403 setTimeout(function() { 404 $(document).on('click.menu-item-search-close', 'body', function(e) { 405 if(!$(e.target).is('.menu-item-type-search-widget .minisearch *')) { 406 let $primaryMenu = $('.nav-menu'); 407 408 if ($primaryMenu.hasClass('animated-minisearch')) { 409 $primaryMenu.removeClass('animated-minisearch'); 410 411 setTimeout(function() { 412 $primaryMenu.removeClass('overlay-search-form-show'); 413 $(document).off('click.menu-item-search-close'); 414 }, 700); 415 416 } else { 417 $primaryMenu.removeClass('overlay-search-form-show'); 418 $(document).off('click.menu-item-search-close'); 419 } 420 } 421 }); 422 }, 500); 423 } else { 424 $('.menu-item-type-search-widget').toggleClass('active'); 425 } 426 }); 427 428 }); 429 }, 430 431 menuHamburger: () => { 432 let $menus = $('.thegem-te-menu__hamburger'); 433 434 $menus.each(function (i, el) { 435 let $menuItem = $(el);
436 let $overlay = $('.hamburger-menu-back', $menuItem); 437 let $toggle = $('.hamburger-toggle', $menuItem); 438 439 // Toggle hamburger menu 440 $menuItem.on('click', '.hamburger-toggle', function (e) { 441 e.preventDefault(); 442 443 if ($overlay.hasClass('active')) { 444 _helpers.unsetBodyLocked(); 445 $menuItem.removeClass('hamburger-active'); 446 $overlay.removeClass('active'); 447 } else { 448 _helpers.setBodyLocked(this); 449 $menuItem.addClass('hamburger-active'); 450 $overlay.addClass('active'); 451 } 452 }); 453 454 $(document).on('keydown', function (event) { 455 if (event.keyCode === 27 && $overlay.hasClass('active')) { 456 $toggle.click(); 457 } 458 }); 459 460 $overlay.on('click', function () { 461 $toggle.click(); 462 }); 463 }); 464 }, 465 466 mobMenuDefault: () => { 467 //dl-menu support for css animations and transitions 468 let supportsTransitions = () => { 469 return getSupportedTransition() != ''; 470 } 471 let getSupportedTransition = () => { 472 let b = document.body || document.documentElement, 473 s = b.style, 474 p = 'transition'; 475 476 if (typeof s[p] == 'string') { 477 return p; 478 } 479 480 // Tests for vendor specific prop 481 let v = ['Moz', 'webkit', 'Webkit', 'Khtml', 'O', 'ms']; 482 p = p.charAt(0).toUpperCase() + p.substr(1); 483 484 for (let i = 0; i < v.length; i++) { 485 if (typeof s[v[i] + p] == 'string') { 486 return true; 487 } 488 } 489 490 return ''; 491 } 492 let supportsAnimations = () => { 493 return getSupportedAnimation() != ''; 494 } 495 let getSupportedAnimation = () => { 496 let t, el = document.createElement("fakeelement"); 497 498 let animations = { 499 "animation": "animationend", 500 "OAnimation": "oAnimationEnd", 501 "MozAnimation": "animationend", 502 "WebkitAnimation": "webkitAnimationEnd", 503 'msAnimation': 'MSAnimationEnd' 504 }; 505 506 for (t in animations) { 507 if (el.style[t] !== undefined) { 508 return t; 509 } 510 } 511 return ''; 512 } 513 window.supportedTransition = getSupportedTransition(); 514 window.supportsTransitions = supportsTransitions(); 515 window.supportedAnimation = getSupportedAnimation(); 516 window.supportsAnimations = supportsAnimations(); 517 518 let $menus = $('.thegem-te-menu-mobile__default'); 519 $menus.each(function (i, el) { 520 //dl-menu init 521 let $menuItem = $(el); 522 $menuItem.find('.sub-menu').addClass('dl-submenu'); 523 524 $menuItem.dlmenu({ 525 animationClasses: { 526 classin: 'dl-animate-in', 527 classout: 'dl-animate-out' 528 }, 529 backLabel: thegem_menu_data.backLabel, 530 showCurrentLabel: thegem_menu_data.showCurrentLabel 531 }); 532 533 // close menu after click not parent item 534 $('li:not(.menu-item-has-children):not(.dl-back)', $menuItem).on('click', 'a', function (e) { 535 if (typeof $.fn.dlmenu === 'function') { 536 $menuItem.dlmenu('closeMenu'); 537 } 538 }); 539 540 //dl-menu navmenu/submenu set maxHeight && left position 541 let navMenu = $menuItem.find('ul').not('.menu-item-type-template ul'); 542 _helpers.setMobMenuDefaultMaxHeight(navMenu); 543 _helpers.setMobMenuDefaultLeftPosition(el, navMenu); 544 545 //dl-menu resize 546 $(window).on('resize', function (e) { 547 setTimeout(function () { 548 _helpers.setMobMenuDefaultMaxHeight(navMenu); 549 _helpers.setMobMenuDefaultLeftPosition(el, navMenu); 550 }, 1000); 551 }); 552 }); 553 }, 554 555 mobMenuSliding: () => { 556 let $menus = $('.thegem-te-menu-mobile__slide-horizontal, .thegem-te-menu-mobile__slide-vertical'); 557 window.isMobMenuSliding = _helpers.isMobMenuSlidingInit($menus); 558 559 $menus.each(function (i, el) { 560 let $menuItem = $(el); 561 let $menuWrap = $('.mobile-menu-slide-wrapper', $menuItem); 562 let $menuClose = $('.mobile-menu-slide-close', $menuItem); 563 let $overlay = $('.mobile-menu-slide-back', $menuItem); 564 let $toggle = $('.dl-trigger', $menuItem); 565 566 $menuItem.on('click', '.dl-trigger', function (e) { 567 e.preventDefault(); 568 569 //$header.removeClass('hidden'); 570 //$header.toggleClass('menu-slide-opened'); 571 572 if ($overlay.hasClass('active')) { 573 $overlay.removeClass('active'); 574 } else { 575 $overlay.addClass('active'); 576 } 577 578 $menuWrap.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function (e) { 579 $menuWrap.removeClass('animation'); 580 }); 581 $menuWrap.addClass('animation').toggleClass('opened'); 582 583 if ($menuWrap.hasClass('opened')) { 584 _helpers.setBodyLocked(this); 585 } else { 586 _helpers.unsetBodyLocked(); 587 } 588 }); 589 590 $('li.menu-item-current', $menuItem).each(function () { 591 let $self = $(this); 592 $self.addClass('opened'); 593 $('> ul', $self).show(); 594 }); 595 596 $menuClose.on('click', function () { 597 $toggle.click(); 598 }); 599 600 $overlay.on('click', function () { 601 $toggle.click(); 602 }); 603 604 $('.menu-item-parent-toggle', $menuWrap).on('click', function (e) { 605 e.preventDefault(); 606 607 if (!window.isMobMenuSliding) return; 608 609 let self = this; 610 $(this).closest('li').toggleClass('opened'); 611 $(this).siblings('ul').slideToggle(200, function () { 612 if (!$(self).closest('li').hasClass('opened')) { 613 $(self).siblings('ul').find('li').removeClass('opened'); 614 $(self).siblings('ul').css('display', ''); 615 $(self).siblings('ul').find('ul').css('display', ''); 616 } 617 }); 618 }); 619 620 $(document).on('click', '.menu-item.mobile-collapsible > a', function(e) { 621 if (!_helpers.isResponsiveMenuVisible($menuItem)) { 622 return; 623 } 624 625 if($(this).next('.menu-item-parent-toggle').length) { 626 e.preventDefault(); 627 $(this).next('.menu-item-parent-toggle').trigger('click'); 628 } 629 }); 630 631 $('.menu-item-parent-toggle', $menuWrap).on('keydown', function(e) { 632 if (e.which === 13) { 633 e.preventDefault(); 634 $(this).trigger('click'); 635 } 636 }); 637 638 // Close overlay menu ESC click 639 $(document).on('keydown', function (event) { 640 if (event.keyCode === 27 && $overlay.hasClass('active')) { 641 $toggle.click(); 642 } 643 }); 644 645 }); 646 }, 647 648 onResize: () => { 649 let resizeTimer; 650 $(window).on('resize', function (e) { 651 clearTimeout(resizeTimer); 652 653 resizeTimer = setTimeout(function () { 654 menuScripts.setLayoutView(); 655 menuScripts.menuAbsoluteTranslate(); 656 657 let $menuSliding = $('.thegem-te-menu-mobile__slide-horizontal, .thegem-te-menu-mobile__slide-vertical'); 658 window.isMobMenuSliding = _helpers.isMobMenuSlidingInit($menuSliding); 659 }, 250); 660 }); 661 }, 662 663 menuMegaMenu: () => { 664 let $megaMenuItems = $('.thegem-te-menu .nav-menu > li.megamenu-enable'); 665 666 $megaMenuItems.each(function () { 667 if ($(this).parents('.thegem-te-menu > nav').hasClass("thegem-te-menu__overlay")) { 668 $(this).removeClass('megamenu-enable'); 669 return; 670 } 671 menuScripts.fixMegaMenuPosition($(this)); 672 let $item = $('> ul', $(this)); 673 if ($item.length == 0) return; 674 $item.addClass('megamenu-item-inited'); 675 676 $(this).hover( 677 function () { 678 menuScripts.fixMegaMenuPosition($(this)); 679 }, 680 function () { 681 } 682 ); 683 }); 684 }, 685 686 fixMegaMenuPosition: (elem, containerWidthCallback) => { 687 688 let isMenuVertical = false;
689 let isMenuPerspective = false; 690 let isMenuHamburger = elem.parents('.thegem-te-menu > nav').hasClass("thegem-te-menu__hamburger"); 691 692 if (!$('.megamenu-inited', elem).length && _helpers.isResponsiveMenuVisible(elem)) { 693 return false; 694 } 695 696 let $item = $('> ul', elem); 697 if ($item.length == 0) return; 698 let self = $item.get(0); 699 700 $item.addClass('megamenu-item-inited'); 701 702 let default_item_css = { 703 width: 'auto', 704 height: 'auto' 705 }; 706 707 if (!isMenuVertical && !isMenuHamburger && !isMenuPerspective) { 708 default_item_css.left = 0; 709 } 710 711 $item 712 .removeClass('megamenu-masonry-inited megamenu-fullwidth') 713 .css(default_item_css); 714 715 $(' > li', $item).css({ 716 left: 0, 717 top: 0 718 }).each(function () { 719 let old_width = $(this).data('old-width') || -1; 720 if (old_width != -1) { 721 $(this).width(old_width).data('old-width', -1); 722 } 723 }); 724 725 if (_helpers.isResponsiveMenuVisible(elem)) { 726 return; 727 } 728 729 let $container = $item.closest('.vc_column-inner'), 730 container_width, 731 container_padding_left, 732 container_padding_right, 733 parent_width; 734 if (containerWidthCallback !== undefined) { 735 container_width = containerWidthCallback(); 736 } else if (isMenuVertical) { 737 container_width = window.gemOptions.clientWidth - $('#site-header-wrapper').outerWidth(); 738 } else if (isMenuPerspective) { 739 container_width = window.gemOptions.clientWidth - $('#primary-navigation').outerWidth(); 740 } else if (isMenuHamburger) { 741 container_width = window.gemOptions.clientWidth - $('.thegem-te-menu .nav-menu').outerWidth(); 742 } else { 743 container_width = $container.width(); 744 container_padding_left = parseInt($container.css('padding-left')); 745 container_padding_right = parseInt($container.css('padding-right')); 746 parent_width = $item.parent().outerWidth(); 747 } 748 749 let megamenu_width = $item.outerWidth(); 750 751 if (megamenu_width > container_width) { 752 megamenu_width = container_width; 753 let new_megamenu_width = container_width - parseInt($item.css('padding-left')) - parseInt($item.css('padding-right')) - parseInt($item.css('border-left')) - parseInt($item.css('border-right')); 754 let columns = $item.data('megamenu-columns') || 4; 755 let margin = 0; 756 $(' > li.menu-item', $item).each(function (index) { 757 if (index < columns) { 758 margin += parseInt($(this).css('margin-left')); 759 } 760 }); 761 let column_width = parseFloat(new_megamenu_width - margin) / columns; 762 let column_width_int = parseInt(column_width); 763 $(' > li', $item).each(function () { 764 $(this).data('old-width', $(this).width()).css('width', column_width_int); 765 }); 766 let columns_dif = (column_width - column_width_int) * columns; 767 $(' > li.megamenu-first-element', $item).css('width', column_width_int + columns_dif); 768 $item.addClass('megamenu-fullwidth').width(new_megamenu_width); 769 } 770 771 if (!isMenuVertical && !isMenuHamburger && !isMenuPerspective && containerWidthCallback === undefined) { 772 let left = 0; 773 if (megamenu_width > parent_width) { 774 left = -(megamenu_width - parent_width) / 2; 775 } 776 777 let container_offset = _helpers.getOffset($container[0]); 778 let megamenu_offset = _helpers.getOffset(self); 779 780 if ((megamenu_offset.x - container_offset.x - container_padding_left + left) < 0) { 781 left = -(megamenu_offset.x - container_offset.x - container_padding_left); 782 } 783 784 if ((megamenu_offset.x + megamenu_width + left) > (container_offset.x + $container.outerWidth() - container_padding_right)) { 785 left -= (megamenu_offset.x + megamenu_width + left) - (container_offset.x + $container.outerWidth() - container_padding_right); 786 } 787 788 $item.css('left', left).css('left'); 789 } 790 791 if ($item.hasClass('megamenu-masonry')) { 792 let positions = {}, 793 max_bottom = 0; 794 795 if (!$item.hasClass('megamenu-fullwidth')) { 796 $item.width($item.width() - 1); 797 } 798 let new_row_height = $('.megamenu-new-row', $item).outerHeight() + parseInt($('.megamenu-new-row', $item).css('margin-bottom')); 799 800 $('> li.menu-item', $item).each(function () { 801 let pos = $(this).position(), 802 top_position; 803 if (positions[pos.left] != null && positions[pos.left] != undefined) { 804 top_position = positions[pos.left]; 805 } else { 806 top_position = pos.top; 807 } 808 positions[pos.left] = top_position + $(this).outerHeight() + new_row_height + parseInt($(this).css('margin-bottom')); 809 if (positions[pos.left] > max_bottom) 810 max_bottom = positions[pos.left]; 811 $(this).css({ 812 left: pos.left, 813 top: top_position 814 }) 815 }); 816 817 $item.height(max_bottom - new_row_height - parseInt($item.css('padding-top'))); 818 $item.addClass('megamenu-masonry-inited'); 819 } 820 821 if ($item.hasClass('megamenu-empty-right')) { 822 let mega_width = $item.width(); 823 let max_rights = { 824 columns: [], 825 position: -1 826 }; 827 828 $('> li.menu-item', $item).removeClass('megamenu-no-right-border').each(function () { 829 let pos = $(this).position();
830 let column_right_position = pos.left + $(this).width(); 831 832 if (column_right_position > max_rights.position) { 833 max_rights.position = column_right_position; 834 max_rights.columns = []; 835 } 836 837 if (column_right_position == max_rights.position) { 838 max_rights.columns.push($(this)); 839 } 840 }); 841 842 if (max_rights.columns.length && max_rights.position >= (mega_width - 7)) { 843 max_rights.columns.forEach(function ($li) { 844 $li.addClass('megamenu-no-right-border'); 845 }); 846 } 847 } 848 849 if (isMenuVertical || isMenuHamburger || isMenuPerspective) { 850 let clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, 851 itemOffset = $item.offset(), 852 itemHeight = $item.outerHeight(), 853 scrollTop = $(window).scrollTop(); 854 855 if (itemOffset.top - scrollTop + itemHeight > clientHeight) { 856 $item.css({ 857 top: clientHeight - itemOffset.top + scrollTop - itemHeight - 20 858 }); 859 } 860 } 861 862 $item.addClass('megamenu-inited'); 863 }, 864 865 menuMegaMenuTemplate: () => { 866 let $megaMenuItems = $('.thegem-te-menu .nav-menu > li.megamenu-template-enable'); 867 868 $megaMenuItems.each(function () { 869 if ($(this).parents('.thegem-te-menu > nav').hasClass("thegem-te-menu__overlay")) { 870 $(this).removeClass('megamenu-template-enable'); 871 $(this).find('.megamenu-template').remove(); 872 return; 873 } 874 875 let $item = $('.megamenu-template', $(this)); 876 if ($item.length == 0) return; 877 menuScripts.fixMegaMenuTemplatePosition($(this)); 878 879 if ($item.data('template')) { 880 let templateID = $item.data('template'); 881 $.ajax({ 882 url: thegem_menu_data.ajax_url, 883 data: { 884 'action': 'get_megamenu_template', 885 'id': templateID 886 }, 887 dataType: 'json', 888 method: 'POST', 889 success: function (response) { 890 if (response.status === 'success') { 891 $item.html(response.data); 892 } 893 }, 894 error: function () { 895 console.log('loading megamenu template ajax error'); 896 } 897 }); 898 } 899 $item.addClass('megamenu-template-item-inited'); 900 901 $(this).hover( 902 function () { 903 menuScripts.fixMegaMenuTemplatePosition($(this)); 904 }, 905 function () { 906 } 907 ); 908 }); 909 }, 910 911 fixMegaMenuTemplatePosition: (elem, containerWidthCallback) => { 912 913 let isMenuVertical = false;
914 let isMenuPerspective = false; 915 let isMenuHamburger = elem.parents('.thegem-te-menu > nav').hasClass("thegem-te-menu__hamburger"); 916 917 if (!$('.megamenu-template-inited', elem).length && _helpers.isResponsiveMenuVisible(elem)) { 918 return false; 919 } 920 921 let $item = $('.megamenu-template', elem); 922 if ($item.length == 0) return; 923 let self = $item.get(0); 924 925 $item.addClass('megamenu-template-item-inited'); 926 let isWidth100 = $item.hasClass("template-width-fullwidth"); 927 928 let default_item_css = { 929 // width: 'auto', 930 // height: 'auto' 931 }; 932 933 if (!isMenuVertical && !isMenuHamburger && !isMenuPerspective) { 934 default_item_css.left = 0; 935 } 936 937 $item.css(default_item_css); 938 939 if (_helpers.isResponsiveMenuVisible(elem)) { 940 return; 941 } 942 943 let $container = $item.closest('.vc_column-inner'), 944 container_width, 945 container_padding_left, 946 container_padding_right, 947 parent_width; 948 if (containerWidthCallback !== undefined) { 949 container_width = containerWidthCallback(); 950 } else if (isMenuVertical) { 951 container_width = window.gemOptions.clientWidth - $('#site-header-wrapper').outerWidth(); 952 } else if (isMenuPerspective) { 953 container_width = window.gemOptions.clientWidth - $('#primary-navigation').outerWidth(); 954 } else if (isMenuHamburger) { 955 container_width = window.gemOptions.clientWidth - $('.thegem-te-menu .nav-menu').outerWidth(); 956 } else { 957 container_width = $container.width(); 958 container_padding_left = parseFloat($container.css('padding-left')); 959 container_padding_right = parseFloat($container.css('padding-right')); 960 parent_width = $item.parent().outerWidth(); 961 } 962 963 let megamenu_width = $item.outerWidth(); 964 965 if (isWidth100 || megamenu_width > document.body.clientWidth) { 966 $item.css('width', document.body.clientWidth); 967 } else if ($item.hasClass("template-width-boxed") && !isMenuVertical && !isMenuHamburger && !isMenuPerspective) { 968 $item.css('width', container_width); 969 } 970 megamenu_width = $item.outerWidth(); 971 972 if (!isMenuVertical && !isMenuHamburger && !isMenuPerspective && containerWidthCallback === undefined) { 973 let left = 0; 974 975 let container_offset = _helpers.getOffset($container[0]); 976 let megamenu_offset = _helpers.getOffset(self); 977 978 if (isWidth100) { 979 left = -megamenu_offset.x; 980 } else { 981 if (megamenu_width > container_width) { 982 left = container_offset.x - megamenu_offset.x - (megamenu_width - container_width)/2; 983 } else if (megamenu_width === container_width) { 984 left = container_offset.x - megamenu_offset.x + container_padding_left; 985 } else { 986 987 if (megamenu_width > parent_width) { 988 left = -(megamenu_width - parent_width) / 2; 989 } 990 991 if ((megamenu_offset.x - container_offset.x - container_padding_left + left) < 0) { 992 left = -(megamenu_offset.x - container_offset.x - container_padding_left); 993 } 994 995 if ((megamenu_offset.x + megamenu_width + left) > (container_offset.x + $container.outerWidth() - container_padding_right)) { 996 left -= (megamenu_offset.x + megamenu_width + left) - (container_offset.x + $container.outerWidth() - container_padding_right); 997 } 998 } 999 } 1000 1001 $item.css('left', left).css('left'); 1002 } 1003 1004 if (isMenuVertical || isMenuHamburger || isMenuPerspective) { 1005 if (megamenu_width > container_width) { 1006 $item.css('width', container_width); 1007 } 1008 let clientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight, 1009 itemOffset = $item.offset(), 1010 itemHeight = $item.outerHeight(), 1011 scrollTop = $(window).scrollTop(); 1012 1013 if (itemOffset.top - scrollTop + itemHeight > clientHeight) { 1014 $item.css({ 1015 top: clientHeight - itemOffset.top + scrollTop - itemHeight - 20 1016 }); 1017 } 1018 } 1019 1020 $item.addClass('megamenu-template-inited'); 1021 }, 1022 1023 menuAbsoluteTranslate: () => { 1024 $navigate.each(function (i, el) { 1025 let $menuWidget = $(this).parents('.elementor-widget'); 1026 _helpers.setTranslateValues($menuWidget); 1027 }); 1028 }, 1029 }; 1030 1031 // Run the function 1032 $(function () { 1033 menuScripts.init(); 1034 }); 1035})(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.