-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathjquery.ihavecookies.min.js
10 lines (10 loc) · 4.01 KB
/
jquery.ihavecookies.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* ihavecookies - jQuery plugin for displaying cookie/privacy message
* v0.3.2
*
* Copyright (c) 2018 Ketan Mistry (https://iamketan.com.au)
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
!function(p){p.fn.ihavecookies=function(e,o){var i=p(this),t=p.extend({cookieTypes:[{type:"Site Preferences",value:"preferences",description:"These are cookies that are related to your site preferences, e.g. remembering your username, site colours, etc."},{type:"Analytics",value:"analytics",description:"Cookies related to site visits, browser types, etc."},{type:"Marketing",value:"marketing",description:"Cookies related to marketing, e.g. newsletters, social media, etc"}],title:"Cookies & Privacy",message:"Cookies enable you to use shopping carts and to personalize your experience on our sites, tell us which parts of our websites people have visited, help us measure the effectiveness of ads and web searches, and give us insights into user behavior so we can improve our communications and products.",link:"/privacy-policy",delay:2e3,expires:30,moreInfoLabel:"More information",acceptBtnLabel:"Accept Cookies",advancedBtnLabel:"Customise Cookies",cookieTypesTitle:"Select cookies to accept",fixedCookieTypeLabel:"Necessary",fixedCookieTypeDesc:"These are cookies that are essential for the website to work correctly.",onAccept:function(){},uncheckBoxes:!1},e),n=u("cookieControl"),c=u("cookieControlPrefs");if(n&&c&&"reinit"!=o){var r=!0;"false"==n&&(r=!1),d(r,t.expires)}else{p("#gdpr-cookie-message").remove();var a='<li><input type="checkbox" name="gdpr[]" value="necessary" checked="checked" disabled="disabled"> <label title="'+t.fixedCookieTypeDesc+'">'+t.fixedCookieTypeLabel+"</label></li>";preferences=JSON.parse(c),p.each(t.cookieTypes,function(e,o){if(""!==o.type&&""!==o.value){var i="";!1!==o.description&&(i=' title="'+o.description+'"'),a+='<li><input type="checkbox" id="gdpr-cookietype-'+o.value+'" name="gdpr[]" value="'+o.value+'" data-auto="on"> <label for="gdpr-cookietype-'+o.value+'"'+i+">"+o.type+"</label></li>"}});var s='<div id="gdpr-cookie-message"><h4>'+t.title+"</h4><p>"+t.message+' <a href="'+t.link+'">'+t.moreInfoLabel+'</a><div id="gdpr-cookie-types" style="display:none;"><h5>'+t.cookieTypesTitle+"</h5><ul>"+a+'</ul></div><p><button id="gdpr-cookie-accept" type="button">'+t.acceptBtnLabel+'</button><button id="gdpr-cookie-advanced" type="button">'+t.advancedBtnLabel+"</button></p></div>";setTimeout(function(){p(i).append(s),p("#gdpr-cookie-message").hide().fadeIn("slow",function(){"reinit"==o&&(p("#gdpr-cookie-advanced").trigger("click"),p.each(preferences,function(e,o){p("input#gdpr-cookietype-"+o).prop("checked",!0)}))})},t.delay),p("body").on("click","#gdpr-cookie-accept",function(){d(!0,t.expires),p('input[name="gdpr[]"][data-auto="on"]').prop("checked",!0);var i=[];p.each(p('input[name="gdpr[]"]').serializeArray(),function(e,o){i.push(o.value)}),l("cookieControlPrefs",encodeURIComponent(JSON.stringify(i)),365),t.onAccept.call(this)}),p("body").on("click","#gdpr-cookie-advanced",function(){p('input[name="gdpr[]"]:not(:disabled)').attr("data-auto","off").prop("checked",!1),p("#gdpr-cookie-types").slideDown("fast",function(){p("#gdpr-cookie-advanced").prop("disabled",!0)})})}!0===t.uncheckBoxes&&p('input[type="checkbox"].ihavecookies').prop("checked",!1)},p.fn.ihavecookies.cookie=function(){var e=u("cookieControlPrefs");return JSON.parse(e)},p.fn.ihavecookies.preference=function(e){var o=u("cookieControl"),i=u("cookieControlPrefs");return i=JSON.parse(i),!1!==o&&(!1!==i&&-1!==i.indexOf(e))};var d=function(e,o){l("cookieControl",e,o),p("#gdpr-cookie-message").fadeOut("fast",function(){p(this).remove()})},l=function(e,o,i){var t=new Date;t.setTime(t.getTime()+24*i*60*60*1e3);var n="expires="+t.toUTCString();return document.cookie=e+"="+o+";"+n+";path=/",u(e)},u=function(e){for(var o=e+"=",i=decodeURIComponent(document.cookie).split(";"),t=0;t<i.length;t++){for(var n=i[t];" "==n.charAt(0);)n=n.substring(1);if(0===n.indexOf(o))return n.substring(o.length,n.length)}return!1}}(jQuery);