1/** 2 * Mobile Barba: reset scrollu po nawigacji SPA. 3 * Bundel resetuje scroll za wczeÅnie (hooks.enter); menu mobile blokuje scroll przez window.onscroll. 4 */ 5(function () { 6 'use strict'; 7 8 if (!document.querySelector('[data-barba="wrapper"]')) { 9 return; 10 } 11 12 var MOBILE_BP = 1024; 13 var mobileQuery = window.matchMedia('(max-width: ' + (MOBILE_BP - 1) + 'px)'); 14 15 function isMobileViewport() { 16 return mobileQuery.matches || window.innerWidth < MOBILE_BP; 17 } 18 19 function unlockScroll() { 20 window.onscroll = null; 21 document.body.style.overflow = ''; 22 document.documentElement.style.removeProperty('overflow'); 23 } 24 25 function setScrollRestorationManual() { 26 if ('scrollRestoration' in history) { 27 history.scrollRestoration = 'manual'; 28 } 29 } 30 31 function scrollToTop() { 32 if (!isMobileViewport()) { 33 return; 34 } 35 36 unlockScroll(); 37 38 try { 39 window.scrollTo(0, 0); 40 } catch (e) {} 41 42 try { 43 window.scrollTo({ top: 0, left: 0, behavior: 'auto' }); 44 } catch (e2) {} 45 46 if (document.documentElement) { 47 document.documentElement.scrollTop = 0; 48 document.documentElement.scrollLeft = 0; 49 } 50 51 if (document.body) { 52 document.body.scrollTop = 0; 53 document.body.scrollLeft = 0; 54 } 55 56 try { 57 if (window.ScrollTrigger) { 58 if (typeof window.ScrollTrigger.clearScrollMemory === 'function') { 59 window.ScrollTrigger.clearScrollMemory(); 60 } 61 if (typeof window.ScrollTrigger.refresh === 'function') { 62 window.ScrollTrigger.refresh(); 63 } 64 } 65 } catch (e3) {} 66 67 try { 68 var gsap = window.gsap; 69 if (gsap && gsap.core && typeof gsap.core.globals === 'function') { 70 var smoother = gsap.core.globals().ScrollSmoother; 71 if (smoother && typeof smoother.getAll === 'function') { 72 smoother.getAll().forEach(function (instance) { 73 if (instance && typeof instance.scrollTo === 'function') { 74 instance.scrollTo(0, false); 75 } 76 }); 77 } 78 } 79 } catch (e4) {} 80 } 81 82 var resetTimer = null; 83 84 function scheduleScrollReset() { 85 if (!isMobileViewport()) { 86 return; 87 } 88 89 if (resetTimer) { 90 clearTimeout(resetTimer); 91 } 92 93 scrollToTop(); 94 requestAnimationFrame(scrollToTop); 95 96 [0, 50, 120, 300, 550, 800, 1100, 1500].forEach(function (delay) { 97 setTimeout(scrollToTop, delay); 98 }); 99 100 resetTimer = setTimeout(function () { 101 resetTimer = null; 102 }, 1600); 103 } 104 105 function isInternalNavigationLink(link) { 106 if (!link || link.target === '_blank' || link.hasAttribute('download')) { 107 return false; 108 } 109 if (link.hasAttribute('data-barba-prevent')) { 110 return false; 111 } 112 113 var href = link.getAttribute('href') || ''; 114 if (!href || href.charAt(0) === '#') { 115 return false; 116 } 117 118 try { 119 return new URL(link.href, window.location.href).origin === window.location.origin; 120 } catch (e) { 121 return false; 122 } 123 } 124 125 if (isMobileViewport()) { 126 setScrollRestorationManual(); 127 } 128 129 if (typeof mobileQuery.addEventListener === 'function') { 130 mobileQuery.addEventListener('change', function (event) { 131 if (event.matches) { 132 setScrollRestorationManual(); 133 } 134 }); 135 } 136 137 function notifyPageChange() { 138 document.dispatchEvent(new CustomEvent('samoseo:page')); 139 } 140 141 ['pushState', 'replaceState'].forEach(function (method) { 142 var original = history[method]; 143 if (typeof original !== 'function') { 144 return; 145 } 146 147 history[method] = function () { 148 var result = original.apply(this, arguments); 149 scheduleScrollReset(); 150 notifyPageChange(); 151 return result; 152 }; 153 }); 154 155 window.addEventListener('popstate', function () { 156 scheduleScrollReset(); 157 notifyPageChange(); 158 }); 159 160 function headerOffset() { 161 var header = document.getElementById('header'); 162 return header ? Math.ceil(header.getBoundingClientRect().height) : 0; 163 } 164 165 function scrollToAnchor(target) { 166 unlockScroll(); 167 168 var top = target.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop) - headerOffset() - 12; 169 170 try { 171 window.scrollTo({ top: Math.max(0, top), left: 0, behavior: 'smooth' });
172 } catch (e) { 173 window.scrollTo(0, Math.max(0, top)); 174 } 175 } 176 177 document.addEventListener( 178 'click', 179 function (event) { 180 var link = event.target.closest && event.target.closest('a[href]'); 181 if (!link) { 182 return; 183 } 184 185 var href = link.getAttribute('href') || ''; 186 if (href.charAt(0) === '#') { 187 var id = href.slice(1); 188 if (!id) { 189 return; 190 } 191 192 var target = document.getElementById(id); 193 if (!target) { 194 try { 195 target = document.getElementById(decodeURIComponent(id)); 196 } catch (e) {} 197 } 198 if (!target) { 199 return; 200 } 201 202 event.preventDefault(); 203 event.stopPropagation(); 204 scrollToAnchor(target); 205 return; 206 } 207 208 if (!isMobileViewport()) { 209 return; 210 } 211 212 if (!isInternalNavigationLink(link)) { 213 return; 214 } 215 216 unlockScroll(); 217 scheduleScrollReset(); 218 }, 219 true 220 ); 221 222 var container = document.querySelector('[data-barba="container"]'); 223 if (container) { 224 new MutationObserver(function () { 225 scheduleScrollReset(); 226 notifyPageChange(); 227 }).observe(container, { childList: true }); 228 } 229})();
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.