Skip to content

Commit

Permalink
Add data protection banner to v1.1 #137
Browse files Browse the repository at this point in the history
  • Loading branch information
khawkins98 committed May 21, 2018
1 parent d40f700 commit 5e39de2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 111 deletions.
99 changes: 2 additions & 97 deletions js/cookiebanner.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,2 @@
/* Copyright (c) EMBL-EBI 2016; Authors: Peter Walter, Ken Hawkins */

(function cookieBanner() {
function setCookie(c_name, value, exdays) {
var exdate = new Date();
var c_value;
exdate.setDate(exdate.getDate() + exdays);
c_value = escape(value) + ((exdays===null) ? "" : ";expires=" + exdate.toUTCString()) + ";domain=.ebi.ac.uk;path=/";
document.cookie = c_name + "=" + c_value;
c_value = escape(value) + ((exdays===null) ? "" : ";expires=" + exdate.toUTCString()) + ";domain=" + document.domain + ";path=/";
document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
var i, x, y, ARRcookies=document.cookie.split(";");
for (i=0; i<ARRcookies.length; i++)
{
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x = x.replace(/^\s+|\s+$/g,"");
if (x===c_name) {
return unescape(y);
}
}
}

function createStyles() {
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');

style.type = 'text/css';
var css = "" +
" #cookie-banner {position:fixed;background-color:#111;width:100%;padding:.75rem;left:0;bottom:0;color:#eee;}" +
" #cookie-banner a {color:#fff;}" +
" .text {margin-right:2em;}";

if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}

head.appendChild(style);
}

function createBanner() {
var banner = document.createElement('div');
var wrapper = document.createElement('div');
var inner = document.createElement('div');

banner.id = "cookie-banner";
wrapper.className = "row";
wrapper.innerHTML = "" +
" <div class='text'>This website uses cookies. By continuing to browse this site, you are agreeing to the use of our site cookies. " +
" To find out more, see our <a href='//www.ebi.ac.uk/about/terms-of-use'>Terms of Use</a>.</div>" +
" <div id='cookie-dismiss'> <button class='close-button' style='top: 0.3rem; color:#fff;' aria-label='Close alert' type='button'><span aria-hidden='true'>&times;</span></button></div>" +
"";

document.body.appendChild(banner);
banner.appendChild(wrapper);
}

function openBanner() {
var height = document.getElementById('cookie-banner').offsetHeight;
document.getElementById('cookie-banner').style.display = 'block';
document.body.style.paddingBottom = height+'px';
}

function closeBanner() {
var height = document.getElementById('cookie-banner').offsetHeight;
document.getElementById('cookie-banner').style.display = 'none';
document.body.style.paddingBottom = '0';
}

function init() {
try {
if (getCookie('cookies-accepted') !== 'true') {
createStyles();
createBanner();
openBanner();

setCookie('cookies-accepted', 'true', 90); // show cookie message only once

document.getElementById('cookie-dismiss').onclick = function() {
closeBanner();
return false;
};
}
}
catch(err) {
setTimeout(init, 100);
}
}

init();

})();
// Disabled in favour of new dataprotection banner
// You can remove this JS file from your includes/sources
43 changes: 29 additions & 14 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
(function externalLinks() {
function isOwnDomain(url) {
return (url.indexOf('//') === -1 ||
url.indexOf('//www.ebi.ac.uk') !== -1 ||
url.indexOf('//wwwdev.ebi.ac.uk') !== -1 ||
url.indexOf('//www.ebi.ac.uk') !== -1 ||
url.indexOf('//wwwdev.ebi.ac.uk') !== -1 ||
url.indexOf('//srs.ebi.ac.uk') !== -1 ||
url.indexOf('//frontier.ebi.ac.uk') !== -1 ||
url.indexOf('//frontier.ebi.ac.uk') !== -1 ||
url.indexOf('//ftp.ebi.ac.uk') !== -1 ||
url.indexOf('//intranet.ebi.ac.uk') !== -1 ||
url.indexOf('//intranet.ebi.ac.uk') !== -1 ||
url.indexOf('//pdbe.org') !== -1 ||
url.indexOf('//' + document.domain) !== -1);
}
Expand Down Expand Up @@ -134,21 +134,21 @@
var searchError = searchBoxes[searchBox].errorText || 'Please enter a search term';
var searchAction = (searchForm) ? searchForm.action : '';
var isEbiSearch = searchAction.indexOf('/ebisearch/') !== -1;

if (searchForm && searchInput && isEbiSearch) {
// add reference to other items for onsubmit anonymous function
searchForm.searchInput = searchInput;
searchForm.searchInputDefault = searchInputDefault;
searchForm.searchError = searchError;

searchForm.onsubmit = function() {
searchInput = this.searchInput;
searchInputDefault = this.searchInputDefault;
searchError = this.searchError;

// Ensure input is trimmed
searchInput.value = searchInput.value.trim();

if (searchInput.value === searchInputDefault || searchInput.value === '') {
alert(searchError);
return false;
Expand All @@ -161,15 +161,15 @@
}
catch (err) {}
})();

// Remove global-nav/global-nav-expanded from header/footer
// if body.no-global-nav is set
(function hideGlobalNav() {
try {
var hasGlobalMasthead = document.getElementById('global-masthead') !== null;
var disabled = document.body.className.indexOf('no-global-nav') !== -1;
var elem;

if (hasGlobalMasthead && disabled) {
if ((elem=document.getElementById('global-nav')) !== null) {
elem.parentNode.removeChild(elem);
Expand All @@ -181,7 +181,7 @@
}
catch (err) {}
})();

// Tap the location bar to scroll to the top
// Disabled for v1.1 per https://github.com/ebiwd/EBI-Framework/issues/23
// (function scrollMeUp() {
Expand All @@ -190,7 +190,7 @@
// if (e.target.nodeName == 'A')
// return;
// // if jQuery then do it all pretty like
// if (window.jQuery) {
// if (window.jQuery) {
// $('html,body').animate({
// scrollTop: 0
// }, 700);
Expand All @@ -211,10 +211,25 @@
localMasthead.style.backgroundColor = localMastheadColor.getAttribute("content");
localMasthead.className += ' meta-background-color';
}
if (localMastheadImage != null) {
localMasthead.style.backgroundImage = 'url(' + localMastheadImage.getAttribute("content") + ')';
if (localMastheadImage != null) {
localMasthead.style.backgroundImage = 'url(' + localMastheadImage.getAttribute("content") + ')';
localMasthead.className += ' meta-background-image';
}
})();

})();


// Use the v1.3 data protection banner on older sites
function legacyDataProtectionBanner() {
var localFrameworkVersion = '1.1'; // 1.1 or 1.2 or compliance or other
// if you select compliance or other we will add some helpful
// CSS styling, but you may need to add some CSS yourself
var newDataProtectionNotificationBanner = document.createElement('script');
newDataProtectionNotificationBanner.src = 'https://dev.ebi.emblstatic.net/web_guidelines/EBI-Framework/v1.3/js/ebi-global-includes/script/5_ebiFrameworkNotificationBanner.js?legacyRequest='+localFrameworkVersion;
document.head.appendChild(newDataProtectionNotificationBanner);
newDataProtectionNotificationBanner.onload = function() {
ebiFrameworkRunDataProtectionBanner(); // invoke the banner
};
}
legacyDataProtectionBanner();

0 comments on commit 5e39de2

Please sign in to comment.