Initial import of the bdmurphy Bookshelf work: the bd-bookshelf theme, bd-bookshelf-plugin, bd-bookshelfhelper and bd-simpleemail plugins, plus the specification documents, mockups and release archives.
68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
/**
|
|
* BD Bookshelf - GDPR Consent
|
|
*
|
|
* @package BD_Bookshelf
|
|
*/
|
|
|
|
(function($) {
|
|
'use strict';
|
|
|
|
$(document).ready(function() {
|
|
// Check if consent already given
|
|
if (bdBookshelfHasConsent()) {
|
|
return;
|
|
}
|
|
|
|
// Show banner
|
|
$('#bd-bookshelf-gdpr-banner').show();
|
|
|
|
// Handle accept button
|
|
$('#bd-bookshelf-gdpr-accept').on('click', function() {
|
|
$.ajax({
|
|
url: bdBookshelfGdpr.ajaxurl,
|
|
type: 'POST',
|
|
data: {
|
|
action: 'bd_bookshelf_accept_consent',
|
|
nonce: bdBookshelfGdpr.nonce
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
// Set cookie
|
|
bdBookshelfSetCookie('bd_bookshelf_consent', '1', bdBookshelfGdpr.cookieDays);
|
|
|
|
// Hide banner
|
|
$('#bd-bookshelf-gdpr-banner').fadeOut(300);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
function bdBookshelfHasConsent() {
|
|
return bdBookshelfGetCookie('bd_bookshelf_consent') === '1';
|
|
}
|
|
|
|
function bdBookshelfSetCookie(name, value, days) {
|
|
var date = new Date();
|
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
var expires = "expires=" + date.toUTCString();
|
|
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
|
}
|
|
|
|
function bdBookshelfGetCookie(name) {
|
|
var nameEQ = name + "=";
|
|
var ca = document.cookie.split(';');
|
|
for (var i = 0; i < ca.length; i++) {
|
|
var c = ca[i];
|
|
while (c.charAt(0) == ' ') {
|
|
c = c.substring(1);
|
|
}
|
|
if (c.indexOf(nameEQ) == 0) {
|
|
return c.substring(nameEQ.length, c.length);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
})(jQuery);
|