1// P03: sostituiscono _.throttle / _.debounce di Lodash (rimosso da header.php). 2// swThrottle: leading + trailing, equivalente al default di Lodash. 3function swThrottle(fn, wait) { 4 var last = 0, timer = null, lastArgs = null, lastThis = null; 5 wait = wait || 0; 6 return function () { 7 var now = Date.now(); 8 var remaining = wait - (now - last); 9 lastArgs = arguments; lastThis = this; 10 if (remaining <= 0 || remaining > wait) { 11 if (timer) { clearTimeout(timer); timer = null; } 12 last = now; 13 fn.apply(lastThis, lastArgs); 14 } else if (!timer) { 15 timer = setTimeout(function () { 16 last = Date.now(); 17 timer = null; 18 fn.apply(lastThis, lastArgs); 19 }, remaining); 20 } 21 }; 22} 23// swDebounce: trailing edge, equivalente al default di Lodash. 24function swDebounce(fn, wait) { 25 var timer = null; 26 wait = wait || 0; 27 return function () { 28 var args = arguments, ctx = this; 29 if (timer) clearTimeout(timer); 30 timer = setTimeout(function () { timer = null; fn.apply(ctx, args); }, wait); 31 }; 32} 33 34jQuery(document).ready(function() { 35 const topSpacing = jQuery(".desktop.landscape body").hasClass("admin-bar") ? 32 : 0; 36 // Sticky Navigation 37 jQuery(".stickyNav").sticky({ 38 topSpacing: topSpacing, 39 zIndex: 100000 40 }); 41 // OPTIMIZED: Funzione per gestire gli elementi sticky con cleanup 42 const handleSticky = (selector, removeClass) => { 43 const element = jQuery(selector); 44 if (!element.length) return; 45 const stickyTop = element.offset().top; 46 let goSticky = true; 47 let scrollHandler = null; 48 scrollHandler = swThrottle(() => { 49 const windowScrollTop = jQuery(window).scrollTop(); 50 if (windowScrollTop >= stickyTop && goSticky) { 51 element.addClass('sticky'); 52 setTimeout(() => { 53 element.removeClass(`${removeClass} sticky`); 54 goSticky = false; 55 // OPTIMIZED: Remove listener after sticky is done 56 if (scrollHandler) { 57 jQuery(window).off('scroll', scrollHandler); 58 scrollHandler = null; 59 } 60 }, 2500); 61 } else { 62 element.removeClass('sticky'); 63 } 64 }, 100); 65 jQuery(window).on('scroll', scrollHandler); 66 }; 67 // Applicazione della funzione sticky a seconda del dispositivo 68 if (device.desktop() || device.tablet()) { 69 handleSticky('.pushbarSticky', 'pushbarSticky'); 70 } 71 if (device.mobile()) { 72 handleSticky('.mobileTopSticky', 'mobileTopSticky'); 73 } 74 // OPTIMIZED: Gestione dello sticky per il video con cleanup 75 consentCallbackQueue.push((googleAllowed, purposeOneAllowed) => { 76 if (!(googleAllowed && purposeOneAllowed)) return; 77 const video = jQuery(".videoSticky").first(); 78 if (!video.length) return; 79 // Su mobile, se il video ha noMobile non attivare lo sticky 80 if (video.hasClass('noMobile') && device.mobile()) return; 81 82 const homeVideo = jQuery("#home-video"); 83 const videoWrap = video.closest('.videoWrap'); 84 const stickyBanner = device.desktop() || device.tablet() ? jQuery(".pushbarLG") : jQuery(".mobile_top"); 85 let isStuck = false; 86 let videoScrollHandler = null; 87 const updateVideoDimensions = () => { 88 let pl = jQuery(".video-js, .video-js video"); 89 let videoWidth = video.outerWidth(); 90 let videoHeight = video.outerHeight(); 91 if(videoWidth < videoHeight){ 92 video.width(`${videoHeight}px`).height(`${videoWidth}px`); 93 pl.width(`${videoHeight}px`); 94 } else { 95 video.width(`${videoWidth}px`).height(`${videoHeight}px`); 96 pl.width(`${videoWidth}px`); 97 } 98 }; 99 // OPTIMIZED: Cache offset values and update on resize only 100 let videoOffset = videoWrap.offset().top + videoWrap.outerHeight(); 101 jQuery(window).on('resize', swDebounce(() => { 102 videoOffset = videoWrap.offset().top + videoWrap.outerHeight(); 103 }, 250)); 104 videoScrollHandler = swThrottle(() => { 105 if (stickyBanner.hasClass('sticky')) return; 106 const windowScrollTop = jQuery(window).scrollTop(); 107 if (windowScrollTop > videoOffset && !isStuck && video.attr('data-sticky-disabled') !== '1') { 108 video.addClass("stuck"); 109 updateVideoDimensions(); 110 isStuck = true; 111 } else if (windowScrollTop <= videoOffset && isStuck) { 112 video.removeClass("stuck").width("auto").height("auto"); 113 updateVideoDimensions(); 114 isStuck = false;
115 } 116 }, 100); 117 jQuery(window).on("scroll", videoScrollHandler); 118 // OPTIMIZED: Cleanup on page unload 119 jQuery(window).on('beforeunload', () => { 120 if (videoScrollHandler) { 121 jQuery(window).off('scroll', videoScrollHandler); 122 } 123 }); 124 }); 125});
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.