Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Sklep
Kup Teraz [tcb-script]document.addEventListener(’DOMContentLoaded’, function () { /* ========= KONFIGURACJA (bez zmian) ========= */ const CAT_PARAM_KEYS = [’product_cat’]; const CAT_CONTAINER_CLASS = 'filter-cat’; const GROUP_CLASS = { supl: 'filter-supl’, gryz: 'filter-gryz’, wskaz: 'filter-wskaz’, edu: 'filter-edu’ }; const URL_KEYS = { supl: 'tag_supl’, gryz: 'tag_gryz’, wskaz: 'product_tag’, edu: 'tag_edu’ }; const OWNED = { 'suplementy’: [’supl’, 'wskaz’], 'psiekąski’: [’gryz’, 'wskaz’], 'psiekaski’: [’gryz’, 'wskaz’], 'edukacja’: [’edu’, 'wskaz’] }; /* ========= GŁÓWNA LOGIKA „STRAŻNIKA” (bez zmian) ========= */ const norm = txt => (txt || ”).toString().trim().toLowerCase().normalize(’NFD’).replace(/[u0300-u036f]/g, ”); let lastKnownCategory = (new URLSearchParams(window.location.search)).get(’product_cat’) || null; function checkAndApplyState() { const currentUrl = new URL(window.location.href); const currentCategory = currentUrl.searchParams.get(’product_cat’); if (currentCategory === lastKnownCategory) { return; } lastKnownCategory = currentCategory; const activeCats = (currentCategory || ”).split(’,’).map(norm).filter(Boolean); const activeGroups = new Set(); activeCats.forEach(cat => (OWNED[cat] || []).forEach(g => activeGroups.add(g))); const nothingSelected = activeCats.length === 0; let urlNeedsCleaning = false; Object.keys(GROUP_CLASS).forEach(key => { const isGroupActive = nothingSelected || activeGroups.has(key); if (!isGroupActive) { const urlKeyForGroup = URL_KEYS[key]; if (urlKeyForGroup && currentUrl.searchParams.has(urlKeyForGroup)) { currentUrl.searchParams.delete(urlKeyForGroup); urlNeedsCleaning = true; } } }); if (urlNeedsCleaning) { window.location.href = currentUrl.toString(); } } function applyVisualState() { const params = new URLSearchParams(window.location.search); const activeCats = (params.get(’product_cat’) || ”).split(’,’).map(norm).filter(Boolean); const activeGroups = new Set(); activeCats.forEach(cat => (OWNED[cat] || []).forEach(g => activeGroups.add(g))); const nothingSelected = activeCats.length === 0; Object.values(GROUP_CLASS).forEach(className => { document.querySelectorAll(’.’ + className).forEach(root => { const key = Object.keys(GROUP_CLASS).find(k => GROUP_CLASS[k] === className.replace(’.’,”)); const isGroupActive = nothingSelected || activeGroups.has(key); root.classList.toggle(’ps-collapsed’, !isGroupActive); root.classList.toggle(’ps-disabled’, !isGroupActive); }); }); } /* ========= NOWA, NIEZAWODNA WERSJA – OBSŁUGA PRZYCISKU RESETOWANIA ========= */ function setupResetButton() { // Ta metoda nasłuchuje na kliknięcia w całym dokumencie. // Dzięki temu zadziała nawet na przyciskach, które pojawią się później (np. w pop-upie). document.body.addEventListener(’click’, function(event) { // Sprawdzamy, czy kliknięty element (lub jego rodzic) ma naszą klasę. const resetButton = event.target.closest(’.przycisk-reset-filtry’); if (resetButton) { // Jeśli tak, zatrzymaj domyślną akcję i wykonaj reset. event.preventDefault(); const cleanUrl = window.location.origin + window.location.pathname; window.location.href = cleanUrl; } }); } /* ========= URUCHOMIENIE I INICJALIZACJA ========= */ const sel = Object.values(GROUP_CLASS).map(c => ’.’ + c).join(’,’); document.querySelectorAll(sel).forEach(root => { root.classList.add(’ps-toggle-group’); const children = Array.from(root.children); if (children.length <= 1) return; const contentNodes = children.slice(1); const contentWrapper = document.createElement(’div’); contentWrapper.className = 'ps-toggle-content’; contentNodes.forEach(node => contentWrapper.appendChild(node)); root.appendChild(contentWrapper); }); applyVisualState(); setInterval(checkAndApplyState, 250); const observer = new MutationObserver(applyVisualState); observer.observe(document.body, { childList: true, subtree: true }); setupResetButton();});[/tcb-script]





















