-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02deedb
commit 883fb59
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
function gdpr() { | ||
if (!hasCookie()) { | ||
setCookie(); | ||
|
||
var banner = el("div", {class: "gdpr-banner"}, [ | ||
on(el("i", {class: "gdpr-close"}), "click", hide), | ||
el("p", {}, [ | ||
"Our site uses ", link("cookies", "https://www.thoughtworks.com/privacy-policy#cookie-section"), | ||
" for analytics. If you're unsure about it, take a look at our ", | ||
link("privacy policy", "https://www.thoughtworks.com/privacy-policy"), "." | ||
]) | ||
]); | ||
|
||
function hide() { | ||
setCookie(); | ||
document.body.removeChild(banner); | ||
} | ||
|
||
document.body.insertBefore(banner, document.body.firstChild); | ||
} | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", gdpr); | ||
|
||
/* ========== DOM helpers ========== */ | ||
|
||
function on(el, type, fn) { | ||
el.addEventListener(type, fn, false); | ||
return el; | ||
} | ||
|
||
function addContent(node, content) { | ||
if ("string" === typeof content) { | ||
content = document.createTextNode(content); | ||
} | ||
node.appendChild(content); | ||
} | ||
|
||
function el(tag, attrs, content) { | ||
const node = document.createElement(tag.toLowerCase()); | ||
|
||
if (attrs) { | ||
for (var key in attrs) { | ||
node.setAttribute(key, attrs[key]); | ||
} | ||
} | ||
|
||
if (content) { | ||
if (content.forEach) { | ||
content.forEach(function (child) { | ||
addContent(node, child); | ||
}); | ||
} else { | ||
addContent(node, content); | ||
} | ||
} | ||
|
||
return node; | ||
} | ||
|
||
function link(text, href) { | ||
return el("a", {href: href, target: "_blank", rel: "noopener noreferrer"}, text); | ||
} | ||
|
||
/* ========== Cookie Utils ========== */ | ||
|
||
function hasCookie() { | ||
return /_gdpr-accept=/.test(document.cookie); | ||
} | ||
|
||
function setCookie() { | ||
if (!hasCookie()) { | ||
document.cookie = "_gdpr-accept=yes; expires=Fri, 31 Dec 9999 23:59:59 GMT"; | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters