|
|
@@ -1,8 +1,8 @@ |
|
|
import $ from 'jquery'; |
|
|
|
|
|
|
|
|
import $ from "jquery"; |
|
|
|
|
|
|
|
|
class IHKSocialBox { |
|
|
class IHKSocialBox { |
|
|
constructor(socialBox) { |
|
|
constructor(socialBox) { |
|
|
this.box = socialBox.addClass('initiated') |
|
|
|
|
|
|
|
|
this.box = socialBox.addClass("initiated"); |
|
|
|
|
|
|
|
|
this.checkHtmlFragmentCookiesAreSet(socialBox); |
|
|
this.checkHtmlFragmentCookiesAreSet(socialBox); |
|
|
this.checkIframe(); |
|
|
this.checkIframe(); |
|
|
@@ -10,22 +10,25 @@ class IHKSocialBox { |
|
|
|
|
|
|
|
|
checkIframe() { |
|
|
checkIframe() { |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
const iframe = this.box.find('iframe'); |
|
|
|
|
|
|
|
|
const iframe = this.box.find("iframe"); |
|
|
if (iframe.length) { |
|
|
if (iframe.length) { |
|
|
iframe.attr('tabindex', '-1'); |
|
|
|
|
|
|
|
|
iframe.attr("tabindex", "-1"); |
|
|
} else { |
|
|
} else { |
|
|
this.checkIframe(); |
|
|
this.checkIframe(); |
|
|
} |
|
|
} |
|
|
}, 1000) |
|
|
|
|
|
|
|
|
}, 1000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
checkHtmlFragmentCookiesAreSet(socialBox) { |
|
|
checkHtmlFragmentCookiesAreSet(socialBox) { |
|
|
|
|
|
if (socialBox.data("useconsent")) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
let socialMediaProtectionText = socialBox.data("socialmediaprotection"); |
|
|
let socialMediaProtectionText = socialBox.data("socialmediaprotection"); |
|
|
let socialMediaType = socialBox.data("socialmediatype"); |
|
|
let socialMediaType = socialBox.data("socialmediatype"); |
|
|
let cookieBot = socialBox.data("usecookiebot"); |
|
|
let cookieBot = socialBox.data("usecookiebot"); |
|
|
|
|
|
|
|
|
if(socialBox.find('iframe').length > 0) { |
|
|
|
|
|
let iframeElement = socialBox.find('iframe')[0]; |
|
|
|
|
|
|
|
|
if (socialBox.find("iframe").length > 0) { |
|
|
|
|
|
let iframeElement = socialBox.find("iframe")[0]; |
|
|
this.checkIframeCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, iframeElement, socialBox); |
|
|
this.checkIframeCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, iframeElement, socialBox); |
|
|
} else { |
|
|
} else { |
|
|
this.checkEmbedCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, socialBox); |
|
|
this.checkEmbedCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, socialBox); |
|
|
@@ -38,7 +41,12 @@ class IHKSocialBox { |
|
|
} |
|
|
} |
|
|
if (document.cookie.indexOf("social-media-consent-" + socialMediaType) === -1) { |
|
|
if (document.cookie.indexOf("social-media-consent-" + socialMediaType) === -1) { |
|
|
this.hideIframeElement(iframeElement); |
|
|
this.hideIframeElement(iframeElement); |
|
|
let textWithCheckbox = '<div class="social-media-protection-text-with-checkbox"> <input name="socialMediaType" type="checkbox" id=' + socialMediaType + '> <label id="textElement">' + socialMediaProtectionText + '</label> </div>'; |
|
|
|
|
|
|
|
|
let textWithCheckbox = |
|
|
|
|
|
'<div class="social-media-protection-text-with-checkbox"> <input name="socialMediaType" type="checkbox" id=' + |
|
|
|
|
|
socialMediaType + |
|
|
|
|
|
'> <label for="' + socialMediaType + '">' + |
|
|
|
|
|
socialMediaProtectionText + |
|
|
|
|
|
"</label> </div>"; |
|
|
|
|
|
|
|
|
$(socialBoxElement).append(textWithCheckbox); |
|
|
$(socialBoxElement).append(textWithCheckbox); |
|
|
|
|
|
|
|
|
@@ -48,14 +56,17 @@ class IHKSocialBox { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
checkEmbedCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, socialBoxElement) { |
|
|
checkEmbedCookieIsSet(socialMediaProtectionText, socialMediaType, cookieBot, socialBoxElement) { |
|
|
let scriptElements = socialBoxElement.find('script'); |
|
|
|
|
|
let imageElements = socialBoxElement.find('img'); |
|
|
|
|
|
|
|
|
let scriptElements = socialBoxElement.find("script"); |
|
|
|
|
|
let imageElements = socialBoxElement.find("img"); |
|
|
if (cookieBot) { |
|
|
if (cookieBot) { |
|
|
$(scriptElements).data("cookieconsent", "marketing"); |
|
|
$(scriptElements).data("cookieconsent", "marketing"); |
|
|
$(imageElements).data("cookieconsent", "marketing"); |
|
|
$(imageElements).data("cookieconsent", "marketing"); |
|
|
} |
|
|
} |
|
|
if (document.cookie.indexOf("social-media-consent-" + socialMediaType) === -1) { |
|
|
if (document.cookie.indexOf("social-media-consent-" + socialMediaType) === -1) { |
|
|
let textWithCheckbox = '<div class="social-media-protection-text-with-checkbox"> <input name="socialMediaType" type="checkbox"> <label id="textElement">' + socialMediaProtectionText + '</label> </div>'; |
|
|
|
|
|
|
|
|
let textWithCheckbox = |
|
|
|
|
|
'<div class="social-media-protection-text-with-checkbox"> <input name="socialMediaType" id="' + socialMediaType + '" type="checkbox"> <label for="' + socialMediaType + '">' + |
|
|
|
|
|
socialMediaProtectionText + |
|
|
|
|
|
"</label> </div>"; |
|
|
|
|
|
|
|
|
$(textWithCheckbox).appendTo(socialBoxElement); |
|
|
$(textWithCheckbox).appendTo(socialBoxElement); |
|
|
|
|
|
|
|
|
@@ -80,17 +91,17 @@ class IHKSocialBox { |
|
|
expirationDate.setDate(expirationDate.getDate() + expirationDays); |
|
|
expirationDate.setDate(expirationDate.getDate() + expirationDays); |
|
|
|
|
|
|
|
|
// Checkbox wurde angeklickt, Cookie setzen |
|
|
// Checkbox wurde angeklickt, Cookie setzen |
|
|
document.cookie = "social-media-consent-" + socialMediaType + "=true; expires=" + expirationDate.toUTCString() + ";"; |
|
|
|
|
|
|
|
|
document.cookie = |
|
|
|
|
|
"social-media-consent-" + socialMediaType + "=true; expires=" + expirationDate.toUTCString() + ";"; |
|
|
|
|
|
|
|
|
console.log("Cookie wurde gesetzt!"); |
|
|
|
|
|
// Finde alle Elemente mit dem selben socialMediaType |
|
|
// Finde alle Elemente mit dem selben socialMediaType |
|
|
let self = this; |
|
|
let self = this; |
|
|
$(`[data-socialmediatype=${socialMediaType}]`).each(function () { |
|
|
$(`[data-socialmediatype=${socialMediaType}]`).each(function () { |
|
|
let currentBox = $(this); |
|
|
let currentBox = $(this); |
|
|
currentBox.find(".social-media-protection-text-with-checkbox").hide(); |
|
|
currentBox.find(".social-media-protection-text-with-checkbox").hide(); |
|
|
let scriptElements = currentBox.find('script'); |
|
|
|
|
|
let imageElements = currentBox.find('img'); |
|
|
|
|
|
let iframeElements = currentBox.find('iframe'); |
|
|
|
|
|
|
|
|
let scriptElements = currentBox.find("script"); |
|
|
|
|
|
let imageElements = currentBox.find("img"); |
|
|
|
|
|
let iframeElements = currentBox.find("iframe"); |
|
|
|
|
|
|
|
|
self.showElements(scriptElements); |
|
|
self.showElements(scriptElements); |
|
|
self.showElements(imageElements); |
|
|
self.showElements(imageElements); |
|
|
@@ -108,16 +119,16 @@ class IHKSocialBox { |
|
|
|
|
|
|
|
|
showElement(htmlFragment) { |
|
|
showElement(htmlFragment) { |
|
|
let $element = $(htmlFragment); |
|
|
let $element = $(htmlFragment); |
|
|
let elementType = $element.prop('tagName').toLowerCase(); |
|
|
|
|
|
let dataSrc = $element.attr('data-src'); |
|
|
|
|
|
if (typeof dataSrc === 'undefined') { |
|
|
|
|
|
dataSrc = $element.attr('src'); |
|
|
|
|
|
|
|
|
let elementType = $element.prop("tagName").toLowerCase(); |
|
|
|
|
|
let dataSrc = $element.attr("data-src"); |
|
|
|
|
|
if (typeof dataSrc === "undefined") { |
|
|
|
|
|
dataSrc = $element.attr("src"); |
|
|
} |
|
|
} |
|
|
if (elementType === 'script') { |
|
|
|
|
|
$element.attr('src', dataSrc); |
|
|
|
|
|
|
|
|
if (elementType === "script") { |
|
|
|
|
|
$element.attr("src", dataSrc); |
|
|
$element.show(); |
|
|
$element.show(); |
|
|
} else if (elementType === 'img' || elementType === 'iframe') { |
|
|
|
|
|
$element.attr('src', dataSrc); |
|
|
|
|
|
|
|
|
} else if (elementType === "img" || elementType === "iframe") { |
|
|
|
|
|
$element.attr("src", dataSrc); |
|
|
$element.show(); |
|
|
$element.show(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@@ -125,8 +136,8 @@ class IHKSocialBox { |
|
|
|
|
|
|
|
|
export default IHKSocialBox; |
|
|
export default IHKSocialBox; |
|
|
|
|
|
|
|
|
$('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () { |
|
|
|
|
|
$('.social-box:not(.initiated)').each(function () { |
|
|
|
|
|
|
|
|
$("body").on("ihk-init dynamic-component-loaded gfi-dynamic-init", function () { |
|
|
|
|
|
$(".social-box:not(.initiated)").each(function () { |
|
|
new IHKSocialBox($(this)); |
|
|
new IHKSocialBox($(this)); |
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
}); |