var dsAllCookies = {};var dsLinks = {};var dsShowSettings = ;var dsSettingsOpen = false; var dsPopupDirectlyOpen = false; var dsBodyStyleBefore = ""; $(document).ready(function() { $("head").append(""); var cookie = localStorage.getItem("ds-cookie"); if(cookie == undefined){ dsOpenCookie(); }else{ dsExecScript(); } }); function dsOpenCookie(fromSettingIcon) { if(fromSettingIcon == undefined) { fromSettingIcon = false; } var hide = false; $.each(dsLinks, function(k, v) { if(location.href.indexOf(v) >= 0) { hide = true; } }); if(!hide || fromSettingIcon) { $("body").append("
"); dsBodyStyleBefore = $("body").attr("style"); $("body").css({ height: "100vh", overflow: "hidden" }); $(".ds-cookiebanner-blocker").removeClass("dsHide"); dsMoreLess(); if($(".ds-cookiebanner > div > div.ds-cookiebanner-title select, .ds-cookiepopup > div > div.ds-cookiebanner-title select").length > 0) { $(".ds-cookiebanner > div > div.ds-cookiebanner-title select, .ds-cookiepopup > div > div.ds-cookiebanner-title select").on("change", function() { location.href = "/"+$(this).val()+"/"; }); } $(".ds-cookiebanner-accept, .ds-cookiebanner-only-functional").click(function() { var data = "save_all=on"; if($(this).hasClass("ds-cookiebanner-only-functional")) { data = "save_functional=on"; } $.ajax({ type: 'POST', data: data, url: "https://consent.dimaster.ch/async/customer/saveCookie?customer=&lang=" }) .done(function(data) { var cookieData = JSON.parse(data); localStorage.setItem("ds-cookie", JSON.stringify(cookieData)); dsExecScript(); }); }); } } function dsExecScript() { if($(".ds-cookiebanner-blocker").length > 0) { $(".ds-cookiebanner-blocker").addClass("dsHide"); if(dsBodyStyleBefore == undefined) { dsBodyStyleBefore = ""; } $("body").attr("style",dsBodyStyleBefore); setTimeout(function() { $(".ds-cookiebanner-blocker").remove(); }, 1000); } var cookie = JSON.parse(localStorage.getItem("ds-cookie")); dsAppendSettings(); $.each(cookie, function(k, v) { if(v.type == "all" || v.type == "functional") { $.each(dsAllCookies, function(key, val) { if(val.readonly == 1 || (v.type != "functional" && val.readonly == 0)) { if(val.execute == 1) { $("head").append(val.script); } else { eval(val.script); } } }); } else { if(dsAllCookies[v.type].execute == 1) { $("head").append(dsAllCookies[v.type].script); } else { eval(dsAllCookies[v.type].script); } } }); } function dsAppendSettings() { if(dsShowSettings == "1" && $("body #dsSettings").length <= 0) { $("body").append("
"); } } function dsOpenPopupDirect(url, hideBanner) { dsPopupDirectlyOpen = true; $("body").append("
"); dsBodyStyleBefore = $("body").attr("style"); $("body").css({ height: "100vh", overflow: "hidden" }); dsOpenPopup(url,false).then(() => { $(".ds-cookiebanner-blocker").removeClass("dsHide"); }); } function dsOpenSettings() { //$("body").append("
"); dsOpenPopup("/async/customer/getContent?customer=&lang=&type=settings",false) .then(function() { //$(".ds-cookiebanner-blocker").removeClass("dsHide"); var cookie = JSON.parse(localStorage.getItem("ds-cookie")); var i = 0; $.each(cookie, function(k, v) { if(v.type == "all") { $.each(dsAllCookies, function(key, val) { $("#cookieBannerSettingsForm input[name='allow_"+key+"']").prop("checked", true); }); } else { var tmp = $("#cookieBannerSettingsForm input[name='allow_"+v.type+"']"); tmp.addClass("tmp"+i); if (!tmp.is(":checked")) { tmp.prop("checked", true); } } checkCatSettingsCheckbox(); i++; }); //dsSettingsOpen = true; }); } function dsMoreLess() { if($(".cookiebanner-more").length > 0) { $(".cookiebanner-more > span").click(function() { $(".cookiebanner-less").removeClass("hide"); $(".cookiebanner-more").addClass("hide"); }); $(".cookiebanner-less > span").click(function() { $(".cookiebanner-less").addClass("hide"); $(".cookiebanner-more").removeClass("hide"); }); } } function dsOpenPopup(url, hideBanner){ return new Promise((resolve) => { if(hideBanner){ $(".ds-cookiebanner").remove(); } if(url.substring(0,1) == "/"){ url = url.substring(1, url.length); } $.ajax({ url: "https://consent.dimaster.ch/"+url }) .done(function(data) { if($(".ds-cookiebanner-blocker .ds-cookiepopup").length <= 0) { $(".ds-cookiebanner-blocker > div").append("
"+data+"
"); $(".ds-cookiepopup > .cookieBanner-closePopup").click(function() { if(dsSettingsOpen || dsPopupDirectlyOpen) { if(dsPopupDirectlyOpen) { dsPopupDirectlyOpen = false; if(dsBodyStyleBefore == undefined) { dsBodyStyleBefore = ""; } $("body").attr("style",dsBodyStyleBefore); } $(".ds-cookiebanner-blocker").addClass("dsHide"); setTimeout(function() { $(".ds-cookiebanner-blocker").remove(); }, 1000); } else { $(".ds-cookiepopup").remove(); $(".ds-cookiebanner").removeClass("hide"); } }); } else { $(".ds-cookiebanner-blocker .ds-cookiepopup > div").html(data); } $(".ds-cookiebanner-blocker .ds-cookiebanner").addClass("hide"); resolve(); }) .fail(function() { console.log("error"); }); }); } function initCheckboxSettings() { $("#cookieBannerSettingsForm form").on("submit", function() { $.ajax({ type: 'POST', data: $("#cookieBannerSettingsForm form").serialize()+"&"+$(this).find("input[type=submit]:focus").attr("name")+"=on", url: "https://consent.dimaster.ch/async/customer/saveCookie?customer=&lang=" }) .done(function(data) { var cookieData = JSON.parse(data); localStorage.setItem("ds-cookie", JSON.stringify(cookieData)); if(dsSettingsOpen) { location.reload(); } else { dsExecScript(); } }); return false; }); setTimeout(function() { $("#cookieBannerSettingsForm form input").each(function() { if($(this).attr("readonly") == undefined && $(this).attr("name").indexOf("allow") >= 0 && $(this).is(":checked")) { var parent = $(this).parent().parent().parent().parent(); console.log(parent) parent.children(".cookiebanner-arrow").addClass("cookiebanner-arrowopen"); parent.children(".cookiebanner-settingsSubcontent").addClass("cookiebanner-open"); } }); },50); $("#cookieBannerSettingsForm form input").on("change", function() { if($(this).attr("name") == "all") { if($(this).is(":checked")) { $("#cookieBannerSettingsForm form input[type='checkbox']:not(:disabled)").prop("checked",true); } else { $("#cookieBannerSettingsForm form input[type='checkbox']:not(:disabled)").prop("checked",false); } } else if($(this).attr("name").indexOf("cat_") >= 0) { var id = $(this).attr("name").replace("cat_",""); if($(this).is(":checked")) { $("#cookieBannerSettingsForm form input[category="+id+"]:not(:disabled)").prop("checked",true) } else { $("#cookieBannerSettingsForm form input[category="+id+"]:not(:disabled)").prop("checked",false) } } checkCatSettingsCheckbox(); }); $("#cookieBannerSettingsForm *[readonly]").click(function(e) { e.preventDefault(); }); $(".cookiebanner-arrow").click(function(){ $(this).toggleClass("cookiebanner-arrowopen"); $(this).parent().children(".cookiebanner-settingsSubcontent").toggleClass("cookiebanner-open"); }); $("#cookieBannerSettingsForm .cookiebanner-settingsSubcontent").each(function() { $(this).css("height", $(this).children().height()+"px"); }); } function checkCatSettingsCheckbox() { var overallChecked = true; $("#cookieBannerSettingsForm form .cookiebanner-catCheckbox").each(function() { var catChecked = true; var catObj = $(this); $(this).parent().parent().find("input:not(.cookiebanner-catCheckbox)").each(function() { if(!$(this).is(":checked")) { catChecked = false; overallChecked = false; } }); if(catChecked) { catObj.prop("checked", true); } else { catObj.prop("checked", false); } }); if(overallChecked) { $("#cookieBannerSettingsForm form input[name='all']:not(:disabled)").prop("checked", true) } else { $("#cookieBannerSettingsForm form input[name='all']:not(:disabled)").prop("checked", false) } }