/*! * jquery.theme.js * * @link https://www.vektorrausch.de * @author vektorrausch GmbH * * @package WordPress * @subpackage cleantheme */ jQuery('document').ready(function($) { var $window = $(window); var $document = $(document); var $bodyHtml = $('html, body'); var $body = $('body'); /* ######################################## *\ A GOOD START JS \* ######################################## */ /* Effizienteres Resize-Event mit setTimeout $window.on('agoodstart-resize', function(e, resizeEvent){}); */ var resizeTimer; var resizeTickrate = 80; $window.resize(function(e) { clearTimeout(resizeTimer); resizeTimer = setTimeout(function() { $window.trigger('agoodstart-resize', e); }, resizeTickrate); }).trigger('resize'); /* Effizienteres Scroll-Event mit setTimeout $window.on('agoodstart-scroll', function(e, scrollEvent){}); */ var scrollTimer; var scrollTickrate = 80; $window.scroll(function(e) { clearTimeout(scrollTimer); scrollTimer = setTimeout(function() { $window.trigger('agoodstart-scroll', e); }, scrollTickrate); }).trigger('scroll'); /* ######################################## *\ LINKS & SPRUNGMARKEN \* ######################################## */ /* Externe Links */ $('.field-body a[href^="http"], .field-excerpt a[href^="http"], a.external').not('a[href*="' + window.location.host + '"], a.no-external, a.not-external').each(function(index, element) { if (window.location.host.substr(0, 3) == 'www' && $(this).attr('href').indexOf(window.location.host.substr(4)) > 0) { return; } if (!$(this).find('img').length) { $(this).addClass('external').attr('target', '_blank').attr('rel', 'noopener'); } }); /* Nach Oben scrollen */ $document.on('click', 'a[href*="#top"]', function(e) { $bodyHtml.animate({ scrollTop : '0px' }, 500, 'swing'); e.preventDefault(); }); /* Nach Unten scrollen */ $document.on('click', 'a[href*="#down"]', function(e) { $bodyHtml.animate({ scrollTop : '+=' + $window.height() + 'px' }, 500, 'swing'); e.preventDefault(); }); /* Zum Anker scrollen */ $document.on('click', 'a[href*="#"]:not(a[href*="#top"], a[href*="#down"])', function(e) { var anchor = this.hash; if ($(anchor).length) { $bodyHtml.animate({ scrollTop : $(anchor).offset().top - 35 }, 500, 'swing'); e.preventDefault(); } }); /* Weiter scrollen oder wieder nach oben */ if ($('#guide').length) { var hideGuideToBottom = 320; var showGuideToTop = 0; var showGuideToTopOffset = 120; var $guideToBottom = $('#guide .down'); var $guideToTop = $('#guide .top'); $window.on('agoodstart-scroll', function(e, scrollEvent) { showGuideToTop = $document.height() - $window.height() - showGuideToTopOffset; if ($(this).scrollTop() >= 0) { $guideToBottom.removeClass('hide'); $guideToTop.addClass('hide'); } if ($(this).scrollTop() >= hideGuideToBottom) { $guideToBottom.addClass('hide'); $guideToTop.addClass('hide'); } if ($(this).scrollTop() >= showGuideToTop) { $guideToBottom.addClass('hide'); $guideToTop.removeClass('hide'); } if ($document.height() <= $window.height() + 10) { $guideToBottom.addClass('hide'); $guideToTop.addClass('hide'); } }); $window.resize('agoodstart-resize', function() { $window.trigger('scroll'); }); } /* ######################################## *\ MISC \* ######################################## */ /* wp-block-spacer */ if ($('.wp-block-spacer').length) { $('.wp-block-spacer').each(function(i, e) { let $elem = $(this); let height = $elem.height(); let cssClass = 'default'; if (height < 25) { cssClass = 'small'; } if (height >= 25) { cssClass = 'medium'; } if (height >= 50) { cssClass = 'large'; } if (height >= 100) { cssClass = 'huge'; } $(this).addClass('wp-block-spacer--' + cssClass); }); } /* Styled Select */ $('select.style-select').each(function(index, element) { $(this).wrap('').after(''); }); /* Material Placeholder */ $('.field-placeholder').each(function(index, element) { var $placeholder = $(this); $('input, textarea, select', $placeholder.not('input[type="radio"], input[type="checkbox"]')).focus(function() { $placeholder.addClass('placeholder-active'); }); $('input, textarea, select', $placeholder.not('input[type="radio"], input[type="checkbox"]')).blur(function() { if ($.trim($(this).val()) != '') { $placeholder.addClass('placeholder-active'); } else { $placeholder.removeClass('placeholder-active'); } }).trigger('blur'); }); /* WPCF7 Bewertungssystem */ if ($('.wpcf7-form .field-rating').length) { $('.wpcf7-form .field-rating .wpcf7-list-item label').hover( function() { var $list = $(this).parents('.field-rating'); var rating = $(this).find('input').val(); $('.wpcf7-list-item', $list).each(function(index, element) { if (index <= rating - 1) { $(element).addClass('active'); } else { $(element).removeClass('active'); } }); }, function() { var $list = $(this).parents('.field-rating'); var rating = $('.wpcf7-list-item.selected', $list).find('input').val(); $('.wpcf7-list-item', $list).each(function(index, element) { if (index <= rating - 1) { $(element).addClass('active'); } else { $(element).removeClass('active'); } }); } ); $('.wpcf7-form .field-rating .wpcf7-list-item label').click(function() { var $list = $(this).parents('.field-rating'); var rating = $(this).find('input').val(); $('.wpcf7-form .field-rating .wpcf7-list-item').removeClass('selected'); if ($(this).find('input').is(':checked')) { $(this).parent().addClass('selected'); } else { rating = 0; } $('.wpcf7-list-item', $list).each(function(index, element) { if (index <= rating - 1) { $(element).addClass('active'); } else { $(element).removeClass('active'); } }); }); $('.wpcf7').on('wpcf7:mailsent', function(e) { $('.wpcf7-form .field-rating .wpcf7-list-item').removeClass('selected').removeClass('active'); $('.wpcf7-form .field-rating .wpcf7-list-item.last').addClass('selected'); }); var $default = $('.wpcf7-form .field-rating input:checked'); if ($default.length) { var $list = $default.parents('.field-rating'); var rating = $default.val(); $default.parents('.wpcf7-list-item').addClass('selected'); $('.wpcf7-list-item', $list).each(function(index, element) { if (index <= rating - 1) { $(element).addClass('active'); } else { $(element).removeClass('active'); } }); } } /* Tablepress */ if ($('table.tablepress').length) { $('table.tablepress').each(function(index, element) { var $this = $(this); if ($this.css('min-width') !== 'none') { $this.wrap('
'); } }); } /* wow.js */ if ($('body.wow-js .animate').length) { wow = new WOW({ boxClass: 'animate', animateClass: 'animated', offset: 35, mobile: true, live: true }); wow.init(); } /* aos.js */ if ($('body.aos-js').length) { AOS.init({ offset: 120, duration: 400, easing: 'ease', delay: 0, once: false, disable: 'mobile', useClassNames: true, animatedClassName: 'animated', }); } /* Einfaches Accordion */ if ($('.accordion').length) { $('.accordion').accordion({ header: ".accordion-header", heightStyle: 'content', icons: false }); }; /* FAQ Accordion */ if ($('.faq-accordion').length) { $('.faq-accordion').accordion({ header: ".accordion-header", heightStyle: 'content', icons: false, active: false, collapsible: true }); }; /* make-font-size-great-again */ if (typeof(Cookies) !== 'undefined') { $('a[href="#make-font-size-great-again"]').click(function(e) { if ($('html').hasClass('font-size-is-great-again')) { $('html').removeClass('font-size-is-great-again'); Cookies.remove('fontSizeIsGreatAgain'); } else { $('html').addClass('font-size-is-great-again'); Cookies.set('fontSizeIsGreatAgain', 'true'); } e.preventDefault(); }); if (Cookies.get('fontSizeIsGreatAgain') !== undefined) { $('html').addClass('font-size-is-great-again'); } } /* print */ $('a[href="#print"]').click(function(e) { window.print(); }); });