function switchCurrency(currency) { setCookie('currency', currency, 30); window.location.reload(); } function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; } function updateUrlParams(additionalParams) { // Parsing the current URL's search parameters into a URLSearchParams object const currentParams = new URLSearchParams(window.location.search); // Create an object to store the parameters we want to keep const paramsToKeep = {}; // List of parameters to retain from the current URL const retainParams = ['q', 'from_price', 'to_price', 'moq']; // Keep only the specified parameters from the current URL retainParams.forEach(param => { if (currentParams.has(param)) { paramsToKeep[param] = currentParams.get(param); } }); // Merge the retained parameters with the additional ones const updatedParams = Object.assign(paramsToKeep, additionalParams); // Remove undefined, null, and false values from the merged parameters Object.keys(updatedParams).forEach(key => { if (updatedParams[key] === undefined || updatedParams[key] === null || updatedParams[key] === false) { delete updatedParams[key]; } }); // Convert the cleaned object back into a URL search string const searchParams = new URLSearchParams(updatedParams).toString(); // Redirect to the new URL with the updated search parameters window.location.href = window.location.pathname + '?' + searchParams; } function getCurrentLanguage() { const path = window.location.pathname; const match = path.match(/^\/([a-z]{2})\//); return match ? match[1] : null; } document.querySelectorAll('.delayed-hover').forEach(item => { let hoverTimeout = null; let leaveTimeout = null; item.addEventListener('mouseenter', () => { clearTimeout(leaveTimeout); // Verhindern, dass hover entfernt wird, wenn schnell zurückgekehrt wird hoverTimeout = setTimeout(() => { item.classList.add('hover'); }, 80); // Verzögerung vor dem Hinzufügen von .hover }); item.addEventListener('mouseleave', () => { clearTimeout(hoverTimeout); // Verhindern, dass .hover hinzugefügt wird, wenn schnell verlassen wird leaveTimeout = setTimeout(() => { item.classList.remove('hover'); }, 150); // Verzögerung vor dem Entfernen von .hover }); }); function showPopoverMenu(popoverClass) { // Selektiert das zu togglen-de Popover anhand der übergebenen Klasse const popover = document.querySelector('.'+popoverClass); // Prüft, ob das angeklickte Popover bereits sichtbar ist const isPopoverVisible = popover.classList.contains('show-popover'); // Entfernt 'show-popover' von allen Elementen document.querySelectorAll('.has-popover.show-popover').forEach(function(el) { el.classList.remove('show-popover'); }); // Toggle das Popover nur, wenn es vorher nicht sichtbar war if (!isPopoverVisible) { popover.classList.add('show-popover'); } // Verhindert das Schließen des Popovers, wenn innerhalb des Popovers geklickt wird popover.addEventListener('click', function(event) { event.stopPropagation(); }); } // Fügt dem Document einen Listener hinzu, um Popovers zu schließen, wenn außerhalb geklickt wird document.addEventListener('click', function(event) { const isClickInsidePopover = event.target.closest('.has-popover.show-popover'); // Wenn nicht innerhalb eines sichtbaren Popovers geklickt wird, schließe alle if (!isClickInsidePopover) { document.querySelectorAll('.has-popover.show-popover').forEach(function(el) { el.classList.remove('show-popover'); }); } }); function setQueryParams(params) { // Create a new URL object based on the current URL let url = new URL(window.location.href); // Iterate over each property in the params object Object.keys(params).forEach(key => { // Set each query parameter to its new value (or add it if it doesn't exist) url.searchParams.set(key, params[key]); }); // Navigate to the updated URL, causing the page to reload window.location.href = url.toString(); } function toggleMobileMenu() { let mainMenu = document.getElementById('main-menu'); mainMenu.classList.toggle('visible'); } function gotoCategories() { if (window.matchMedia("(max-width: 700px)").matches) { // Get the current path let currentPath = window.location.pathname; // Extract the language code (assuming it's the first part of the path) let languageCode = currentPath.split('/')[1]; // Construct the new URL let newUrl = '/' + languageCode + '/categories'; // Redirect to the new URL window.location.href = newUrl; } }