';
}
});
// Display cookie message on page
var cookieMessage = '
';
setTimeout(function(){
$($element).append(cookieMessage);
$('#gdpr-cookie-message').hide().fadeIn('slow', function(){
// If reinit'ing, open the advanced section of message
// and re-check all previously selected options.
if (event == 'reinit') {
$('#gdpr-cookie-advanced').trigger('click');
$.each(preferences, function(index, field) {
$('input#gdpr-cookietype-' + field).prop('checked', true);
});
}
});
var item_num = $('.ui-tabs li').length + 1;
var btn_state = true;
$('.ui-tabs li').hover(function(){
$(this).addClass('hover');
},function(){
$(this).removeClass('hover');
});
// Tabs managment
$('.ui-tabs li').click(function(){
var btn_state = true;
if(btn_state){
btn_state = !btn_state;
$('.ui-tabs li').removeClass('opened-tab');
$(this).addClass('opened-tab');
var i = $('.ui-tabs li').index(this);
$('.ui-tab').removeClass('show');
$('.ui-tab').addClass('aui-helper-hidden');
$('.ui-tab').eq(i).addClass('show');
$('.ui-tab').eq(i).removeClass('aui-helper-hidden');
setTimeout(function(){
btn_state = !btn_state;
},500);
}
});
}, settings.delay);
// When accept button is clicked drop cookie
$('body').on('click','#gdpr-cookie-accept', function(){
// Set cookie
dropCookie(true, settings.expires);
// If 'data-auto' is set to ON, tick all checkboxes because
// the user hasn't clicked the customise cookies button
$('input[name="gdpr[]"][data-auto="on"]').prop('checked', true);
// Save users cookie preferences (in a cookie!)
var prefs = [];
$.each($('input[name="gdpr[]"]').serializeArray(), function(i, field){
prefs.push(field.value);
});
setCookie('cookieControlPrefs', encodeURIComponent(JSON.stringify(prefs)), 365);
// Run callback function
settings.onAccept.call(this);
});
$('body').on('click', '#gdpr-cookie-agree', function(){
// 12 months
setCookie('cookieControl', true, 365*24);
setCookie('cookieControlPrefs', encodeURIComponent(JSON.stringify(['statistics'])), 365*24);
hideMessage();
settings.onAccept.call(this);
});
$('body').on('click', '#gdpr-cookie-disagree', function(){
// 182 days / 1/2 year
setCookie('cookieControl', true, 182 * 24);
setCookie('cookieControlPrefs', encodeURIComponent(JSON.stringify([])), 0);
hideMessage();
settings.onAccept.call(this);
});
// Toggle advanced cookie options
$('body').on('click', '#gdpr-cookie-advanced', function(){
// Uncheck all checkboxes except for the disabled 'necessary'
// one and set 'data-auto' to OFF for all. The user can now
// select the cookies they want to accept.
$('input[name="gdpr[]"]:not(:disabled)').attr('data-auto', 'off').prop('checked', false);
$('#gdpr-cookie-types').slideDown('fast', function(){
$('#gdpr-cookie-advanced').prop('disabled', true);
});
});
}
// Uncheck any checkboxes on page load
if (settings.uncheckBoxes === true) {
$('input[type="checkbox"].ihavecookies').prop('checked', false);
}
};
// Method to get cookie value
$.fn.ihavecookies.cookie = function() {
var preferences = getCookie('cookieControlPrefs');
return JSON.parse(preferences);
};
// Method to check if user cookie preference exists
$.fn.ihavecookies.preference = function(cookieTypeValue) {
var control = getCookie('cookieControl');
var preferences = getCookie('cookieControlPrefs');
preferences = JSON.parse(preferences);
if (control === false) {
return false;
}
if (preferences === false || preferences.indexOf(cookieTypeValue) === -1) {
return false;
}
return true;
};
var hideMessage = function() {
$('#gdpr-cookie-message').fadeOut('fast', function() {
$(this).remove();
});
}
/*
|--------------------------------------------------------------------------
| Drop Cookie
|--------------------------------------------------------------------------
|
| Function to drop the cookie with a boolean value of true.
|
*/
var dropCookie = function(value, expiryHours) {
setCookie('cookieControl', value, expiryHours);
hideMessage();
};
/*
|--------------------------------------------------------------------------
| Set Cookie
|--------------------------------------------------------------------------
|
| Sets cookie with 'name' and value of 'value' for 'expiry_hours'.
|
*/
var setCookie = function(name, value, expiry_hours) {
var d = new Date();
d.setTime(d.getTime() + (expiry_hours*60*60*1000));
var expires = "expires=" + d.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
return getCookie(name);
};
/*
|--------------------------------------------------------------------------
| Get Cookie
|--------------------------------------------------------------------------
|
| Gets cookie called 'name'.
|
*/
var getCookie = function(name) {
var cookie_name = name + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i