1
0
Fork 0
mirror of https://github.com/infinum/cookies_eu synced 2023-03-27 23:21:16 -04:00

Add async and defer support

This commit is contained in:
Gabrijel Škoro 2016-10-03 22:06:23 +02:00
parent d84d63663f
commit 7520dde55d

View file

@ -1,34 +1,50 @@
//= require js.cookie
'use strict';
document.addEventListener('DOMContentLoaded', function() {
var cookiesEu = {
init: function() {
var cookiesEuOKButton = document.querySelector('.js-cookies-eu-ok');
var cookiesEu = {
init: function() {
var cookiesEuOKButton = document.querySelector('.js-cookies-eu-ok');
if (cookiesEuOKButton) {
this.addListener(cookiesEuOKButton);
}
},
addListener: function(target) {
// Support for IE < 9
if (target.attachEvent) {
target.attachEvent('onclick', this.setCookie);
} else {
target.addEventListener('click', this.setCookie, false);
}
},
setCookie: function() {
Cookies.set('cookie_eu_consented', true, { path: '/', expires: 365 });
var container = document.querySelector('.js-cookies-eu');
container.parentNode.removeChild(container);
if (cookiesEuOKButton) {
this.addListener(cookiesEuOKButton);
}
},
addListener: function(target) {
// Support for IE < 9
if (target.attachEvent) {
target.attachEvent('onclick', this.setCookie);
} else {
target.addEventListener('click', this.setCookie, false);
}
},
setCookie: function() {
Cookies.set('cookie_eu_consented', true, { path: '/', expires: 365 });
var container = document.querySelector('.js-cookies-eu');
container.parentNode.removeChild(container);
}
};
(function() {
var isCalled = false;
function isReady() {
if (isCalled) return;
isCalled = true;
cookiesEu.init();
}
cookiesEu.init();
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', isReady, false);
}
});
// Old browsers IE < 9
if (window.addEventListener) {
window.addEventListener('load', isReady, false);
} else if (window.attachEvent) {
window.attachEvent('onload', isReady);
}
})();