/** * Language */ var Language = { en: { trackingCookies: { request: "This website uses cookies for statistical-purposes. Do you agree?", moreInformation: "More about the cookie law.", allow: "Yes", deny: "No" } }, nl: { trackingCookies: { request: "Deze website maakt gebruik van cookies voor statistiek-doeleinden. Gaat u hiermee akkoord?", moreInformation: "Meer over de cookiewet", allow: "Ja", deny: "Nee" } } }; /** * Cookie checker * Checks if the user allows tracking cookies by asking it using an information bar. * Usage: * var cc = new CookieCheck({ infoPage: 'http://www.example.com/about-cookies' }); * To know when a user accepts or denies these cookies you can add a callback: * cc.addCallback(Function myFunction[, boolean allwaysCall]); * The callback function receives one argument: * - true when the user accepts it * - false when the user denies it * - null when we don't know yet (only in combination with the allwaysCall boolean) * If you also want to know if we don't know yet if the user allows it you can pass a boolean true * to the addCallback method else the callback function is only called when the user actually clicks * the bar (accepts or denies) or when the user already had accepted or denied. */ var CookieCheck = Class.create({ cookieName: 'allow-tracking-cookies', cookieValue: null, checkValue: null, callbacks: [], options: { infoPage: null // page to link to for more information }, initialize: function (options) { if (typeof options === 'object') { Object.extend(this.options, options); } this.cookieValue = Cookie.get(this.cookieName); if (!(!!~['true','false'].indexOf(this.cookieValue))) { document.observe('dom:loaded', function() { cc.ask(); }); } else { this.checkValue = this.cookieValue === 'true' ? true : false; } }, // adds a callback function addCallback: function (callback, allwaysCall) { if (typeof callback === 'function') { if (allwaysCall || this.checkValue !== null) { callback(this.checkValue); } this.callbacks.push(callback); } else { throw "CookieCheck::addCallback(): callback is not a function"; } }, // sets the new value, saves it and calls callbacks setValue: function (value) { var sValue, bValue; if (typeof value === 'boolean') { bValue = value; sValue = value ? 'true' : 'false'; } else { if (value === 'true') { bValue = true; sValue = value; } else { bValue = false; sValue = 'false'; } } this.checkValue = bValue; Cookie.set(this.cookieName, sValue); $A(this.callbacks).each(function (cb) { cb(bValue); }); }, // creates an information bar with clickable links ask: function () { var barClick = function (event, value) { event.stop(); var el = Event.element(event); this.setValue(value); bar.select('a').invoke('stopObserving'); bar.remove(); $('centerbox').removeClassName('cookiebarmargin'); if (value === 'false') { window.open(el.href); } }, bar = new Element('div', { 'class': 'information-bar', id: 'tracking-cookies' }), request, links; bar.addClassName('information-bar'); request = new Element('p', { 'class': 'text' }).update(Language.trackingCookies.request); if (this.options.infoPage) { request.insert(' ').insert( new Element('a', { href: this.options.infoPage }).update(Language.trackingCookies.moreInformation) ); } bar.insert(request); links = new Element('ul', { 'class': 'links' }).insert( new Element('li').update( new Element('a', { 'class': 'allow', href: '#allow' }) .update(Language.trackingCookies.allow) .observe('click', barClick.bindAsEventListener(this, 'true')) ) ).insert( new Element('li').update( new Element('a', { 'class': 'extern external', href: 'http://sitestat.com/privacy/cookie-opt-out.php?lang=nl_NL'}) .update(Language.trackingCookies.deny) .observe('click', barClick.bindAsEventListener(this, 'false')) ) ); links.addClassName('links'); bar.insert(links); if($('pagename')){ $('pagename').insert({ after: bar }); } else { $('centerbox').insert({ before: bar }); } $('centerbox').addClassName('cookiebarmargin'); } }); /** * Static Cookie functions */ var Cookie = { // default values days: 365 * 30, path: '/', // set a cookie, returns its value set: function setCookie(name, value, days, path) { days = days ? days : Cookie.days; path = path ? path : Cookie.path; if(typeof name != 'undefined' && typeof value != 'undefined') { document.cookie = name+'='+value+'; expires='+ Cookie.getTimeFromDays(days)+'; path='+path; return value; } return null; }, // get the value of a cookie get: function getCookie(name) { if(( result = $A(document.cookie.split('; ')).find(function(cookie) { return cookie.startsWith(name); }) )) { return result.replace(result.split('=').first()+'=', ''); } return null; }, // unset/remove a cookie unset: function unsetCookie(name) { Cookie.set(name,'', -1); }, // get correctly formatted timestamp relative to now with the specified days: getTimeFromDays: function getTimeFromDays(days) { var date = new Date(); date.setTime(date.getTime()+(60*60*24*days*1000)); return date.toGMTString(); } }; try { var lang = 'en'; Language = lang ? (Language[lang] || Language.en) : Language.en; var cc = new CookieCheck({ infoPage: typeof cookiePolicyPage != 'undefined' ? cookiePolicyPage : null }) } catch(e) { console.dir(e); } document.observe('dom:loaded', function() { // Doorklik links voorzien van anoniem attribuut if(cc.checkValue === null) { // either we don't know (null); $$('a[href^="http://nl.sitestat.com/rivm/rivm-nl/"]').each(function(a) { a.href = a.href + "&ns_nc=1"; }); } // Statistics cc.addCallback(function (trackingCookiesAllowed) { if (trackingCookiesAllowed !== false) { // either we don't know (null) or it's allowed var script = document.createElement("script"); script.type = "text/javascript"; script.async = true; script.src = '/js/sitestat.js?_v=-1344436226'; document.getElementsByTagName("body")[0].appendChild(script); } }, true); });