/** * EXAMPLE 1: * * * ... * * * EXAMPLE 2: * * * ... * * *
*
* */ (function (fn) { "use strict"; // set or get cookie var cookie = function (name, value, days, path, domain, secure) { if (value === undefined) { var i, x, y, cookies = document.cookie.split(";"); for (i = 0; i < cookies.length; i++) { x = cookies[i].substr(0, cookies[i].indexOf("=")); y = cookies[i].substr(cookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == name) { return y; } } } else { days = days ? days : 365; var expire = new Date(); expire.setDate(expire.getDate() + days); var values = []; if (days !== undefined && days !== null) { values.push("expires=" + expire.toGMTString()); } if (path !== undefined && path !== null) { values.push("path=" + path); } if (domain !== undefined && domain !== null) { values.push("domain=" + domain); } if (secure !== undefined && secure !== null && secure) { values.push("secure"); } if (values.length > 0) { value = value + "; " + values.join("; "); } document.cookie = escape(name) + "=" + value; } }; // if cookie available then return if (cookie(fn)) { return; } // warning box close function window[fn] = { close: function (expire, path, domain, secure) { // set the cookie cookie(fn, true, expire, path, domain, secure); // remove warning box var wbox = document.getElementById(fn + 'Box'); wbox.className = wbox.className + ' closed'; }, reject: function () { // show reject information var wbox = document.getElementById(fn + 'Box'); wbox.className = wbox.className + ' reject'; } }; var warn = function () { // get parameters var tag = document.getElementById('cookieWarn'); if (!tag) { console.error('cookieWarn element not found by id'); return; } var lang = document.documentElement.lang; var data = JSON.parse(tag.getAttribute('data-lang-' + lang).replace(/'/g, '"')); if (!data) { return; } var delay = parseInt(tag.getAttribute('data-delay')); var domain = tag.getAttribute('data-domain'); var path = tag.getAttribute('data-path'); var secure = tag.getAttribute('data-secure'); var expire = parseInt(tag.getAttribute('data-expire')); var style = tag.getAttribute('data-style'); var classes = tag.getAttribute('data-class'); var bootstrap = (window.jQuery && typeof $().modal == 'function'); var css = { style: [ '#' + fn + 'Box {transition:all 0.4s ease-in-out;position:fixed;z-index:999999;bottom:-20px;left:0;right:0;opacity:0;text-align:center;padding:10px;background-color:#212121}', '#' + fn + 'Box .btn {white-space:nowrap}', '#' + fn + 'Box .reject_more {padding:0px 10px;display:none;}', '#' + fn + 'Box.reject .reject_more {display:block;}', '#' + fn + 'Box.loaded {opacity:0.9;bottom:0px}', '#' + fn + 'Box.closed {opacity:0;bottom:-20px}' ], style2: [ '#' + fn + 'Box {font-family: Verdana;line-height:24px;color:#f1f1f1;font-size:14px;}', '#' + fn + 'Box .btn {text-transform:uppercase;cursor:pointer;background-color:#f1f1f1;color:#659fda;padding:3px 14px;margin-left:10px;}', '#' + fn + 'Box .btn:hover {background-color:#ffffff;color:#4d78a5;}', '#' + fn + 'Box a {text-decoration:none;color:#659fda}', ], type: 'text/css', element: document.createElement('style'), append: function () { if (!bootstrap) { this.style = this.style.concat(this.style2); } this.element.type = this.type; this.element.appendChild(document.createTextNode(this.style.join(' '))); document.head.insertBefore(this.element, document.head.childNodes[0]); } }; css.append(); // create warning box var wbox = document.createElement('div'); wbox.setAttribute("id", fn + "Box"); if (classes) { wbox.setAttribute("class", classes); } var args = [ expire ? expire : 'null', path ? "'" + path + "'" : '/', domain ? "'" + domain + "'" : 'null', secure == "true" ? 1 : 0, ].join(','); var info = (data.more_link && data.more_text) ? ' ' + data.more_text + ' ' : ''; var accept_button = '' + data.accept_text + ''; if (data.reject_text) { var reject_button = '' + data.reject_text + ''; var reject_content = '' + data.reject_info + ' ' + data.reject_link + ''; } else { var reject_button = ''; var reject_content = ''; } wbox.innerHTML = '
' + data.text + info + accept_button + reject_button + reject_content + '
'; // append to body var body = document.getElementsByTagName("body")[0]; body.appendChild(wbox); setTimeout(function () { wbox.className = wbox.className + ' loaded'; }, delay ? parseInt(delay) : 500); } var isDOMready = function(){ if (document.readyState == 'complete') { warn(); } else { setTimeout(function () { isDOMready(); }, 1000); } }; isDOMready(); })('cookieWarn');