Instantly share code, notes, and snippets.
Last active
August 29, 2015 14:05
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save oropesa/e1eae4e222bc41ecc8e9 to your computer and use it in GitHub Desktop.
Wordpress Cookies Managing. Is not all the code, but It's the first template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var //cookie | |
, $btnCookie = $('#btn-acceptCookies') | |
, $divCookie = $('div.cookiesAlert') | |
, theCookieKey = 'THE_SITE_NAME_cookie_policy' | |
, theCookieVal = 'accepted' | |
, theCookieDays = 15 | |
//cookie erasing | |
, $btnDeleteCookies = $('#btn-deleteAllCookies') | |
, cookieDeleteText = 'Our cookies have been removed from your device successfully. ' | |
+ '<a id="deleteAllCookiesConfirm" class="btn btn-danger btn-cookies" href="#deleteAllCookiesConfirm">OK</a>' | |
//cookie functions | |
,setCookie = function(key, value, days) { | |
var expires = '' | |
, date = new Date() | |
; | |
if (days) { | |
date.setTime( date.getTime()+(days*24*60*60*1000) ); | |
expires = "; expires=" + date.toGMTString(); | |
} | |
document.cookie = key + "=" + value + expires + "; path=/"; | |
} | |
, eraseCookie = function(key) { | |
setCookie(key, "", -1); | |
} | |
, eraseAllCookies = function() { | |
var cookies = document.cookie.split(';') | |
, cookiesLength = cookies.length | |
, i = 0 | |
; | |
for(;i < cookiesLength; i++) { | |
eraseCookie(cookies[i]); | |
} | |
} | |
, getCookie = function(key) { | |
var keyEQ = key + "=" | |
, cookies = document.cookie.split(';') | |
, cookie | |
, i = 0 | |
; | |
for(;i < cookies.length; i++) { | |
cookie = cookies[i]; | |
while (cookie.charAt(0) == ' ') | |
cookie = cookie.substring(1, cookie.length); | |
if (cookie.indexOf(keyEQ) == 0) | |
return cookie.substring(keyEQ.length, cookie.length); | |
} | |
return null; | |
} | |
; | |
//cookies | |
if($btnCookie.length) { | |
$btnCookie.on('click', function(e) { | |
e.preventDefault(); | |
setCookie(theCookieKey, theCookieVal, theCookieDays); | |
$divCookie.addClass(theCookieVal); | |
}); | |
} | |
if($btnDeleteCookies.length) { | |
$btnDeleteCookies | |
.popover({ | |
'content' : cookieDeleteText | |
, 'html' : true | |
}) | |
.on('click', function(e) { | |
e.preventDefault(); | |
eraseAllCookies(); | |
}); | |
$btnDeleteCookies.on('shown.bs.popover', function () { | |
$('#deleteAllCookiesConfirm').on('click', function(e) { | |
e.preventDefault(); | |
$btnDeleteCookies.popover('hide'); | |
}); | |
}) | |
} | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//COOKIE MESSAGE | |
.cookiesAlert { | |
background: @darkgray; | |
color: white; | |
font-size: 1.3rem; | |
overflow: hidden; | |
text-align: center; | |
&.accepted { | |
.container { | |
margin-top: -30%; | |
} | |
} | |
.container { | |
.transition(all ease 3s); | |
position: relative; | |
overflow: hidden; | |
padding: 1.5rem; | |
a { | |
color: @white; | |
text-decoration: underline; | |
white-space: nowrap; | |
&.btn-cookie { | |
margin: .7rem; | |
padding: .3rem .8rem; | |
background: white; | |
color: @darkgray; | |
text-decoration: none; | |
border-radius: 5px; | |
border-bottom: 2px solid darken(@white, 25%); | |
} | |
} | |
p { | |
margin: 0; | |
} | |
} | |
} | |
//Button Delet Cookie | |
.btn-cookies { | |
padding: 0 .5rem; | |
font-size: 1.2rem; | |
position: relative; | |
display: inline-block; | |
top: -2px; | |
margin-left: .2rem; | |
} | |
.popover { | |
font-size: 1.3rem; | |
border-color: @brand-danger; | |
color: @brand-danger; | |
&.right > .arrow { | |
border-right-color: @brand-danger; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Hook this on the top of the body | |
*/ | |
function cookie_message() { | |
if( isset($_COOKIE['THE_SITE_NAME_cookie_policy']) ){ | |
$theCookieDays = 15; //expire 15 days | |
setcookie('THE_SITE_NAME_cookie_policy', 'accepted', time()+($theCookieDays*3600*24), '/'); | |
return; | |
} | |
$cookieURL = 'http://THE_SITE_NAME_URL/COOKIES_PAGE'; | |
?> | |
<div class="cookiesAlert"> | |
<div class="container"> | |
<div class="col-xs-12 col-sm-12"> | |
<p>In <?php bloginfo('name') ?> We use proprietary and third party cookies. We consider that if you continue to browse accepts use. <a href="<?php echo $cookieURL ?>">Learn more</a><a class="btn-acceptCookies" href="#aceptar-cookies">Ok</a></p> | |
</div> | |
</div> | |
</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment