/**
* Created by mathieu on 07/03/17. */
(function(cookiebanner) {
// stop from running again, if accidently included more than once. if (cookiebanner.hasInitialised) return;
var util = { // only used for extending the initial options deepExtend: function(target, source) { for (var prop in source) { if (source.hasOwnProperty(prop)) { if (prop in target && this.isPlainObject(target[prop]) && this.isPlainObject(source[prop])) { this.deepExtend(target[prop], source[prop]); } else { target[prop] = source[prop]; } } } return target; },
replaceContent: function(str, callback) { var marker = /{{([a-z][a-z0-9\-_]*)}}/ig; return str.replace(marker, function(matches) { return callback(arguments[1]) || ; }) },
};
// valid cookie values cookiebanner.status = { deny: 'deny', allow: 'allow', dismiss: 'dismiss' };
cookiebanner.Banner = (function() {
var defaultOptions = {
enabled: true,
content: { message: 'Our protect is here.', link: 'BioDesigner|Dophin', button: 'click here', href: 'https://' },element: ' ', window: ' '
};
function Banner() { this.initialise.apply(this, arguments); }
Banner.prototype.initialise = function(options) {
// set options back to default options util.deepExtend(this.options = {}, defaultOptions);
var content = this.options.window.replace('Template:Children', getInnerMarkup.call(this));; this.element = appendMarkup.call(this, content);
this.autoOpen(); };
Banner.prototype.hasAnswered = function() { return Object.keys(cookiebanner.status).indexOf(this.getStatus()) >= 0; };
Banner.prototype.autoOpen = function(options) { !this.hasAnswered() && this.options.enabled && this.open(); };
Banner.prototype.open = function() { if (!this.element) return;
if(!this.isOpen()) { this.element.style.display = ; }
return this; };
Banner.prototype.close = function() { if(!this.element) return;
if(this.isOpen()) { this.element.style.display = 'none'; } return this; };
Banner.prototype.isOpen = function() { return this.element && this.element.style.display == ; };
function appendMarkup(markup) { var div = document.createElement('div'); div.innerHTML = markup;
var el = div.children[0];
el.style.display = 'none';
// save ref to the function handle so we can unbind it later this.onButtonClick = handleButtonClick.bind(this);
el.addEventListener('click', this.onButtonClick);
document.body.appendChild(el); return el; }
function handleButtonClick(event) { this.setStatus(cookiebanner.status.allow); this.close(); }
function getInnerMarkup() { var opts = this.options;
return util.replaceContent(opts.element, function(name) { var str = opts.content[name]; return (name && typeof str == 'string' && str.length) ? str : ; }); }
return Banner;
}());
cookiebanner.initialise = function() { new cookiebanner.Banner(); };
// prevent this code from being run twice cookiebanner.hasInitialised = true; window.cookiebanner = cookiebanner;
}(window.cookiebanner || {}));
window.addEventListener("load", function(){
window.cookiebanner.initialise();
});