1/* 2* Mega Menu script made by Denis Odintsov for Unlimited Elements 3*/ 4 5function ueMegaMenu(){ 6 7 var g_menu, g_menuSection, g_menuItem, g_menuListWrap, g_indicator, g_translateX, g_menuList, g_objBody, g_objHtml, g_dataMenuOpen, g_objOverlay, g_menuWrapOffsetLeft, g_viewportWidth, g_dataPositionX, g_dataEditor, g_menuItemTitle, g_showErrors, g_offsetX, g_urlBase, g_dataCloseDelay; 8 var g_classActive, g_classSection, g_menuActiveClass; 9 var g_isDesktopViewport, g_isNotDesktopViewport, g_isCustomResponsiveViewport, g_isNotCustomResponsiveViewport; 10 var g_arrItems; 11 12 /* 13 * apply template's styles to menu item's section 14 */ 15 function setTemplateStyle(){ 16 17 var objLayout = jQuery('.uc-template-wrapper .elementor'); 18 var objLayoutClass = objLayout.attr('class'); 19 20 g_menu.addClass(objLayoutClass); 21 } 22 23 /* 24 * hide expand icon if no item section found 25 */ 26 function hideIcon(objSection){ 27 28 if(g_indicator.length == 0) 29 return(false); 30 31 var objSectionArrow = objSection.find(".sub-arrow"); 32 var objSectionTitle = objSection.find('.uc-mega_menu_title'); 33 var dataClickable = objSectionTitle.data('clickable-link'); 34 35 if(dataClickable == false) 36 return(false); 37 38 if(dataClickable == true && g_dataMenuOpen == 'click') 39 objSectionArrow.hide(); 40 } 41 42 /* 43 * clone sections and append to its parent item 44 */ 45 function findSections(objSection, menuSectionParent, menuSectionItem, firstMenuSectionParent){ 46 47 //use clone mentod id in editor and detach method if live page 48 var clonedSectionItem; 49 50 if(g_dataEditor == 'yes') 51 clonedSectionItem = menuSectionItem.clone(); 52 53 if(g_dataEditor == 'no') 54 clonedSectionItem = menuSectionItem.detach(); 55 56 menuSectionParent.html(clonedSectionItem); 57 58 hideIcon(objSection); 59 60 var objMenuSection = menuSectionParent.children(); 61 objMenuSection.addClass("uc-connected"); 62 63 if(!objMenuSection.hasClass("uc-connected")) 64 return(true); 65 66 setTimeout(function(){ 67 68 objMenuSection.css({ 69 'position': 'absolute', 70 'visibility': 'hidden' 71 }); 72 73 var dataOpenFirstItem = g_menuList.data('open-first'); 74 75 if(dataOpenFirstItem == false) 76 return(false); 77 78 var firstObjMenuSection = firstMenuSectionParent.children(); 79 80 firstObjMenuSection.css({ 81 'position': '', 82 'visibility': 'visible' 83 }); 84 85 }, 200) 86 } 87 88 /* 89 * handle section find error 90 */ 91 function showHideErrors(objSection, menuSectionId, menuSectionParent, menuSectionItem) { 92 93 if(g_showErrors == false) 94 return(false); 95 96 if(menuSectionItem.length > 0) 97 return(false); 98 99 var menuItemTitle = objSection.find('.uc-mega_menu_title'); 100 var menuItemTitleType = menuItemTitle.data('type'); 101 102 if(menuItemTitleType == 'link') 103 return(false); 104 105 objSection.addClass('section-error'); 106 menuSectionParent.addClass('section-error'); 107 108 menuSectionParent.html("<div class='uc-section-error'><div class='uc-error'>Couldn't find a section with id: '" + menuSectionId + "'</div></div>"); 109 } 110 111 /* 112 * handle debug hidden template / section 113 */ 114 function debugHiddenElements() { 115 116 if(g_dataEditor == 'no') 117 return(false); 118 119 //find template for debugging purposes 120 var menuTemplate = jQuery(".uc-template-wrapper"); 121 var dataDebug = g_menu.data("debug"); 122 123 if(dataDebug == false) 124 return(false); 125 126 menuTemplate.css({'display': ''}); 127 } 128 129 /* 130 * set dropdown element full width and position in case custom width is grater than viewport width 131 */ 132 function setFullWidth(menuSectionParent){ 133 134 menuSectionParent.css({ 135 'width': g_viewportWidth + 'px', 136 'top': '100%', 137 'left': - g_menuWrapOffsetLeft + 'px', 138 'transform': 'translate(0, 0)', 139 'right': 'unset' 140 }); 141 142 var menuItemParent = menuSectionParent.parents(".uc-mega_menu_list_item"); 143 144 //set static position to menu-item so dropdown is positioned relatively to menu-list-wrapper 145 menuItemParent.css({ 146 'position': 'static' 147 }); 148 } 149 150 /* 151 * set dropdown element position left 152 */ 153 function setScreenStartPos(menuSectionParent){ 154 155 menuSectionParent.css({ 156 'left': - g_menuWrapOffsetLeft + 'px', 157 'transform': 'translate(0, 0)' 158 }); 159 160 //find 'elementor' parents and set left positin css propery so mega menu section were positioned with respect to 'elementor' element 161 var objElementorParent = g_menu.parents('.elementor'); 162 163 if(objElementorParent.length > 0){ 164 165 var elementorParentOffsetLeft = jQuery(objElementorParent[0]).offset().left; 166 167 menuSectionParent.css({ 168 'left': - g_menuWrapOffsetLeft + elementorParentOffsetLeft + 'px', 169 }); 170 171 } 172 173 } 174 175 /* 176 * set position / width 177 */ 178 function setWidthType(widthType, widthTypeFull, widthTypeCustom, customWidthNumber, menuSectionParent, each){ 179 180 //find 'elementor' parents and set max width property 181 var objElementorParent = g_menu.parents('.elementor'); 182 183 if(objElementorParent.length > 0){ 184 185 var elementorParentWidth = jQuery(objElementorParent[0]).width(); 186 187 menuSectionParent.css({'max-width': elementorParentWidth + 'px'}); 188 189 } 190 191 if(widthType == widthTypeFull){ 192 setScreenStartPos(menuSectionParent); 193 menuSectionParent.css({'width': g_viewportWidth + 'px'}); 194 return(false); 195 } 196 197 if(widthType == widthTypeCustom){ 198 menuSectionParent.css({'width': customWidthNumber + 'px'}); 199 } 200 201 if(customWidthNumber == '0' || customWidthNumber == '' || customWidthNumber >= g_viewportWidth){ 202 setFullWidth(menuSectionParent); 203 }else{ 204 205 //set position relative back when dropdown again can be fully visible in the screen 206 g_menuItem.eq(each).css({'position': 'relative'}); 207 208 //return values that were set before change of the width to full-width 209 if (g_dataPositionX == "item_left"){ 210 menuSectionParent.css({ 211 'left': '0' 212 }); 213 } 214 215 if (g_dataPositionX == "item_right"){ 216 menuSectionParent.css({ 217 'left': 'unset', 218 'right': '0' 219 }); 220 } 221 222 if (g_dataPositionX == "item_center"){ 223 menuSectionParent.css({ 224 'left': '50%', 225 'right': 'unset' 226 }); 227 } 228 229 } 230 } 231 232 /* 233 * set position / width for each type of width-type 234 */ 235 function handleWidthType(){ 236 237 var menuItemsNumber = g_menuItem.length; 238 239 for (let i=0; i<menuItemsNumber; i++){ 240 241 var menuSectionParent = g_menuItem.eq(i).find('.uc-mega_menu_section'); 242 243 var widthType = g_arrItems[i].dropdown_width; 244 var customWidthNumber = g_arrItems[i].dropdown_width_number; 245 246 setWidthType(widthType, 'full', 'custom', customWidthNumber, menuSectionParent, i); 247 248 if(widthType == 'default'){ 249 250 var defaultWidthType = g_menuList.data('default-width-type'); 251 var defaultWidthNumber = g_menuList.data('default-width-number'); 252 253 setWidthType(defaultWidthType, 'default_full', 'default_custom', defaultWidthNumber, menuSectionParent, i) 254 } 255 } 256 } 257 258 /* 259 * debug items ids 260 */ 261 function showHideMenuItemsId(){ 262 263 var debugMenuItemsId = g_menu.data("items-id"); 264 265 if (debugMenuItemsId == false) 266 return(false); 267 268 //show all item ids 269 g_menuListWrap.append("<div class='available_id_s'>Item Id's List<ul class='available_item_id_s_list'></ul></div>"); 270 271 var objItemIdList = g_menu.find(".available_item_id_s_list"); 272 var menuItemsNumber = g_menuItem.length; 273 274 for(let i=0; i<=menuItemsNumber-1; i++){ 275 var objMenuItem = g_menuItem.eq(i); 276 var objMenuItemDataId = objMenuItem.data("id"); 277
278 //if data-id attribute is empty, skip and go to next data-id 279 if(!objMenuItemDataId){ 280 continue; 281 }else{ 282 objItemIdList.append("<li>" + objMenuItemDataId + "</li>"); 283 } 284 } 285 } 286 287 /* 288 * debug elements ids 289 */ 290 function showHideElementsId(){ 291 292 var debugElementsId = g_menu.data("elements-id"); 293 294 if (debugElementsId == false) 295 return(false); 296 297 //show list of section's ids that can be connected to mega menu items 298 g_menuListWrap.append("<div class='available_id_s'>Section Id's List<ul class='available_section_id_s_list'></ul></div>"); 299 300 var objSectionIdList = g_menu.find(".available_section_id_s_list"); 301 var availableSections = jQuery('section'); 302 303 availableSections.each(function(){ 304 305 var objSectionItem = jQuery(this); 306 var objSectionItemId = objSectionItem.attr('id'); 307 var objSectionItemDisplay = objSectionItem.css('display'); 308 309 //watch only those sections that are displayed on the page 310 if(objSectionItemDisplay == 'none') 311 return(true); 312 313 //if id attribute is empty, skip and go to next id 314 if(!objSectionItemId){ 315 return(true); 316 } 317 318 //check if sections are connected to mega menu items 319 if(objSectionItem.hasClass("uc-connected")){ 320 return(true); 321 }else{ 322 //add section's id to the list 323 objSectionIdList.append("<li>" + objSectionItemId + "</li>"); 324 } 325 }); 326 } 327 328 /* 329 * set overlay position to screen left 330 */ 331 function setOverlayPosition(activeMenuItem){ 332 333 var dataOverlay = g_objOverlay.data('overlay'); 334 335 if(dataOverlay == false) 336 return(false); 337 338 if(g_isCustomResponsiveViewport.matches == true || !activeMenuItem.length) 339 return(false); 340 341 342 var g_menuListWrapOffsetTop = g_menuListWrap.offset().top; 343 var g_menuListWrapOffsetHeight = g_menuListWrap.height(); 344 var documentOffsetHeight = jQuery(document).height(); 345 346 var g_objOverlayOffsetTop = g_menuListWrapOffsetTop + g_menuListWrapOffsetHeight; 347 var g_objOverlayOffsetHeight = documentOffsetHeight - g_objOverlayOffsetTop; 348 349 g_objOverlay.show(); 350 351 var dataOverlayPosition = g_objOverlay.data('overlay-position'); 352 353 g_objOverlay.css({ 354 'width': g_viewportWidth + 'px', 355 'left': - g_menuWrapOffsetLeft + 'px', 356 'transform': 'translate(0, 0)', 357 'height': g_objOverlayOffsetHeight + 'px' 358 }); 359 360 if(dataOverlayPosition == 'under') 361 return(false); 362 363 var overlayTopPosition = -g_menuListWrapOffsetTop; 364 365 g_objOverlay.css({ 366 'top': overlayTopPosition + 'px', 367 'height': documentOffsetHeight + 'px' 368 }); 369 370 371 } 372 373 /* 374 * set active disresponsive height 375 */ 376 function setDisactiveResponsiveHeight(){ 377 378 if(g_isNotCustomResponsiveViewport.matches == true) 379 return(false); 380 381 g_menuSection.css({'height': '0px'}); 382 383 } 384 385 /* 386 * set disactive responsive height for parent menu item 387 */ 388 function setActiveResponsiveHeight(activeMenuItem){ 389 390 if(!activeMenuItem) 391 return(false); 392 393 var menuSectionActive = activeMenuItem.find(g_classSection); 394 var menuSectionActiveChild = menuSectionActive.children(); 395 var menuSectionActiveHeight = menuSectionActiveChild.outerHeight(); 396 397 398 if(g_menuSection.hasClass(g_classActive)){ 399 setDisactiveResponsiveHeight(); 400 menuSectionActive.css({'height': menuSectionActiveHeight + 'px'}); 401 }else{ 402 setDisactiveResponsiveHeight(); 403 } 404 } 405 406 /* 407 *set active menu item icon 408 */ 409 function setActiveArrow(activeItem){ 410 411 var indicatorActive = activeItem.find('.sub-arrow'); 412 var collapseIndicatorClass = '.uc_collapse_indicator'; 413 var objCollapseIndicator = jQuery(collapseIndicatorClass); 414 415 if(objCollapseIndicator.length){ 416 var objCollapseIndicatorItem = objCollapseIndicator.parents('.uc-mega_menu_list_item'); 417 418 objCollapseIndicatorItem.find('.sub-arrow').html("<span class='uc_expand_indicator'></span>"); 419 } 420 421 indicatorActive.html("<span class='uc_collapse_indicator'></span>"); 422 } 423 424 /* 425 * set disactive menu item icon 426 */ 427 function setDisactiveArrow(){ 428 429 var collapseIndicatorClass = '.uc_collapse_indicator'; 430 var objCollapseIndicator = jQuery(collapseIndicatorClass); 431 432 if(objCollapseIndicator.length){ 433 var objCollapseIndicatorItem = objCollapseIndicator.parents('.uc-mega_menu_list_item'); 434 435 objCollapseIndicatorItem.find('.sub-arrow').html("<span class='uc_expand_indicator'></span>"); 436 } 437 438 } 439 440 /* 441 * set top position 100% + padding-bottom of menu-list-wrapper 442 */ 443 function setTopPosition(objElement){ 444 445 var activeMenuSection = objElement.find(g_classSection); 446 var menuListPaddingBottom = g_menuList.css('padding-bottom'); 447 448 activeMenuSection.css({ 449 'top': 'calc(100% + ' + menuListPaddingBottom + ')' 450 }); 451 } 452 453 /* 454 * handle positionX option 455 */ 456 function isElementInViewportX(objElement) { 457 458 var activeMenuSection = objElement.find(g_classSection); 459 460 if(!activeMenuSection.length) 461 return(true); 462 463 var activeMenuSectionWidth = activeMenuSection.width(); 464 var elementPositionLeft = activeMenuSection.offset().left; 465 var elementPositionRight = activeMenuSectionWidth + elementPositionLeft; 466 467 var isInViewport; 468 469 if (g_dataPositionX == "item_left"){ 470 var menuItemPositionLeft = objElement.offset().left; 471 var elementPositionRight = activeMenuSectionWidth + menuItemPositionLeft + g_offsetX; 472 var elementPositionLeft = activeMenuSection.offset().left; 473 474 //if dropdown width == viewportwidth + width of a scroll bar 475 if(activeMenuSectionWidth == g_viewportWidth) 476 return(true); 477 478 setTopPosition(objElement); 479 480 if(elementPositionLeft < 0){ 481 g_translateX = 0 + 'px'; 482 }else if(elementPositionRight >= g_viewportWidth){ 483 g_translateX = g_viewportWidth - elementPositionRight + g_offsetX + "px"; 484 } 485 486 isInViewport = elementPositionLeft > 0 && elementPositionRight < g_viewportWidth; 487 488 return(isInViewport); 489 } 490 491 if (g_dataPositionX == "item_right"){ 492 var menuItemPositionRight = objElement.offset().left + objElement.width(); 493 var elementPositionLeft = menuItemPositionRight - activeMenuSectionWidth + g_offsetX; 494 var elementPositionRight = activeMenuSection.offset().left + activeMenuSectionWidth; 495 496 //if dropdown width == viewportwidth + width of a scroll bar 497 if(activeMenuSectionWidth == g_viewportWidth) 498 return(true); 499 500 setTopPosition(objElement); 501 502 if(elementPositionLeft < 0){ 503 g_translateX = Math.abs(elementPositionLeft) + g_offsetX + "px"; 504 }else{ 505 g_translateX = 0 + 'px'; 506 } 507 508 isInViewport = elementPositionLeft > 0 && elementPositionLeft + g_offsetX > 0 && elementPositionRight < g_viewportWidth; 509 510 return(isInViewport); 511 } 512 513 if (g_dataPositionX == "item_center"){ 514 var menuItemPositionLeft = objElement.offset().left; 515 var objElementWidth = objElement.width(); 516 var elementPositionCenter = menuItemPositionLeft + (objElementWidth / 2); 517 var elementPositionLeft = elementPositionCenter - (activeMenuSectionWidth / 2) + g_offsetX; 518 var elementPositionRight = elementPositionCenter + (activeMenuSectionWidth / 2) + g_offsetX; 519 520 //if dropdown width == viewportwidth + width of a scroll bar 521 if(activeMenuSectionWidth == g_viewportWidth) 522 return(true); 523 524 setTopPosition(objElement); 525 526 if(elementPositionLeft < 0){ 527 g_translateX = '-' + (objElementWidth / 2) - menuItemPositionLeft + 'px'; 528 }else if(elementPositionRight > g_viewportWidth){ 529 g_translateX = 'calc(-50% + ' + (g_viewportWidth - elementPositionRight + g_offsetX) + 'px)'; 530 } 531 532 isInViewport = elementPositionLeft > 0 && elementPositionRight < g_viewportWidth; 533 534 return(isInViewport); 535 } 536 } 537 538 /* 539 * dropdown element style always visible 540 */ 541 function setCssVisiblePositionX(activeMenuSection){ 542 543 activeMenuSection.css({ 544 "transform": "translate(" + g_translateX + ", 0)" 545 }); 546 } 547 548 /* 549 * set dropdown element position 550 */ 551 function setVisiblePositionX(objElement){ 552 553 if(g_isCustomResponsiveViewport.matches == true) 554 return(false); 555 556 var activeMenuSection = objElement.find(g_classSection); 557 var activeMenuSectionWidth = activeMenuSection.width(); 558 559 //if activeMenuSectionWidth is less than viewport width - return to original coordinates 560 if(activeMenuSectionWidth > g_viewportWidth) 561 return(false); 562 563 activeMenuSection.css({ 564 "transform": "translate(" + g_offsetX + "px, 0)" 565 }); 566 567 568 //if position_x is "item_center" than transform calculate with '-50%' 569 if (g_dataPositionX == "item_center" && activeMenuSectionWidth < g_viewportWidth){ 570 activeMenuSection.css({ 571 "transform": "translate(calc(-50% + " + g_offsetX + "px), 0)" 572 }); 573 } 574 575 if(isElementInViewportX(objElement)) 576 return(false); 577 578 //if dropdown does not fit in screen than change coordinates so it is always fully visible 579 setCssVisiblePositionX(activeMenuSection); 580 } 581 582 /* 583 * set dropdown cover element position 584 */ 585 function setCoverPosition(menuSection, menuSectionChild){ 586 587 if(menuSection.length == 0) 588 return(false); 589 590 if(menuSectionChild.length == 0) 591 return(false); 592 593 var objCover = menuSection.next(); 594 var menuItem = menuSectionChild.parents('.uc-mega_menu_list_item'); 595 596 var objCoverHeight = menuSectionChild.outerHeight(); 597 var objCoverWidth = menuSection.width(); 598 var menuItemWidth = menuItem.width(); 599 600 var menuItemOffsetLeft = menuItem.offset().left; 601 var menuSectionOffsetLeft = menuSection.offset().left; 602 603 var menuItemOffsetRight = menuItemOffsetLeft + menuItemWidth; 604 var menuSectionOffsetRight = menuSectionOffsetLeft + objCoverWidth; 605 606 objCover.css({ 607 'width': objCoverWidth + 'px', 608 'height': objCoverHeight + 'px' 609 }); 610 611 if (menuItemOffsetLeft == menuSectionOffsetLeft){ 612 objCover.css({ 613 'left': '0px', 614 'right': 'unset' 615 }); 616 } 617 618 if(menuItemOffsetRight == menuSectionOffsetRight){ 619 objCover.css({ 620 'left': 'unset', 621 'right': '0px' 622 }); 623 } 624 625 if (menuItemOffsetLeft > menuSectionOffsetLeft){ 626 627 var menuItemSectionPositionDeviation = menuItemOffsetLeft - menuSectionOffsetLeft; 628 629 objCover.css({ 630 'right': 'unset', 631 'left': - menuItemSectionPositionDeviation + 'px' 632 }); 633 } 634 635 if (menuItemOffsetLeft < menuSectionOffsetLeft){ 636 637 var menuItemSectionPositionDeviation = menuSectionOffsetLeft - menuItemOffsetLeft; 638 639 objCover.css({ 640 'right': 'unset', 641 'left': menuItemSectionPositionDeviation + 'px' 642 }); 643 } 644 645 if(objCoverWidth == g_viewportWidth){ 646 647 objCover.css({ 648 'right': 'unset', 649 'left': - g_menuWrapOffsetLeft + 'px' 650 }); 651 } 652 } 653 654 /* 655 * set active item 656 */ 657 function setActive(activeMenuItem){ 658 659 g_menuItem.removeClass(g_classActive); 660 g_menuSection.removeClass(g_classActive); 661 662 var activeMenuItemSection = activeMenuItem.find(g_classSection); 663 664 activeMenuItem.addClass(g_classActive); 665 activeMenuItemSection.addClass(g_classActive); 666 667 setTimeout(function(){ 668 activeMenuItemSection.children().css({ 669 'position': '', 670 'visibility': 'visible' 671 }); 672 },100); 673 674 //add active class to menu if menu item section has children 675 if(activeMenuItemSection.children().length){ 676 g_menu.addClass(g_menuActiveClass); 677 678 if(g_isCustomResponsiveViewport.matches == false){ 679 680 g_objBody.addClass(g_menuActiveClass); 681 g_objHtml.addClass(g_menuActiveClass); 682 } 683 684 }else{ 685 g_menu.removeClass(g_menuActiveClass); 686 g_objBody.removeClass(g_menuActiveClass); 687 g_objHtml.removeClass(g_menuActiveClass); 688 } 689 690 if(g_isCustomResponsiveViewport.matches == true){
691 setActiveResponsiveHeight(activeMenuItem); 692 } 693 694 setVisiblePositionX(activeMenuItem); 695 handleWidthType(); 696 setTipPosition(activeMenuItemSection); 697 setOverlayPosition(activeMenuItem); 698 699 var menuSectionChild = activeMenuItemSection.children(); 700 701 setCoverPosition(activeMenuItemSection, menuSectionChild); 702 scrollToHead(activeMenuItem); 703 } 704 705 /* 706 * set disactive menu item 707 */ 708 function setDisactive(){ 709 710 g_menuItem.removeClass(g_classActive); 711 g_menuSection.removeClass(g_classActive); 712 setDisactiveArrow(); 713 714 setTimeout(function(){ 715 g_menuSection.children().css({ 716 'position': 'absolute', 717 'visibility': 'hidden' 718 }); 719 },g_dataCloseDelay); 720 721 //remove active class from menu 722 g_menu.removeClass(g_menuActiveClass); 723 724 if(g_isCustomResponsiveViewport.matches == false){ 725 726 g_objBody.removeClass(g_menuActiveClass); 727 g_objHtml.removeClass(g_menuActiveClass); 728 } 729 730 if(g_objOverlay.length) 731 g_objOverlay.hide(); 732 733 } 734 735 /* 736 * create tip 737 */ 738 function createTip(menuSectionParent){ 739 740 var isTipExist = menuSectionParent.data('tip'); 741 742 if(isTipExist == false) 743 return(false); 744 745 var offsetY = g_menuList.data("offset-y"); 746 747 //create padding for the tip 748 if(offsetY < 14){ 749 menuSectionParent.css({'padding-top': '14px'}) 750 }else if(offsetY >= 14){ 751 menuSectionParent.css({'padding-top': offsetY + 'px'}) 752 } 753 754 var objsection = menuSectionParent.find('.uc-connected'); 755 756 objsection.prepend('<div class="ue-tip"></div>'); 757 758 var objErrorTip; 759 760 if(menuSectionParent.hasClass('section-error')){ 761 menuSectionParent.find('.uc-section-error').prepend('<div class="ue-tip"></div>'); 762 763 objErrorTip = menuSectionParent.find('.ue-tip'); 764 765 objErrorTip.css({ 766 'border-top-color': '#cccccc', 767 'border-left-color': '#cccccc' 768 }) 769 } 770 771 var objTip = menuSectionParent.find('.ue-tip'); 772 var menuSectionBgColor = objsection.css('background-color'); 773 var dataTipBgColor = menuSectionParent.data('bg-color'); 774 var dataTipMainColor = menuSectionParent.data('tip-color'); 775 776 var isMenuSectionBorderExist = parseInt(objsection.css('border-width')) > 0; 777 var menuSectionBorderColor = objsection.css('border-color'); 778 779 if(menuSectionBgColor == 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false){ 780 objTip.css({ 781 'border-top-color': dataTipBgColor, 782 'border-left-color': dataTipBgColor, 783 }); 784 } 785 786 if(isMenuSectionBorderExist == true){ 787 objTip.css({ 788 'border-top-color': menuSectionBorderColor, 789 'border-left-color': menuSectionBorderColor, 790 }); 791 } 792 793 if(menuSectionBgColor != 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false){ 794 objTip.css({ 795 'border-top-color': menuSectionBgColor, 796 'border-left-color': menuSectionBgColor, 797 }); 798 } 799 800 if(menuSectionParent.hasClass('section-error')){ 801 802 objErrorTip.css({ 803 'border-top-color': '#cccccc', 804 'border-left-color': '#cccccc' 805 }) 806 } 807 808 if(dataTipMainColor != ''){ 809 objTip.css({ 810 'border-top-color': dataTipMainColor, 811 'border-left-color': dataTipMainColor, 812 }); 813 } 814 815 if(menuSectionBgColor == 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false && dataTipBgColor == '' && dataTipMainColor == ''){ 816 objTip.css({ 817 'border-top-color': '#C9C9C9', 818 'border-left-color': '#C9C9C9' 819 }); 820 } 821 } 822 823 /* 824 * set position of the tip 825 */ 826 function setTipPosition(menuSectionParent){ 827 828 if(menuSectionParent.length == 0) 829 return(false); 830 831 var objTip = menuSectionParent.find('.ue-tip'); 832 var objsection = menuSectionParent.find('.uc-connected'); 833 834 var menuSectionBgColor = objsection.css('background-color'); 835 var menuSectionBorderColor = objsection.css('border-color'); 836 var dataTipBgColor = menuSectionParent.data('bg-color'); 837 var dataTipMainColor = menuSectionParent.data('tip-color'); 838 839 var isMenuSectionBorderExist = parseInt(objsection.css('border-width')) > 0; 840 841 var menuItem = menuSectionParent.parents('.uc-mega_menu_list_item'); 842 843 var menuItemWidth = menuItem.width(); 844 var objTipWidth = objTip.width(); 845 var menuSectionWidth = menuSectionParent.width(); 846 var menuItemCenter = menuItemWidth / 2; 847 848 var menuItemOffsetLeft = menuItem.offset().left; 849 var menuSectionOffsetLeft = menuSectionParent.offset().left; 850 851 var menuItemOffsetRight = menuItemOffsetLeft + menuItemWidth; 852 var menuSectionOffsetRight = menuSectionOffsetLeft + menuSectionWidth; 853 854 var menuItemCenterOffsetLeft = menuItemOffsetLeft + menuItemCenter; 855 856 if (menuItemOffsetLeft == menuSectionOffsetLeft){ 857 objTip.css({ 858 'left': (menuItemWidth / 2) + 'px', 859 'right': 'unset' 860 }); 861 } 862 863 if(menuItemOffsetRight == menuSectionOffsetRight){ 864 objTip.css({ 865 'left': 'unset', 866 'right': (menuItemWidth / 2) + 'px' 867 }); 868 } 869 870 if (menuSectionOffsetLeft < menuItemOffsetLeft && menuSectionOffsetRight > menuItemCenterOffsetLeft + objTipWidth){ 871 872 //find how much menuSectionOffsetLeft is less then menuItemOffsetLeft 873 var menuItemSectionPositionDeviation = menuItemOffsetLeft - menuSectionOffsetLeft; 874 875 objTip.css({ 876 'left': menuItemSectionPositionDeviation + (menuItemWidth / 2) + 'px', 877 'right': 'unset' 878 }); 879 } 880 881 if (menuSectionOffsetLeft < menuItemOffsetLeft && menuSectionOffsetRight <= menuItemCenterOffsetLeft + objTipWidth){ 882 883 //find how much menuSectionOffsetLeft is less then menuItemOffsetLeft 884 var menuItemSectionPositionDeviation = menuItemOffsetLeft - menuSectionOffsetLeft; 885 886 objTip.css({ 887 'left': 'unset', 888 'right': '0px', 889 'transform': 'translate(0, -50%) rotate(0)', 890 'border-top-color': 'transparent', 891 'border-left-color': 'transparent' 892 }); 893 894 //set right border color 895 if(menuSectionBgColor == 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false){ 896 objTip.css({ 897 'border-right-color': dataTipBgColor 898 }); 899 } 900 901 if(isMenuSectionBorderExist == true){ 902 objTip.css({ 903 'border-right-color': menuSectionBorderColor 904 }); 905 } 906 907 if(menuSectionBgColor != 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false){ 908 objTip.css({ 909 'border-right-color': menuSectionBgColor 910 }); 911 } 912 913 if (menuSectionParent.hasClass('section-error')){ 914 var objErrorTip = menuSectionParent.find('.ue-tip'); 915 916 objErrorTip.css({ 917 'border-right-color': '#cccccc', 918 }); 919 } 920 921 if(dataTipMainColor != ''){ 922 objTip.css({ 923 'border-right-color': dataTipMainColor 924 }); 925 } 926 927 if(menuSectionBgColor == 'rgba(0, 0, 0, 0)' && isMenuSectionBorderExist == false && dataTipBgColor == '' && dataTipMainColor == ''){ 928 objTip.css({ 929 'border-right-color': '#C9C9C9' 930 }); 931 } 932 933 } 934 935 if (menuSectionOffsetLeft > menuItemOffsetLeft && menuSectionOffsetLeft < menuItemCenterOffsetLeft - objTipWidth){ 936 937 //find how much menuSectionOffsetLeft is grater then menuItemOffsetLeft 938 var menuItemSectionPositionDeviation = menuSectionOffsetLeft - menuItemOffsetLeft; 939 940 objTip.css({ 941 'left': (menuItemWidth / 2) - menuItemSectionPositionDeviation + 'px', 942 'right': 'unset' 943 }); 944 } 945 946 if (menuSectionOffsetLeft > menuItemOffsetLeft && menuSectionOffsetLeft >= menuItemCenterOffsetLeft - objTipWidth){ 947 948 //find how much menuSectionOffsetLeft is grater then menuItemOffsetLeft 949 var menuItemSectionPositionDeviation = menuSectionOffsetLeft - menuItemOffsetLeft; 950 951 objTip.css({ 952 'left': '0px', 953 'right': 'unset', 954 'transform': 'translate(0, -50%) rotate(0)', 955 'border-top-color': 'transparent' 956 }); 957 } 958 } 959 960 /* 961 * get menu item offset top position 962 */ 963 function getScrollPos(){ 964 965 if(g_isNotCustomResponsiveViewport.matches == true) 966 return(false); 967 968 g_menuItem.each(function(){ 969 970 var objItem = jQuery(this); 971 972 var menuItemOffsetTop = objItem.offset().top; 973 974 objItem.attr('data-scrollpos', menuItemOffsetTop); 975 }); 976 } 977 978 /* 979 * check if element is in viewport 980 */ 981 function isElementInViewport(element){ 982 983 var elementTop = element.offset().top; 984 var viewportTop = jQuery(window).scrollTop(); 985 986 //check if beginning of the element is in viewport 987 var isInViewport = elementTop > viewportTop; 988 989 return(isInViewport); 990 } 991 992 /* 993 * scroll to head 994 */ 995 function scrollToHead(menuItem){ 996 997 if(g_isNotCustomResponsiveViewport.matches == true) 998 return(false); 999 1000 var menuItemOffsetTop = menuItem.data('scrollpos'); 1001 var menuItemSection = menuItem.find(g_classSection); 1002 1003 //wait untill height transition is finished 1004 setTimeout(function(){ 1005 1006 if(isElementInViewport(menuItemSection) == true) 1007 return(false); 1008 1009 g_menuListWrap.animate({ 1010 scrollTop: menuItemOffsetTop 1011 }, 400); 1012 }, 400); 1013 } 1014 1015 /* 1016 * hide arrows while animation is on 1017 */ 1018 function showHideArrows(){ 1019 1020 if(g_indicator.length == 0) 1021 return(false); 1022 1023 var dataAnimation = g_indicator.data('animate-arrows') 1024 1025 if(dataAnimation == false) 1026 return(false); 1027 1028 setTimeout(function(){ 1029 g_indicator.css({'opacity': 1}); 1030 }, 300) 1031 } 1032 1033 /* 1034 * set class to menu item title when base url matches 1035 */ 1036 function checkUrl(){ 1037 1038 var itemsNumber = g_menuItem.length; 1039 1040 for(let i=0; i<itemsNumber; i++){ 1041 var menuItemTitle = g_menuItem.eq(i).find('.uc-mega_menu_title'); 1042 var menuItemUrl = menuItemTitle.attr('href'); 1043 1044 if(menuItemUrl == g_urlBase){ 1045 menuItemTitle.addClass('uc-current-page'); 1046 } 1047 } 1048 } 1049 1050 /* 1051 * show | hide section in editor 1052 */ 1053 function hideSectionInEditor(menuSectionItem){ 1054 1055 if(g_dataEditor == false) 1056 return(false); 1057 1058 1059 if(menuSectionItem.hasClass('uc-connected') == true) 1060 return(false); 1061 1062 var dataShowInEditor = g_menuList.data('show-section'); 1063 1064 if(dataShowInEditor == 'no'){ 1065 menuSectionItem.css({ 1066 'position': '', 1067 'visibility': 'visible' 1068 }); 1069 } 1070 1071 if(dataShowInEditor == 'message' || dataShowInEditor == 'hide'){ 1072 menuSectionItem.css({ 1073 'position': 'absolute', 1074 'visibility': 'hidden' 1075 }); 1076 } 1077 } 1078 1079 /* 1080 * open first item on mobile 1081 */ 1082 function openFirstItem(){ 1083 1084 if(g_isNotCustomResponsiveViewport.matches == true) 1085 return(false); 1086 1087 var firstItem = g_menuItem.eq(0); 1088 var firsItemTitle = firstItem.find('.uc-mega_menu_title'); 1089 var dataFirstItemType = firsItemTitle.data('type'); 1090 var dataFirstItemClickable = firsItemTitle.data('clickable-link'); 1091 1092 if(dataFirstItemType != 'section') 1093 return(false); 1094 1095 if(dataFirstItemClickable != false) 1096 return(false); 1097 1098 var dataOpenFirstItem = g_menuList.data('open-first'); 1099 1100 if(dataOpenFirstItem == false) 1101 return(false); 1102 1103 setActive(firstItem); 1104 setActiveArrow(firstItem); 1105 1106 } 1107 1108 /* 1109 * define item type "section" behaviour 1110 */ 1111 function handleItemTypeSection(){ 1112 1113 var menuSectionParentItem = g_menuSection.parents('.uc-mega_menu_list_item'); 1114 1115 menuSectionParentItem.each(function(){ 1116 1117 var objSection = jQuery(this); 1118 var menuSectionId = objSection.data("id"); 1119 var menuSectionItem = jQuery("#" + menuSectionId); 1120 var menuSectionParent = objSection.find(g_classSection); 1121 var firstMenuSectionParent = objSection.eq(0).find(g_classSection); 1122 1123 setTemplateStyle(); 1124 1125 findSections(objSection, menuSectionParent, menuSectionItem, firstMenuSectionParent); 1126 1127 showHideErrors(objSection, menuSectionId, menuSectionParent, menuSectionItem); 1128 debugHiddenElements(); 1129 1130 1131 }); 1132 1133 handleWidthType(); 1134 showHideArrows(); 1135 1136 //set visible position of all dropdown sections and then create tip 1137 for(let i = 0; i < g_menuItem.length; i++){ 1138 1139 var objMenuItem = g_menuItem.eq(i); 1140 var menuSection = objMenuItem.find(g_classSection); 1141 var menuSectionChild = menuSection.children(); 1142 1143 setVisiblePositionX(objMenuItem); 1144 1145 createTip(menuSection); 1146 setTipPosition(menuSection); 1147 setCoverPosition(menuSection, menuSectionChild); 1148 } 1149 1150 //handle debug mode 1151 showHideMenuItemsId(); 1152 showHideElementsId(); 1153 1154 if(g_isCustomResponsiveViewport.matches == true){ 1155 g_menuListWrap.addClass('uc-mobile-mode'); 1156 }else{ 1157 g_menuListWrap.removeClass('uc-mobile-mode'); 1158 } 1159 1160 getScrollPos(); 1161 checkUrl(); 1162 1163 openFirstItem(); 1164 } 1165 1166 /* 1167 * define item type "section" behaviour in editor 1168 */ 1169 function handleItemTypeSectionInEditor(){ 1170 1171 g_menuItem.each(function(){ 1172 1173 var objSection = jQuery(this); 1174 var menuSectionId = objSection.data("id"); 1175 var menuSectionItem = jQuery("#" + menuSectionId); 1176 var menuSectionParent = objSection.find(g_classSection); 1177 1178 1179 showHideErrors(objSection, menuSectionId, menuSectionParent, menuSectionItem); 1180 debugHiddenElements(); 1181 1182 hideSectionInEditor(menuSectionItem) 1183 1184 }); 1185 1186 //handle debug mode 1187 showHideMenuItemsId(); 1188 showHideElementsId(); 1189 1190 } 1191 1192 /* 1193 * handle click event 1194 */ 1195 function menuItemClick(objTitle){ 1196 1197 var activeMenuItemClick = objTitle.parents('.uc-mega_menu_list_item'); 1198 1199 if(activeMenuItemClick.hasClass(g_classActive)){ 1200 1201 setDisactive(); 1202 1203 if(g_isCustomResponsiveViewport.matches == true) 1204 setDisactiveResponsiveHeight(); 1205 1206 }else{
1207 setActive(activeMenuItemClick); 1208 setActiveArrow(activeMenuItemClick); 1209 } 1210 } 1211 1212 /* 1213 * close menu when anchor link click 1214 */ 1215 function closeMenuOnAnchorClick(objTitle){ 1216 1217 var url = objTitle.attr('href'); 1218 1219 //if not anchor do nothing 1220 if (url.indexOf("#") == -1) 1221 return(false); 1222 1223 setDisactive(); 1224 1225 if(g_isCustomResponsiveViewport.matches == false) 1226 return(false); 1227 1228 setDisactiveResponsiveHeight(); 1229 g_menuListWrap.removeClass(g_menuActiveClass); 1230 g_objBody.removeClass(g_menuActiveClass); 1231 g_objHtml.removeClass(g_menuActiveClass); 1232 g_menu.removeClass(g_menuActiveClass); 1233 1234 } 1235 1236 /* 1237 * handle click event 1238 */ 1239 function onMenuItemClick(e){ 1240 1241 var objTitle = jQuery(this); 1242 var isItemClickable = objTitle.data('clickable-link'); 1243 var itemType = objTitle.data('type'); 1244 var titleClass = 'uc-mega_menu_title'; 1245 1246 if (g_dataMenuOpen == 'hover'){ 1247 1248 if(g_isDesktopViewport.matches == true && g_isCustomResponsiveViewport.matches == false && itemType != 'link' && isItemClickable == false) 1249 return(false); 1250 1251 if(itemType != 'link' && isItemClickable == false){ 1252 menuItemClick(objTitle); 1253 return(false); 1254 } 1255 1256 if(g_isNotDesktopViewport.matches == true && isItemClickable == true){ 1257 1258 var objTarget = jQuery(e.target); 1259 var objTargetParent = objTarget.parent(); 1260 1261 if(objTargetParent.hasClass(titleClass) == false){ 1262 1263 menuItemClick(objTitle); 1264 return(false); 1265 1266 } 1267 1268 if(objTargetParent.hasClass(titleClass) == true) 1269 return(true) 1270 1271 } 1272 1273 if(g_isDesktopViewport.matches == true && isItemClickable == true) 1274 return(true); 1275 1276 //close menu when anchor link click 1277 if(itemType == 'link'){ 1278 1279 closeMenuOnAnchorClick(objTitle); 1280 1281 //stop any further function execution 1282 return(true); 1283 1284 } 1285 1286 menuItemClick(objTitle); 1287 } 1288 1289 //close menu when anchor link click 1290 if(itemType == 'link'){ 1291 1292 closeMenuOnAnchorClick(objTitle); 1293 1294 //stop any further function execution 1295 return(true); 1296 1297 } 1298 1299 if(g_isDesktopViewport.matches == true && isItemClickable == true) 1300 return(true); 1301 1302 if(g_isNotDesktopViewport.matches == true && isItemClickable == true){ 1303 1304 var objTarget = jQuery(e.target); 1305 var objTargetParent = objTarget.parent(); 1306 1307 if(objTargetParent.hasClass(titleClass) == false){ 1308 1309 menuItemClick(objTitle); 1310 return(false); 1311 1312 } 1313 1314 if(objTargetParent.hasClass(titleClass) == true) 1315 return(true) 1316 1317 } 1318 1319 if(isItemClickable == false) 1320 menuItemClick(objTitle); 1321 } 1322 1323 /* 1324 * handle click on body event 1325 */ 1326 function setDisactiveOnbodyClick(event){ 1327 1328 if(g_menuItem.hasClass(g_classActive) == false) 1329 return(false); 1330 1331 if(g_isCustomResponsiveViewport.matches == true) 1332 return(false); 1333 1334 //exclude arrow indicator from this function to prevent closing dropdown after arrow click 1335 if(jQuery(event.target).hasClass('uc_expand_indicator')) 1336 return(false); 1337 1338 if (!jQuery(event.target).closest(g_menuItem).length) 1339 setDisactive(); 1340 1341 } 1342 1343 /* 1344 * handle body click event 1345 */ 1346 function bodyClick(event){ 1347 1348 if (g_dataMenuOpen == 'hover'){ 1349 1350 if(g_isDesktopViewport.matches == true && g_isNotCustomResponsiveViewport.matches == true){ 1351 return(false); 1352 } 1353 1354 setDisactiveOnbodyClick(event); 1355 } 1356 1357 setDisactiveOnbodyClick(event); 1358 } 1359 1360 /* 1361 * close menu on mega-menu-inner-links link-item click 1362 */ 1363 function onInnerLinkClick(){ 1364 1365 setDisactive(); 1366 1367 if(g_isCustomResponsiveViewport.matches == true){ 1368 setDisactiveResponsiveHeight(); 1369 g_menuListWrap.removeClass(g_menuActiveClass); 1370 g_objBody.removeClass(g_menuActiveClass); 1371 g_objHtml.removeClass(g_menuActiveClass); 1372 g_menu.removeClass(g_menuActiveClass); 1373 } 1374 1375 openFirstItem(); 1376 } 1377 1378 /* 1379 * handle body click event 1380 */ 1381 function handleMenuItemClick(){ 1382 1383 g_menuItemTitle.on("click", onMenuItemClick); 1384 1385 jQuery(document).on('click', function(event) { 1386 1387 bodyClick(event); 1388 }); 1389 1390 } 1391 1392 /* 1393 * handle mouse enter event on menu item 1394 */ 1395 function onMenuItemMouseEnter(){ 1396 1397 if(g_dataMenuOpen == 'click') 1398 return(false); 1399 1400 if(g_isCustomResponsiveViewport.matches == true) 1401 return(false); 1402 1403 var activeMenuItemHover = jQuery(this); 1404 1405 setActive(activeMenuItemHover); 1406 setActiveArrow(activeMenuItemHover); 1407 } 1408 1409 /* 1410 * set disactive menu item on mouseleave 1411 */ 1412 function onMenuItemMouseLeave(){ 1413 1414 if(g_dataMenuOpen == 'click') 1415 return(false); 1416 1417 if(g_isCustomResponsiveViewport.matches == true) 1418 return(false); 1419 1420 setDisactive(); 1421 } 1422 1423 /* 1424 * handle hover event 1425 */ 1426 function handleMenuItemHover(){ 1427 1428 g_menuItem.on('mouseenter', onMenuItemMouseEnter); 1429 1430 g_menuListWrap.on('mouseleave', onMenuItemMouseLeave); 1431 } 1432 1433 /* 1434 * handle mega-menu-inner-links link-item click 1435 */ 1436 function handleMenuInnerLinksClick(){ 1437 1438 g_menuList.on('close_mega_menu', onInnerLinkClick); 1439 } 1440 1441 /* 1442 * handle menu item open option 1443 */ 1444 function menuItemOpen(){ 1445 1446 handleMenuItemHover(); 1447 handleMenuItemClick(); 1448 handleMenuInnerLinksClick(); 1449 } 1450 1451 /* 1452 * define responsive mode behaviour 1453 */ 1454 function onBurgerMenuClick(){ 1455 1456 g_menuListWrap.addClass(g_menuActiveClass); 1457 g_objBody.addClass(g_menuActiveClass); 1458 g_objHtml.addClass(g_menuActiveClass); 1459 } 1460 1461 /* 1462 * close menu on click on the burger 1463 */ 1464 function onCloseBurgerMenuBtnClick(){ 1465 1466 g_menuItem.removeClass(g_classActive); 1467 1468 g_menuSection.removeClass(g_classActive); 1469 setDisactiveArrow(); 1470 1471 setDisactiveResponsiveHeight(); 1472 g_menuListWrap.removeClass(g_menuActiveClass); 1473 g_objBody.removeClass(g_menuActiveClass); 1474 g_objHtml.removeClass(g_menuActiveClass); 1475 1476 //remove active class from menu 1477 g_menu.removeClass(g_menuActiveClass); 1478 1479 openFirstItem(); 1480 } 1481 1482 /* 1483 * remove from body and menu wrapper open class 1484 */ 1485 function removeOpenClass(){ 1486 1487 if(g_menuListWrap.hasClass(g_menuActiveClass) == false) 1488 return(false); 1489 1490 if(g_objBody.hasClass(g_menuActiveClass) == false) 1491 return(false); 1492 1493 g_menuListWrap.removeClass(g_menuActiveClass); 1494 g_objBody.removeClass(g_menuActiveClass); 1495 g_objHtml.removeClass(g_menuActiveClass); 1496 } 1497 1498 /* 1499 * handle resize event 1500 */ 1501 function onWindowResize(){ 1502 1503 var activeMenuItem = g_menu.find('.uc-mega_menu_list_item.uc-active_item'); 1504 1505 //set height 0 except active section when resize from desktop to mobile 1506 if(g_isCustomResponsiveViewport.matches == true){ 1507 1508 //add responsive class to wrapper on mobile 1509 g_menuListWrap.addClass('uc-mobile-mode'); 1510
1511 setActiveResponsiveHeight(activeMenuItem); 1512 1513 g_objOverlay.hide(); 1514 } 1515 1516 //remove menu / wrapper open class when breakpoint changes 1517 if(g_isNotCustomResponsiveViewport.matches == true){ 1518 1519 removeOpenClass(); 1520 1521 //remove responsive class from wrapper 1522 g_menuListWrap.removeClass('uc-mobile-mode'); 1523 1524 g_menuSection.css({'height': 'unset'}); 1525 } 1526 1527 //update viewport width var on scroll 1528 g_viewportWidth = jQuery(window).width(); 1529 1530 //update left position on scroll 1531 g_menuWrapOffsetLeft = g_menuListWrap.offset().left; 1532 1533 handleWidthType(); 1534 1535 //set visible position of all dropdown sections / set position of the tip 1536 for(let i = 0; i < g_menuItem.length; i++){ 1537 1538 var objMenuItem = g_menuItem.eq(i); 1539 var menuSection = objMenuItem.find(g_classSection); 1540 var menuSectionChild = menuSection.children(); 1541 1542 setVisiblePositionX(objMenuItem); 1543 1544 setTipPosition(menuSection); 1545 setCoverPosition(menuSection, menuSectionChild); 1546 } 1547 1548 setOverlayPosition(activeMenuItem); 1549 1550 getScrollPos(); 1551 1552 //handle sticky section bug protection 1553 setTimeout(onPageScroll,100); 1554 1555 } 1556 1557 /* 1558 * handle scroll event for sticky section protection 1559 */ 1560 function onPageScroll(){ 1561 1562 var objParentSticky = g_menu.parents('.elementor-sticky'); 1563 1564 //only if .elementor-sticky exist 1565 if(!objParentSticky.length) 1566 return(false); 1567 1568 var objActiveMenuSections = jQuery('.uc-mega_menu_section.uc-active_item'); 1569 var visibleMenuSectionNum = objActiveMenuSections.length; 1570 1571 //only if active menu item section exist 1572 if(!visibleMenuSectionNum) 1573 return(false); 1574 1575 //only if active menu item section number grater than 1 1576 if(visibleMenuSectionNum == 1) 1577 return(false); 1578 1579 objActiveMenuSections.each(function(index, el){ 1580 1581 //look for index 1 only 1582 if(index == 0) 1583 return(true); 1584 1585 //hide opened section with opacity and pointer events 1586 el.style.opacity = 0; 1587 el.style.pointerEvents = 'none'; 1588 1589 if(g_isNotCustomResponsiveViewport.matches == true) 1590 return(true) 1591 1592 jQuery(this).removeClass('uc-active_item'); 1593 1594 }); 1595 1596 } 1597 1598 /** 1599 * find focused item and trigger event 1600 */ 1601 function findFocusedAndTrigger(e, eventToTrigger){ 1602 1603 //look at each title item 1604 g_menuItemTitle.each(function(){ 1605 1606 var objTitle = jQuery(this); 1607 1608 //if not focused then skip 1609 if(!objTitle.is(':focus')) 1610 return(true); 1611 1612 //if open menu type hover 1613 if(g_dataMenuOpen == 'hover') 1614 objTitle.trigger(eventToTrigger); 1615 1616 var activeMenuItemClick = objTitle.parents('.uc-mega_menu_list_item'); 1617 1618 //if open menu type click 1619 //if enter - check if active and open if not 1620 if(g_dataMenuOpen == 'click' && e.keyCode == 13){ 1621 1622 if(activeMenuItemClick.hasClass(g_classActive) == false){ 1623
1624 setActive(activeMenuItemClick); 1625 setActiveArrow(activeMenuItemClick); 1626 1627 } 1628 1629 } 1630 1631 //if esc - check if active and close if opened 1632 if(g_dataMenuOpen == 'click' && e.keyCode == 27){ 1633 1634 if(activeMenuItemClick.hasClass(g_classActive) == false) 1635 return(true); 1636 1637 setDisactive(); 1638 1639 } 1640 1641 e.preventDefault(); 1642 1643 }); 1644 1645 } 1646 1647 /** 1648 * find focused item and trigger open 1649 */ 1650 function findFocusedAndOpen(e){ 1651 1652 findFocusedAndTrigger(e, 'mouseenter'); 1653 1654 } 1655 1656 /** 1657 * find focused item and trigger close 1658 */ 1659 function findFocusedAndClose(e){ 1660 1661 findFocusedAndTrigger(e, 'mouseleave'); 1662 1663 } 1664 1665 /** 1666 * open / close with key press 1667 */ 1668 function onKeyDown(e){ 1669 1670 //do not listen on mobile devices 1671 if(g_isCustomResponsiveViewport.matches == true) 1672 return(true); 1673 1674 //if pressed key is enter then trigger open 1675 if(e.keyCode == 13) 1676 findFocusedAndOpen(e); 1677 1678 //if pressed key is esc then trigger close 1679 if(e.keyCode == 27) 1680 findFocusedAndClose(e); 1681 1682 } 1683 1684 /** 1685 * protection from parent backdrop filter css property 1686 **/ 1687 function backdropFilterProtection(){ 1688 1689 //find element with backdrop property 1690 var objElements = g_menu.parents('.elementor-element'); 1691 1692 if(!objElements.length) 1693 return(false); 1694 1695 //look at each element 1696 objElements.each(function(){ 1697 1698 var objElement = jQuery(this); 1699 var objElementBackdropProperty = objElement.css('backdrop-filter'); 1700 1701 //if none then skip 1702 if(objElementBackdropProperty == 'none') 1703 return(true); 1704 1705 //if not none then set to none 1706 objElement.css('backdrop-filter', 'none'); 1707 1708 }); 1709 1710 } 1711 1712 /* 1713 * lord icons protection 1714 */ 1715 function lordIconsProtection(){ 1716 1717 var objLordIcons = g_menu.find('lord-icon'); 1718 1719 if(!objLordIcons.length) 1720 return(false); 1721 1722 objLordIcons.each(function(){ 1723 1724 var objIcon = jQuery(this); 1725 var srcIcon = objIcon.attr('src'); 1726 1727 objIcon.attr('src','') 1728 1729 setTimeout(function(){ 1730 1731 objIcon.attr('src',srcIcon); 1732 1733 },600); 1734 1735 }); 1736 1737 } 1738 1739 1740 /* 1741 * init menu 1742 */ 1743 this.init = function(objMegaMenu, arrItems, urlAjax){ 1744 1745 //init globals 1746 g_menu = jQuery(objMegaMenu); 1747 1748 //protection for no menu element found 1749 if(!g_menu.length){ 1750 1751 console.log("Mega Menu not found"); 1752 1753 return(false); 1754 } 1755 1756 //backdrop filter protection 1757 setTimeout(backdropFilterProtection, 200); 1758 1759 g_menuSection = g_menu.find(".uc-mega_menu_section"); 1760 g_menuList = g_menu.find(".uc-mega_menu_list"); 1761 g_menuItem = g_menu.find(".uc-mega_menu_list_item"); 1762 g_menuItemTitle = g_menu.find(".uc-mega_menu_title"); 1763 g_menuListWrap = g_menu.find(".uc-mega_menu-wrapper"); 1764 g_indicator = g_menuItem.find('.sub-arrow'); 1765 g_objBody = jQuery("body"); 1766 g_objHtml = jQuery("html"); 1767 g_dataMenuOpen = g_menuList.data("menu-open"); 1768 g_objOverlay = g_menu.find('.uc_mega_menu_overlay'); 1769 g_menuWrapOffsetLeft = g_menuListWrap.offset().left; 1770 g_viewportWidth = jQuery(window).width(); 1771 g_dataPositionX = g_menuList.data("position-x"); 1772 g_dataEditor = g_menu.data("editor"); 1773 g_showErrors = g_menu.data("errors"); 1774 g_offsetX = g_menuList.data("offset-x"); 1775 g_dataCloseDelay = g_menuList.data("close-delay"); 1776 g_urlBase = urlAjax; 1777 1778 g_menuActiveClass = "uc-menu-open"; 1779 g_classSection = '.uc-mega_menu_section'; 1780 g_classActive = 'uc-active_item'; 1781 1782 g_isDesktopViewport = window.matchMedia("(min-width: 1025px)"); 1783 g_isNotDesktopViewport = window.matchMedia("(max-width: 1024px)"); 1784 1785 var customResponsiveBreakpoint = g_menuListWrap.data("responsive-breakpoint"); 1786
1787 g_isCustomResponsiveViewport = window.matchMedia("(max-width: " + customResponsiveBreakpoint + "px)"); 1788 g_isNotCustomResponsiveViewport = window.matchMedia("(min-width: " + (customResponsiveBreakpoint + 1) + "px)"); 1789 1790 g_arrItems = arrItems; 1791 1792 //remove any loader that was active 1793 var objLoaders = g_menu.find('.uc-mega-menu-item-loader'); 1794 1795 objLoaders.remove(); 1796 1797 //remove uc-arrow-hidden class from sub-arrows 1798 if(g_indicator.length) 1799 g_indicator.removeClass('uc-arrow-hidden'); 1800 1801 //if in editor do nothing with sections 1802 if(g_dataEditor == 'no') 1803 handleItemTypeSection(); 1804 1805 //if in editor debug sections 1806 if(g_dataEditor == 'yes') 1807 handleItemTypeSectionInEditor(); 1808 1809 var burgerMenu = g_menu.find(".uc-mega_menu-burger"); 1810 var closeBtn = g_menu.find(".uc-mega_menu-close-btn"); 1811 1812 //init events 1813 burgerMenu.on("click", onBurgerMenuClick); 1814 closeBtn.on("click", onCloseBurgerMenuBtnClick); 1815 1816 //if in editor do not open dropdown 1817 if(g_dataEditor == 'yes') 1818 return(false); 1819 1820 menuItemOpen(); 1821 1822 jQuery(window).on('resize', function(){ 1823 setTimeout(onWindowResize,100) 1824 }); 1825 1826 jQuery(window).on('scroll', function(){ 1827 setTimeout(onPageScroll,100); 1828 }); 1829 1830 g_menuListWrap.on('scroll', function(){ 1831 setTimeout(onPageScroll,100); 1832 }); 1833 1834 jQuery(window).on("keydown", function(e){ 1835 onKeyDown(e); 1836 }); 1837 1838 //lord icons load protection 1839 lordIconsProtection(); 1840 1841 } 1842}
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.