function goBack(){if (document.referrer.indexOf(window.location.host) !== -1) {history.go(-1); return false;}}; function runAfterElementExists(jquery_selector,callback){var checker = window.setInterval(function() {if ($(jquery_selector).length) {clearInterval(checker);callback();}}, 200);} document.addEventListener('DOMContentLoaded', function() { if (document.referrer.indexOf(window.location.host) !== -1) {$('.goBackLink').removeClass('d-none');} function calculateNewPrice() { var currentPrice = 18.99; var NewQuantity = $(".qty-input").val().replace(/,/, "."); NewPrice = (currentPrice * NewQuantity).toFixed(2); NewPriceText = NewPrice.toString().replace(/\./g, ','); $(".price>span").html(NewPriceText+' €'); $(".articleQuantity").html("Preis gültig für "+ NewQuantity +" Artikel"); var oldUVP=18.99; var NewOldPrice = (oldUVP * NewQuantity).toFixed(2); NewOldPriceText = NewOldPrice.toString().replace(/\./g, ','); $(".priceRrp>span").html(NewOldPriceText+' €'); var percent=(NewOldPrice-NewPrice)/NewOldPrice*100; var percentRound = Math.round(percent); $(".savingPercentTarget").html("
-"+percentRound+"%
"); }; runAfterElementExists(".qty-btn-container", function() { $('.qty-btn-container button.qty-btn').click(function() {calculateNewPrice();}); $('.qty-box .qty-input').on('input propertychange paste', function() {calculateNewPrice();}); }); function calculatePercent() { if ($('.priceRrp>.Price').length > 0){ $(".savingPercentTarget").removeClass("hidden"); $('.priceRow .price').addClass("salePrice"); var oldUVP= $(".priceRrp .Price").text().replace(/,/, ".").replace(/€/, "").replace(/EUR/, ""); var currentPrice = $(".price.h1 span").text().replace(/,/, ".").replace(/EUR/, "").replace(/€/, ""); var percent=(oldUVP-currentPrice)/oldUVP*100; var percentRound = Math.round(percent); $(".savingPercentTarget").html("
-"+percentRound+"%
"); };}; setTimeout(function(){calculatePercent(); }, 300); runAfterElementExists(".variation-select select", function() { let sel = document.querySelectorAll('.variation-select select'); sel.forEach(function() {this.addEventListener ("change", function () { setTimeout(function(){ calculatePercent(); }, 750); $('.availabilityWrapper').removeClass("opacity_0"); }); }); if($("select.custom-select option:selected").text().indexOf('Bitte') >= 0) {$('.availabilityWrapper').addClass("opacity_0");};}); });