1/* global woodmart_settings */ 2(function($) { 3 woodmartThemeModule.headerBuilder = function() { 4 var $header = $('.whb-header'), 5 $headerBanner = $('.header-banner'), 6 $stickyElements = $('.whb-sticky-row'), 7 $firstSticky = '', 8 $window = woodmartThemeModule.$window, 9 isSticked = false, 10 stickAfter = 300, 11 cloneHTML = '', 12 previousScroll, 13 isHideOnScroll = $header.hasClass('whb-hide-on-scroll'); 14 15 $stickyElements.each(function() { 16 var $this = $(this); 17 18 if ($this[0].offsetHeight > 10) { 19 $firstSticky = $this; 20 return false; 21 } 22 }); 23 24 // Real header sticky option 25 if ($header.hasClass('whb-sticky-real') || $header.hasClass('whb-scroll-slide')) { 26 var $adminBar = $('#wpadminbar'); 27 var headerHeight = $header.find('.whb-main-header')[0].offsetHeight; 28 var adminBarHeight = $adminBar.length > 0 ? $adminBar[0].offsetHeight : 0; 29 30 if ($header.hasClass('whb-sticky-real')) { 31 // if no sticky rows 32 if ($firstSticky.length === 0 || $firstSticky[0].offsetHeight < 10 || 'undefined' !== typeof elementorFrontend && elementorFrontend.isEditMode()) { 33 return; 34 } 35 36 $header.addClass('whb-sticky-prepared').css({ 37 paddingTop: headerHeight 38 }); 39 40 stickAfter = Math.ceil($firstSticky.offset().top) - adminBarHeight; 41 } 42 43 if ($header.hasClass('whb-scroll-slide')) { 44 stickAfter = headerHeight + adminBarHeight; 45 } 46 } 47 48 if ($header.hasClass('whb-sticky-clone')) { 49 var data = []; 50 data['cloneClass'] = $header.find('.whb-general-header').attr('class'); 51 52 if (isHideOnScroll) { 53 data['wrapperClasses'] = 'whb-hide-on-scroll'; 54 } 55 56 cloneHTML = woodmart_settings.whb_header_clone; 57 58 cloneHTML = cloneHTML.replace(/<%([^%>]+)?%>/g, function(replacement) { 59 var selector = replacement.slice(2, -2); 60 61 return $header.find(selector).length 62 ? $('<div>') 63 .append($header.find(selector).first().clone()) 64 .html() 65 : (data[selector] !== undefined) ? data[selector] : ''; 66 }); 67 68 cloneHTML = cloneHTML.replace(/<link[^>]*>/g, ''); 69 70 $header.after(cloneHTML); 71 $header = $header.parent().find('.whb-clone'); 72 73 $header.find('.whb-row').removeClass('whb-flex-equal-sides').addClass('whb-flex-flex-middle'); 74 } 75 76 $window.on('scroll', function() { 77 var after = stickAfter; 78 var currentScroll = woodmartThemeModule.$window.scrollTop(); 79 var windowHeight = woodmartThemeModule.$window.height(); 80 var documentHeight = woodmartThemeModule.$document.height(); 81 82 if ($headerBanner.length > 0 && woodmartThemeModule.$body.hasClass('header-banner-display')) { 83 after += $headerBanner[0].offsetHeight; 84 } 85 86 if (!$('.close-header-banner').length && $header.hasClass('whb-scroll-stick')) { 87 after = stickAfter; 88 } 89 90 if (currentScroll > after) { 91 stickHeader(); 92 } else { 93 unstickHeader(); 94 } 95 96 var startAfter = 100; 97 98 if ($header.hasClass('whb-scroll-stick')) { 99 startAfter = 500; 100 } 101 102 if (isHideOnScroll) { 103 if (previousScroll - currentScroll > 0 && currentScroll > after) { 104 $header.addClass('whb-scroll-up'); 105 $header.removeClass('whb-scroll-down'); 106 } else if (currentScroll - previousScroll > 0 && currentScroll + windowHeight !== documentHeight && currentScroll > (after + startAfter)) { 107 $header.addClass('whb-scroll-down'); 108 $header.removeClass('whb-scroll-up'); 109 } else if (currentScroll <= after) { 110 $header.removeClass('whb-scroll-down'); 111 $header.removeClass('whb-scroll-up'); 112 } else if (currentScroll + windowHeight >= documentHeight - 5) { 113 $header.addClass('whb-scroll-up'); 114 $header.removeClass('whb-scroll-down'); 115 } 116 } 117 118 previousScroll = currentScroll; 119 }); 120 121 function stickHeader() { 122 if (isSticked) { 123 return; 124 } 125 126 isSticked = true; 127 $header.addClass('whb-sticked'); 128 menuDropdownRecalc(); 129 } 130 131 function unstickHeader() { 132 if (!isSticked) { 133 return; 134 } 135 136 isSticked = false; 137 $header.removeClass('whb-sticked'); 138 menuDropdownRecalc(); 139 } 140 141 function menuDropdownRecalc() { 142 if (!$header.hasClass('whb-boxed')) { 143 return; 144 } 145 146 $('.wd-offsets-calculated .wd-dropdown-menu').attr('style', ''); 147 $('.wd-offsets-calculated').removeClass('wd-offsets-calculated'); 148 woodmartThemeModule.$window.trigger('wdHeaderBuilderStickyChanged'); 149 } 150
151 woodmartThemeModule.$document.trigger('wdHeaderBuilderInited'); 152 }; 153 154 woodmartThemeModule.$window.on('wdEventStarted', function() { 155 woodmartThemeModule.headerBuilder(); 156 }); 157})(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.