Skip to content

Instantly share code, notes, and snippets.

@cranca
Last active July 28, 2016 11:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cranca/7775154 to your computer and use it in GitHub Desktop.
Save cranca/7775154 to your computer and use it in GitHub Desktop.
Adaptación del script de Cookie Assistant
_cookie_banner_enable_cookies = true;
_cookie_banner_disable_cookies = false;
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function($) {
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)}(function(e){function n(e){return e}function o(e){return decodeURIComponent(e.replace(t," "))}function i(e){0===e.indexOf('"')&&(e=e.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return r.json?JSON.parse(e):e}catch(n){}}var t=/\+/g,r=e.cookie=function(t,c,a){if(void 0!==c){if(a=e.extend({},r.defaults,a),"number"==typeof a.expires){var u=a.expires,f=a.expires=new Date;f.setDate(f.getDate()+u)}return c=r.json?JSON.stringify(c):String(c),document.cookie=[r.raw?t:encodeURIComponent(t),"=",r.raw?c:encodeURIComponent(c),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}for(var d=r.raw?n:o,p=document.cookie.split("; "),s=t?void 0:{},m=0,x=p.length;x>m;m++){var l=p[m].split("="),g=d(l.shift()),v=d(l.join("="));if(t&&t===g){s=i(v);break}t||(s[g]=i(v))}return s};r.defaults={},e.removeCookie=function(n,o){return void 0!==e.cookie(n)?(e.cookie(n,"",e.extend(o,{expires:-1})),!0):!1}});
function updateWidgetPosition(t){switch($widget=$("#cookie_banner_wrapper"),$widget.removeClass("top-left top-right bottom-left bottom-right"),t){case"top-left":$widget.addClass("top-left");break;case"top-right":$widget.addClass("top-right");break;case"bottom-left":$widget.addClass("bottom-left");break;case"bottom-right":$widget.addClass("bottom-right")}}function updateWidgetTheme(t){$widget=$("#cookie_banner_wrapper"),t.match(/dark/)?$widget.addClass("dark"):$widget.removeClass("dark"),t.match(/large/)?$widget.addClass("large"):$widget.removeClass("large")}
$el = $('#cookie_banner_container')
$el.html("<div id=\"cookie_banner_wrapper\">\n <h2><\/h2> \n <p>Esta web usa cookies para mejorar la experiencia de los usuarios, haz clic para aceptar nuestra política de privacidad. <a href=\"/legal\" class=\"btn-more\" target=\"_blank\">Más información<\/a>\n<\/p>\n\n <div class=\"buttons\">\n <a href=\"#\" class=\"btn-accept\">Acepto<\/a>\n<\/div>\n<\/div>");
var cookie_banner_settings = {"headline":"","text":"Esta web usa cookies para mejorar la experiencia de los usuarios, haz clic para aceptar nuestra política de privacidad.","accept_text":"Acepto","more_text":"Más información","policy_url":"/legal","position":"bottom-right"}
template = 'small-light';
// show or hide ?
if ($.cookie('cookie_banner_enable_cookies') == 'true') {
$el.hide();
} else {
$el.show();
}
if (template && template != '') {
updateWidgetTheme(template);
}
if (position = cookie_banner_settings['position']) {
updateWidgetPosition(position);
}
$el.find('a.btn-accept').click(function() {
$.cookie('cookie_banner_enable_cookies', true, { expires: 356, path: '/' });
$el.fadeOut();
});
$el.find('a.btn-decline').click(function() {
$.cookie('cookie_banner_disable_cookies', true, { expires: 356, path: '/' });
});
$el.find('a.btn-more').click(function() {
});
});
}
})();
/*
* CSS -- Ponlo en tu hoja de estilos
#cookie_banner_wrapper {
position: fixed !important;
width: 100% !important;
max-width: 100% !important;
background-color: #fff !important;
padding: 10px !important;
border: 1px solid #ccc !important;
font-family: 'Open Sans','Helvetica Neue', Helvetica, Arial, sans-serif !important;
font-size: 14px !important;
line-height: 15px !important;
z-index: 9999 !important;
box-shadow: 0px 5px 10px rgba(0,0,0,0.2);
}
#cookie_banner_wrapper.top-left {
left: 10px !important;
top: 10px !important;
}
#cookie_banner_wrapper.top-right {
right: 0px !important;
top: 10px !important;
}
#cookie_banner_wrapper.bottom-left {
left: 10px !important;
bottom: 10px !important;
}
#cookie_banner_wrapper.bottom-right {
right: 0px !important;
bottom: 0px !important;
}
#cookie_banner_wrapper.dark {
background-color: #222 !important;
color: #fff !important;
}
#cookie_banner_wrapper.large {
width: 600px !important;
}
#cookie_banner_wrapper h2 {
font-size: 14px !important;
line-height: 16px !important;
margin: 0 0 4px 0 !important;
padding: 0 !important;
}
#cookie_banner_wrapper p {
margin: 0 !important;
padding: 0 !important;
margin-top: 3px !important;
margin-bottom: 10px !important;
width: auto;
float: left;
}
#cookie_banner_wrapper div.buttons {
margin: 5px 0 3px 0 !important;
width: auto;
float: right;
}
#cookie_banner_wrapper a.btn-accept {
padding: 4px 8px !important;
font-size: 12px !important;
font-family: 'Open Sans''Helvetica Neue',Helvetica,Arial,sans-serif !important;
font-weight: bold !important;
text-align: center !important;
text-decoration: none !important;
cursor: pointer !important;
outline: none !important;
overflow: visible !important;
color: #fff !important;
background: #BBD205 !important;
border: 1px solid #781 !important;
}
#cookie_banner_wrapper a.btn-accept:focus,
#cookie_banner_wrapper a.btn-accept:hover {
text-decoration: none !important;
color: #fff !important;
background: #434343 !important;
border: 1px solid #670 !important;
}
#cookie_banner_wrapper a.btn-more {
color: #0088cc !important;
font-size: 12px !important;
margin-left: 10px !important;
}
* HTML -- Ponlo en el footer
<div id="cookie_banner_container"></div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment