Skip to content

Commit

Permalink
Release 1.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ToX82 committed Mar 13, 2016
1 parent 74ae998 commit 969a682
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 51 deletions.
3 changes: 3 additions & 0 deletions cookiebar-grey.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
#cookie-bar-tracking {
display: none;
}
#cookie-bar-scrolling {
display: none;
}
#cookie-bar-privacy-page {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion cookiebar-grey.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 57 additions & 37 deletions cookiebar-latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function setupCookieBar() {
var cookiesListDiv;
var detailsLinkText;
var detailsLinkUrl;
var startup = false;
var shutup = false;

/**
* If cookies are disallowed, delete all the cookies at every refresh
Expand All @@ -87,60 +89,59 @@ function setupCookieBar() {
* @param null
* @return null
*/
var checkEurope = new XMLHttpRequest();

// If the user is in EU, then STARTUP
var checkEurope = new XMLHttpRequest();
checkEurope.open('GET', '//freegeoip.net/json/', true);
checkEurope.onreadystatechange = function() {
if (checkEurope.readyState === 4 && checkEurope.status === 200) {
clearTimeout(xmlHttpTimeout);
var country = JSON.parse(checkEurope.responseText).country_code;
if (cookieLawStates.indexOf(country) > -1) {
if (getURLParameter('always')) {
var accepted = getCookie();
if (accepted === undefined) {
startup();
}
} else {
if (document.cookie.length > 0 || window.localStorage.length > 0) {
var accepted = getCookie();
if (accepted === undefined) {
startup();
}
}
}
startup = true;
} else {
console.log('cookieBAR - Not an EU user, no cookieBAR.');
shutup = true;
}
}
}

checkEurope.send();
};

/*
* Using an external service for geoip localization could be a long task
* If it takes more than 1.5 second, start normally
* @param null
* @return null
*/
var xmlHttpTimeout = setTimeout(ajaxTimeout, 1500);
function ajaxTimeout() {
checkEurope.abort();
console.log('cookieBAR - Timeout for ip geolocation');
checkEurope.abort();
startup = true;
}
checkEurope.send();

if (document.cookie.length > 0 || window.localStorage.length > 0) {
var accepted = getCookie();
if (accepted === undefined) {
startup();
}
// If at least a cookie or localstorage is set, then STARTUP
if (document.cookie.length > 0 || window.localStorage.length > 0) {
var accepted = getCookie();
if (accepted === undefined) {
startup = true;
} else {
shutup = true;
}
}

// If cookieBAR should always be show, then STARTUP
if (getURLParameter('always')) {
startup = true;
}

if (startup === true && shutup === false) {
startCookieBar();
}


/**
* Load external files (css, language files etc.)
* @return null
*/
function startup() {
function startCookieBar() {
var userLang = detectLang();

// Load CSS file
Expand All @@ -149,9 +150,10 @@ function setupCookieBar() {
theme = '-' + getURLParameter('theme');
}
var path = scriptPath.replace(/[^\/]*$/, '');
var minified = (scriptPath.indexOf('.min') > -1) ? '.min' : '';
var stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('href', path + 'cookiebar' + theme + '.css');
stylesheet.setAttribute('href', path + 'cookiebar' + theme + minified + '.css');
document.head.appendChild(stylesheet);

// Load the correct language messages file and set some variables
Expand All @@ -176,6 +178,7 @@ function setupCookieBar() {
thirdparty = document.getElementById('cookie-bar-thirdparty');
tracking = document.getElementById('cookie-bar-tracking');

scrolling = document.getElementById('cookie-bar-scrolling');
privacyPage = document.getElementById('cookie-bar-privacy-page');
privacyLink = document.getElementById('cookie-bar-privacy-link');

Expand All @@ -197,6 +200,10 @@ function setupCookieBar() {
tracking.style.display = 'block';
}

if (getURLParameter('scrolling')) {
scrolling.style.display = 'inline-block';
}

if (getURLParameter('top')) {
cookieBar.style.top = 0;
setBodyMargin('top');
Expand Down Expand Up @@ -226,9 +233,9 @@ function setupCookieBar() {
function getScriptPath() {
var scripts = document.getElementsByTagName('script');

for (var i = 0; i < scripts.length; i++) {
for (i = 0; i < scripts.length; i += 1) {
if (scripts[i].hasAttribute('src')) {
var path = scripts[i].src;
path = scripts[i].src;
if (path.indexOf('cookiebar') > -1) {
return path;
}
Expand Down Expand Up @@ -260,7 +267,7 @@ function setupCookieBar() {
function listCookies(cookiesListDiv) {
var cookies = [];
var i, x, y, ARRcookies = document.cookie.split(';');
for (i = 0; i < ARRcookies.length; i++) {
for (i = 0; i < ARRcookies.length; i += 1) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf('='));
y = ARRcookies[i].substr(ARRcookies[i].indexOf('=') + 1);
x = x.replace(/^\s+|\s+$/g, '');
Expand Down Expand Up @@ -307,12 +314,9 @@ function setupCookieBar() {
*/
function removeCookies() {
// Clear cookies
document.cookie.split(';')
.forEach(function(c) {
document.cookie = c.replace(/^ +/, '')
.replace(/=.*/, '=;expires=' + new Date()
.toUTCString() + ';path=/');
});
document.cookie.split(';').forEach(function(c) {
document.cookie = c.replace(/^\ +/, '').replace(/\=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
});

// Clear localStorage
localStorage.clear();
Expand Down Expand Up @@ -434,6 +438,22 @@ function setupCookieBar() {
promptClose.addEventListener('click', function() {
fadeOut(prompt, 250);
});

if (getURLParameter('scrolling')) {
var scrollPos = document.body.getBoundingClientRect().top;
var scrolled = false;
window.addEventListener('scroll', function() {
if (scrolled === false) {
if (document.body.getBoundingClientRect().top - scrollPos > 250 || document.body.getBoundingClientRect().top - scrollPos < -250) {
setCookie('cookiebar', 'CookieAllowed');
clearBodyMargin();
fadeOut(prompt, 250);
fadeOut(cookieBar, 250);
scrolled = true;
}
}
});
}
}
}

Expand Down
Loading

0 comments on commit 969a682

Please sign in to comment.