(function($) { $(document).ready(function() { // Lightbox für RTE mit Bildern if ($('.product img[data-htmlarea-zoom="true"]').length) { $('.product img[data-htmlarea-zoom="true"]').each(function () { $(this).wrap(''); }); } console.log('🚀:ready'); $().initCookiePreferences(); $().getUserInfoByAjax(); $().getMainNavByAjax(); $().getTopNavByAjax(); $().getMessagesByAjax(function(){ if($('.typo3-messages').length) { $('.typo3-messages').find('.alert').addClass('fade show alert-dismissible').append(''); //setTimeout(function() { $('.typo3-messages').fadeOut(600, function() { $(this).remove(); }); }, 6000); } }); $('body').addClass('loaded'); let totopoff = 111; if (window.matchMedia("(min-width: 768px)").matches) { totopoff = 144; } if (window.location.hash) { let hash = window.location.hash; console.log(hash); if ($(hash).length) { $('html,body').animate({scrollTop: $(hash).offset().top - totopoff}, 600); } } $('a.scroll-link').on('click', function (e) { e.preventDefault(); let hash = this.hash; let linkid = $(hash); let idtotop = 0; if ($(linkid).length) { idtotop = parseInt($(linkid).offset().top); } $('html,body').animate({scrollTop: idtotop - totopoff}, 600); }); let header = $('#header'), headspacer = $('#headspacer'), headheight = header.height(), winheight = $(window).height(), winwidth = $(window).width(), wintotop = $(window).scrollTop(), stoff = 56; function navCalc() { if (wintotop > stoff) { header.addClass('sticky'); headspacer.addClass('sticked'); headheight = headspacer.height(); } else { headspacer.removeClass('sticked'); header.removeClass('sticky'); headheight = header.height(); } } navCalc(); $(window).resize(function () { winheight = $(window).height(); winwidth = $(window).width(); navCalc(); }); function navSwitch() { if (wintotop > stoff) { header.addClass('sticky'); headspacer.addClass('sticked'); headheight = headspacer.height(); } else { headspacer.removeClass('sticked'); header.removeClass('sticky'); headheight = header.height(); } } navSwitch(); $(window).scroll(function () { wintotop = $(window).scrollTop(); navSwitch(); }); $('.scroll-up').on('click', function (e) { e.preventDefault(); e.stopPropagation(); $('html,body').animate({scrollTop: 0}, 600); }); $('.header__search--input').focus(function() { if ($(this).is(":focus")) { $('.header__search').addClass('open'); } }); $('.header__search--input').bind('keypress keydown keyup', function (e) { if (e.keyCode == 13) { e.preventDefault(); $('.header__search').submit(); } }); $('.header__search .search-btn').on('click', function (e) { e.preventDefault(); e.stopPropagation(); if ($('.header__search').hasClass('open')){ $('.header__search').submit(); } else { $('.header__search').addClass('open'); setTimeout(function() { $('.header__search--input').focus(); }, 600); } }); $('.header__search .search-close').on('click', function (e) { e.preventDefault(); if ($('.header__search').hasClass('open')){ $('.header__search').removeClass('open'); } }); $('[data-bs-toggle="tooltip"]').tooltip(); // $('[data-bs-toggle="collapse"]').collapse(); $('[data-bs-toggle="dropdown"]').dropdown(); $('.navbar-toggler').on('click', function (e) { $('body').toggleClass('overflow'); }); if (window.matchMedia("(max-width: 991px)").matches) { new SimpleBar($('#navbar')[0]); $(document).on('click','.submenu-toggle',function(e) { e.preventDefault(); e.stopPropagation(); if($(this).hasClass('open')) { window.location.href = $(this).attr('href'); } else { if($(this).next('.submenu').length){ $(this).next('.submenu').toggle(); } $(this).addClass('open'); } }); $(document).on('click','.navbar .dropdown-toggle',function(e) { e.preventDefault(); e.stopPropagation(); if($(this).hasClass('open')) { window.location.href = $(this).attr('href'); } else { if($(this).next('.dropdown-menu').length){ $(this).next('.dropdown-menu').toggle(); } $(this).addClass('open'); } }); } $(".pswp-img").jqPhotoSwipe({ galleryOpen: function (gallery) { }, shareEl: false, }); $(".gallery .pswp-img").jqPhotoSwipe({ forceSingleGallery: true }); if($('.teaser').length) { $(document).on('click','.teaser-toggle',function(e) { let container = $(this).parents('div[class^="container"]'), teaser = $(this).parent('.teaser'); if (window.matchMedia("(max-width: 767px)").matches) { container = $(this);0 } if(teaser.hasClass('active')) { $('.teaser__content.show').slideUp("normal", function() { $(this).remove(); } ); teaser.removeClass('active'); } else { $('.teaser__content.show').slideUp("normal", function() { $(this).remove(); } ); $('.teaser').each(function() { $(this).removeClass('active'); }); teaser.addClass('active'); // desktop teaser.children('.teaser__content').clone().insertAfter(container).addClass('show').slideDown(600); } }); } if($('.contenttable').length) { $('.contenttable').basictable(); } // Cookie Handling function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } let openNewsletterPopup = function() { let newsletterPopup = $('#newsletterPopup'); newsletterPopup.removeClass('hide') let resetFunction = function() { newsletterPopup.addClass('hide') $('header').css('filter', 'unset'); $('main').css('filter', 'unset'); $('footer').css('filter', 'unset'); } if (newsletterPopup) { let screenHeight = document.documentElement.clientHeight; if (870 <= screenHeight && document.documentElement.clientWidth > 500) { newsletterPopup.css('bottom', '0px'); newsletterPopup.css('top', 'unset'); newsletterPopup.css('position', 'fixed'); } $('header').css('filter', 'blur(5px)'); $('main').css('filter', 'blur(5px)'); $('footer').css('filter', 'blur(5px)'); newsletterPopup.css('filter', 'unset'); newsletterPopup.find('.close').on('click', function (){ resetFunction(); }); $(window).on('keydown', function(e){ if (e.code == 'Escape') { resetFunction(); } }); } if (getCookie('bosch-privacy-v2') && JSON.parse(getCookie('bosch-privacy-v2')).marketing) { setCookie('newsletter', "1", 2) } } // Newsletterpopup if($('.hero--start').length && $('html').attr('lang') == 'de-DE' ) { // if (!getCookie('newsletter')) { // if (!getCookie('bosch-privacy-v2')) { // setTimeout(function() { // let cookieBanner = $('.BoschPrivacySettingsV2') // var observer = new MutationObserver(function(mutations) { // mutations.forEach(function(mutation) { // if (mutation.attributeName == 'aria-hidden') { // openNewsletterPopup(); // } // }); // }); // if ($('.BoschPrivacySettingsV2').attr('aria-hidden') == 'true') { // openNewsletterPopup(); // } else { // observer.observe(cookieBanner[0], { // attributes: true // }); // } // }, 1000); // } else { // setTimeout(function() { // openNewsletterPopup(); // if (getCookie('bosch-privacy-v2') && JSON.parse(getCookie('bosch-privacy-v2')).marketing) { // setCookie('newsletter', "1", 2) // } // }, 1000); // } // } } // Filter toggle if ($('.products-filter').length) { const filterToggle = document.querySelector('.filter-toggle'); const filterAccordion = document.querySelector('.products-filter'); const overlay = document.querySelector('.overlay'); const body = document.querySelector('body'); if (window.matchMedia("(max-width: 991px)").matches) { filterAccordion.classList.add('hidden'); } filterToggle.addEventListener('click', function() { filterAccordion.classList.toggle('hidden'); overlay.classList.toggle('show'); body.classList.toggle('filter-open'); }); window.addEventListener('resize', function() { if (window.matchMedia("(max-width: 991px)").matches) { filterAccordion.classList.add('hidden'); } else { filterAccordion.classList.remove('hidden'); overlay.classList.remove('show'); body.classList.remove('filter-open'); } }); } }); $.fn.getUserInfoByAjax = function (callback) { jQuery.ajax({ async: 'false', url: window.location.protocol + "//" + window.location.hostname + '/'+$().getLanguage()+'ajax.userinfo', data: {}, type: 'POST', dataType: 'html', beforeSend: function () { }, success: function (result) { var html = $.parseHTML(result); $('#usermenu').replaceWith(html); if (typeof callback === 'function') { callback(step); } }, error: function (error) { console.log(error); } }); } $.fn.getMainNavByAjax = function (callback) { jQuery.ajax({ async: 'false', url: window.location.protocol + "//" + window.location.hostname + '/'+$().getLanguage()+'ajax.mainnav', data: {}, type: 'POST', dataType: 'html', beforeSend: function () { }, success: function (result) { var html = $.parseHTML(result); $('#mainmenu').replaceWith(html); if (typeof callback === 'function') { callback(step); } }, error: function (error) { console.log(error); } }); } $.fn.getTopNavByAjax = function (callback) { jQuery.ajax({ async: 'false', url: window.location.protocol + "//" + window.location.hostname + '/'+$().getLanguage()+'ajax.topnav', data: {}, type: 'POST', dataType: 'html', beforeSend: function () { }, success: function (result) { var html = $.parseHTML(result); $('#topmenu').replaceWith(html); if (typeof callback === 'function') { callback(step); } }, error: function (error) { console.log(error); } }); } $.fn.getMessagesByAjax = function (callback) { let url = ''; if ($().getUrlParameter('logout') === '1') { url = window.location.protocol + "//" + window.location.hostname + '/' + $().getLanguage() + 'ajax.messages?logout=1'; } else if ($().getUrlParameter('login') === '1') { url = window.location.protocol + "//" + window.location.hostname + '/' + $().getLanguage() + 'ajax.messages?login=1'; } else { url = window.location.protocol + "//" + window.location.hostname + '/' + $().getLanguage() + 'ajax.messages'; } jQuery.ajax({ async: 'false', url: url, data: {}, type: 'POST', dataType: 'html', beforeSend: function () { }, success: function (result) { var html = $.parseHTML(result); $('#messages').replaceWith(html); if (typeof callback === 'function') { callback(); } }, error: function (error) { console.log(error); } }); } $.fn.getLanguage = function(){ var htmlLang = $('html').attr('lang'); switch (htmlLang) { case 'en': return 'en/'; default: return ''; } } $.fn.getUrlParameter = function (sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return typeof sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; $.fn.initCookiePreferences = function () { let germanPrivacyLink = $('.nav-link[title="Privatsphäre-Einstellungen"]'); if (germanPrivacyLink.length) { germanPrivacyLink.on("click", function (e) { e.preventDefault(); e.stopPropagation(); showDockPrivacySettings(); }) } let englishPrivacyLink = $('.nav-link[title="Privacy settings"]'); if (englishPrivacyLink.length) { englishPrivacyLink.on("click", function (e) { e.preventDefault(); e.stopPropagation(); showDockPrivacySettings(); }) } }; })(jQuery);