Skip to content

Commit

Permalink
Bugfix: Fix events on IE
Browse files Browse the repository at this point in the history
IE does not support "new CustomEvent()"
¯\_(ツ)_/¯
  • Loading branch information
Nikdro committed Oct 18, 2018
1 parent c2a23af commit cfef23b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Resources/Private/Templates/FusionObjects/Initialize.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,48 @@
<![CDATA[
var settings =]]>{settings -> f:format.raw()}<![CDATA[;

var enableEvent = document.createEvent("CustomEvent");
enableEvent.initCustomEvent('kd-cookieconsent', false, false, "enable-cookies");
var disableEvent = document.createEvent("CustomEvent");
disableEvent.initCustomEvent('kd-cookieconsent', false, false, "disable-cookies");

settings.onInitialise = function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type === 'opt-in') {
if (status === 'allow') {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "enable-cookies"}));
document.dispatchEvent(enableEvent);
} else {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "disable-cookies"}));
document.dispatchEvent(disableEvent);
}
}
if (type === 'opt-out' && !didConsent) {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "disable-cookies"}));
document.dispatchEvent(disableEvent);
}
};

settings.onStatusChange = function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type === 'opt-in') {
if (status === 'allow') {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "enable-cookies"}));
document.dispatchEvent(enableEvent);
} else {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "disable-cookies"}));
document.dispatchEvent(disableEvent);
}
}
if (type === 'opt-out' && !didConsent) {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "disable-cookies"}));
document.dispatchEvent(disableEvent);
}
};

settings.onRevokeChoice = function() {
var type = this.options.type;
if (type === 'opt-in') {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "disable-cookies"}));
document.dispatchEvent(disableEvent);
}
if (type === 'opt-out') {
document.dispatchEvent(new CustomEvent("kd-cookieconsent", {detail: "enable-cookies"}));
document.dispatchEvent(enableEvent);
}
};


window.addEventListener("load", function(){
window.cookieconsent.initialise(settings)});
]]>
Expand Down

0 comments on commit cfef23b

Please sign in to comment.