(function (ttcc){
var reg_match = /\d+$/;
var dbdata;
if (ttcc.hasInitialised) return;
// Initialisieren
ttcc.initialise = function (data) {
data = atob(data);
dbdata = JSON.parse(data);
ttcc.fbload();
// ttcc.ytload();
ttcc.read_cookie('truetravel_ttconsent');
ttcc.Popup();
// Event Listener - Alle Checkboxen
$('#cm-selectAllCheckboxes').on('click', function () {
ttcc.selectAllCheckboxes();
});
// Event Listener - Personalisierung
$('#ck_3').change(function () {
ttcc.selectSpecific(3);
});
// Event Listener - Komfort
/*$('#ck_3').change(function () {
ttcc.selectSpecific(3);
});*/
// Event Listener - Statistik
$('#ck_2').change(function () {
ttcc.selectSpecific(2);
});
// Auswahl bestätigen - Cookie schreiben mit ausgewählten Checkboxes als json 64 Bit decoded
$('#cm-selectSpecific').on('click', function () {
var checkboxes = $('.cmCat-checkboxes');
checkedBoxes = {};
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
var j = i+1;
checkedBoxes[i] = $('#ck_'+j).attr('name');
}
}
var expire = new Date();
console.log('Expire before: '+expire.toUTCString());
if($('.cmCat-checkboxes:checked').length < 3)
{
expire.setTime(expire.getTime() + (60*60*1000));
}
else
{
expire.setDate(expire.getDate() + 36500);
}
console.log('Expire after: '+expire.toUTCString());
if($('.cmCat-checkboxes:checked').length == 1) {
document.cookie = 'RA-Cookies=true;expires=0;path=/;domain='+location.hostname.replace('www.', '');
}
else {
document.cookie = 'RA-Cookies=false;expires=0;path=/;domain='+location.hostname.replace('www.', '');
}
document.cookie = 'truetravel_ttconsent='+btoa(JSON.stringify(checkedBoxes))+';expires='+expire.toUTCString()+';path=/;samesite=none;secure;domain='+location.hostname.replace('www.', '');
ttcc.read_cookie('truetravel_ttconsent');
setTimeout(function () {
location.reload();
},500);
});
};
ttcc.Popup = function () {
ttcc.changeToggleText();
};
// Details anzeigen - Change Text
ttcc.changeToggleText = function () {
if($('#cm-descToggle').hasClass('collapsed')) {
$('#cm-descToggle').html('Details anzeigen');
$('#cm-descToggle').attr('aria-expanded', 'false');
}
else {
$('#cm-descToggle').html('Details ausblenden');
$('#cm-descToggle').attr('aria-expanded', 'true');
}
$('#cm-descToggle').click(function () {
ttcc.consentDescToggle();
});
}
// Details anzeigen - open / close Details
ttcc.consentDescToggle = function () {
if($('#cm-descToggle').hasClass('collapsed')) {
$('#cm-descToggle').html('Details ausblenden');
$('#cm-descToggle').attr('aria-expanded', 'false');
}
else {
$('#cm-descToggle').html('Details anzeigen');
$('#cm-descToggle').attr('aria-expanded', 'true');
}
$('#cm-consentDesc').toggleClass('collapsed');
$('#cm-descToggleIcon').toggleClass('collapsed');
$('#cm-descToggle').toggleClass('collapsed');
}
// Alle Checkboxen auswählen
ttcc.selectAllCheckboxes = function () {
var checkboxes = $('.cmCat-checkboxes');
var recallthis = false;
for (var i = 0; i < checkboxes.length; i++) {
if (!checkboxes[i].checked) {
recallthis = true;
ttcc.setCheckbox(i, checkboxes);
break;
}
}
if (recallthis) {
setTimeout(function () {
ttcc.selectAllCheckboxes();
}, 100);
} else {
setTimeout(function () {
try {
ttcc.closeConsentDialog(checkboxes, 'all');
} catch (error) {
console.log(error);
}
}, 200);
}
}
// Alles auswählen
ttcc.closeConsentDialog = function (checkboxArray, clickedButton) {
var cats = {};
for (var i = 0; i < checkboxArray.length; i++) {
var obj = checkboxArray[i];
cats[obj.id.match(reg_match)[0]] = obj.checked ? 1 : 0;
}
cats[1] = 1;
var checkboxes = $('.cmCat-checkboxes');
checkedBoxes = {};
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
var j = i+1;
checkedBoxes[i] = $('#ck_'+j).attr('name');
}
}
var expire = new Date();
//expire.setDate(expire.getDate() + 365);
if($('.cmCat-checkboxes:checked').length < 3)
{
expire.setTime(expire.getTime() + (60*60*1000));
}
else
{
expire.setDate(expire.getDate() + 36500);
}
document.cookie = 'truetravel_ttconsent='+btoa(JSON.stringify(checkedBoxes))+';expires='+expire.toUTCString()+';path=/;samesite=none;secure;domain='+location.hostname.replace('www.', '');
ttcc.read_cookie('truetravel_ttconsent');
setTimeout(function () {
location.reload();
},500);
}
// Hinweis für Personalisierung
ttcc.selectSpecific = function(categoryNum) {
$("#cm-notification").css("display", "none");
var checkboxes = $('.cmCat-checkboxes');
if (dbdata.config.cookieBoxAcceptStaticCookies === true && dbdata.config.cookieBoxAcceptKomfortCookies === true && dbdata.config.cookieBoxAcceptPersonalCookies === true) {
if (categoryNum == 4) {
for (var i = 0; i < categoryNum - 1; i++) {
$("#cm-notification").css("display", "block");
ttcc.setCheckbox(i, checkboxes);
}
$(".checkmark_ck_4").focus();
}
if (categoryNum == 3 && checkboxes[3].checked === true) {
ttcc.unsetCheckbox(3, checkboxes);
$("#cm-notification").css("display", "none");
} else if (categoryNum == 2 && checkboxes[2].checked === true) {
ttcc.unsetCheckbox(2, checkboxes);
ttcc.unsetCheckbox(2, checkboxes);
$("#cm-notification").css("display", "none");
}
if (checkboxes[categoryNum - 1].checked === false) {
$("#cm-notification").css("display", "none");
}
}
else if (dbdata.config.cookieBoxAcceptStaticCookies === false && dbdata.config.cookieBoxAcceptKomfortCookies === true && dbdata.config.cookieBoxAcceptPersonalCookies === true) {
if (categoryNum == 4) {
if (checkboxes[2].checked === true) {
$("#cm-notification").html("Zur Aktivierung dieser Kategorie wird auch die Kategorie Komfort aktiviert.");
$("#cm-notification").css("display", "block");
ttcc.setCheckbox(1, checkboxes);
}
$(".checkmark_ck_4").focus();
}
}
else if (dbdata.config.cookieBoxAcceptStaticCookies === true && dbdata.config.cookieBoxAcceptKomfortCookies === false && dbdata.config.cookieBoxAcceptPersonalCookies === true) {
if (categoryNum == 4) {
if (checkboxes[2].checked === true) {
$("#cm-notification").html("Zur Aktivierung dieser Kategorie wird auch die Kategorie Statistik aktiviert.");
$("#cm-notification").css("display", "block");
ttcc.setCheckbox(1, checkboxes);
}
$(".checkmark_ck_4").focus();
}
}
}
// Checkboxen setzen
ttcc.setCheckbox = function (i, checkboxArray) {
checkboxArray[i].checked = true;
var checkmark = $('#checkmark_' + checkboxArray[i].getAttribute('id'));
checkmark.attr('aria-checked', 'true');
// location.reload();
}
// Checkboxen unsetten
ttcc.unsetCheckbox = function (i, checkboxArray) {
checkboxArray[i].checked = false;
var checkmark = $('#checkmark_' + checkboxArray[i].getAttribute('id'));
checkmark.attr('aria-checked', 'false');
}
// Cookies lesen und Modal anzeigen wenn Cookie nicht vorhanden ist
ttcc.read_cookie = function (cookie) {
var my_cookie_eq = cookie + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) ==' ') {
c = c.substring(1,c.length);
}
if (c.indexOf(my_cookie_eq) == 0) {
cookie_content = JSON.parse(atob(c.replace(cookie + '=', '')));
var statistic = false;
if (cookie_content[1] == 'statistics') {
statistic = true;
}
/*
var comfort = false;
if (cookie_content[2] == 'comfort') {
comfort = true;
setCheckbox(2, checkboxes);
}
*/
var marketing = false;
if (cookie_content[2] == 'marketing') {
marketing = true;
// setCheckbox(2, checkboxes);
}
$('#cookie-consent').hide();
/*
$('#cookie-consent').html('');
*/
$('html').css('overflow', '');
return c.substring(my_cookie_eq.length,c.length);
}
else {
$('#cookie-consent').show();
//$('html').css('overflow', 'hidden');
}
}
return null
}
// Cookie setzen
ttcc.setCookie = function(cookie, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = ""
document.cookie = cookie+"="+value+expires+"; path=/;samesite=none;secure;domain="+location.hostname.replace('www.', '');
// Wenn Statistische Cookies erlaubt werden Seite einmal neu laden
var csettings = JSON.parse(atob(value));
$.each(csettings, function (i, v) {
if (v == 'statistics') {
// location.reload();
}
});
}
// Lade Facebook / Instagram-Inhalt
ttcc.fbload = function () {
$(".CookieConsent").on('click', '.tt-btn', function (e) {
e.preventDefault();
var facebook = $(this).closest('.CookieConsent').find('.tt-hide script').html();
facebook = atob(facebook);
console.log(facebook);
$(this).closest('.CookieConsent').html(facebook);
});
}
// Lade Youtube / Vimeo-Inhalt
ttcc.ytload = function () {
$(".CookieConsent").on('click', '.video-wall button', function (e) {
e.preventDefault();
var facebook = $(this).closest('.CookieConsent').find('.tt-hide script').html();
facebook = atob(facebook);
console.log(facebook);
$(this).closest('.CookieConsent').html(facebook);
});
}
window.truetravelCookieConsent = ttcc;
}(window.truetravelCookieConsent || {})
);