-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.easyCookie.min.js
1 lines (1 loc) · 5.52 KB
/
jquery.easyCookie.min.js
1
(function(a){"use strict";a.easyCookie=function(b,c,d){function e(a){return a.hasOwnProperty("name")&&0<a.name.length&&a.hasOwnProperty("value")&&0<a.value.length&&a.hasOwnProperty("expire")&&0<a.value.length}function f(){const a=document.cookie.split(";");return 0<a.length?a.map(function(a){return a.trim().split("=")}).reduce(function(a,b){return a[b[0]]=b[1],a},{}):[]}function g(a,b,c){document.cookie=a+"="+encodeURIComponent(b)+";domain="+h.domain+";path="+h.path+";expires="+c.toUTCString()+(h.secure?";secure":"")}const h=a.extend(!0,{domain:location.hostname,path:"/",secure:!1,expire:1},d);navigator.cookieEnabled||a.error("Cookies not enabled.");const i={getAll:function(){return f()},setMulti:function(b){const c=[],d=i;return a.isArray(b)||a.error("You need to specify an array."),1>b.length&&a.error("No element in the array."),b.map(function(a){if(e(a)){let b=!1;const e=a.expire_type,f=a.name,g=a.value,h=a.expire;"years"===e?(b=d.setYears(f,g,h),c.push({name:f,status:b})):"months"===e?(b=d.setMonth(f,g,h),c.push({name:f,status:b})):"days"===e?(b=d.setDays(f,g,h),c.push({name:f,status:b})):"hours"===e?(b=d.setHours(f,g,h),c.push({name:f,status:b})):"minutes"===e?(b=d.setMinutes(f,g,h),c.push({name:f,status:b})):"seconds"===e?(b=d.setSeconds(f,g,h),c.push({name:f,status:b})):(b=d.setDays(f,g,h),c.push({name:f,status:b}))}}),c},removeMulti:function(b){const c=[];return a.isArray(b)||a.error("You need to specify an array."),1>b.length&&a.error("No element in the array."),b.map(function(a){const b=i.remove(a);c.push({name:a,status:b})}),c},set:function(a,b){return this.setDays(a,b,h.expire),this.has(a)},has:function(a){return this.getAll().hasOwnProperty(a)},get:function(a){return this.has(a)?decodeURIComponent(this.getAll()[a]):null},remove:function(a){return!!this.has(a)&&this.setSeconds(a,"",1)},count:function(){return document.cookie.split(";").length},setYears:function(a,b,c=1){const d=new Date;return d.setFullYear(d.getFullYear()+c),g(a,b,d),this.has(a)},setMonth:function(a,b,c=1){const d=new Date;return d.setMonth(d.getMonth()+c),g(a,b,d),this.has(a)},setDays:function(a,b,c=1){const d=new Date;return d.setDate(d.getDate()+c),g(a,b,d),this.has(a)},setHours:function(a,b,c=1){const d=new Date;return d.setHours(d.getHours()+c),g(a,b,d),this.has(a)},setMinutes:function(a,b,c=1){const d=new Date;return d.setMinutes(d.getMinutes()+c),g(a,b,d),this.has(a)},setSeconds:function(a,b,c=1){const d=new Date;return d.setSeconds(d.getSeconds()+c),g(a,b,d),this.has(a)},init:function(){b&&c&&this.setDays(b,c,h.expire)}};return i.init(),i},a.easyCookieConsent=function(b){function c(){let b="";return a.ajax({async:!1,url:"http://ip-api.com/json/",type:"GET",dataType:"json",success:function(a){"success"===a.status&&(b=a.countryCode.toLocaleLowerCase())}}),b}const d=a.extend(!0,{palette:{button:{text:"#000",background:"#ddd"},popup:{text:"#000",background:"#fff"},link:{text:"#606060",background:"transparent"}},content:{message:"Lorem ipsum dolor sit amet, consectetur adipisicing elit. A accusantium architecto aut cum dolorem eos error, esse explicabo, fugiat fugit maxime perferendis qui quod ratione repellat repellendus saepe temporibus veritatis.",dismiss:"Ok, thanks!",link:"privacy policy.",href:"https://google.com"},country:!1,language:{tr:{message:"Lorem ipsum dolor sit amet, consectetur adipisicing elit. A accusantium architecto aut cum dolorem eos error, esse explicabo, fugiat fugit maxime perferendis qui quod ratione repellat repellendus saepe temporibus veritatis.",dismiss:"Ok, thanks!",link:"privacy policy.",href:"https://google.com"}},cookie_name:"easy_cookie_consent_status"},b);let e="";const f=a.easyCookie(),g=d.cookie_name,h=""===c()||f.has(g)?"tr":c(),i=d.country?d.language[h]:d.content,j=".easy_cookie_consent_content",k=i.message,l=i.dismiss,m=i.link,n=i.href,o=d.palette,p=f.has(g),q=a("body"),r=a("<style/>",{type:"text/css"}).text(".easy_cookie_consent_content{position:fixed;bottom:0;background:#fff;max-width:850px;left:0;right:0;padding:5px;margin:0 auto;height:auto;display:flex;display:-webkit-flex;align-items:center;justify-content:center;z-index:1000;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;-webkit-border-radius:5px 5px 0 0;-moz-border-radius:5px 5px 0 0;border-radius:5px 5px 0 0;-webkit-box-shadow:0 -2px 5px rgba(0,0,0,0.4);-moz-box-shadow:0 -2px 5px rgba(0,0,0,0.4);box-shadow:0 -2px 5px rgba(0,0,0,0.4)}.easy_cookie_consent_content p{margin:0;display:inline-block;word-break:break-all}.easy_cookie_consent_content p > a[href]{color:#606060}.easy_cookie_consent_content button{margin-left:20px;padding:.4em .8em;font-size:.9em;border:2px solid #ddd;text-align:center;border-radius:4px;cursor:pointer;outline:none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}@media only screen and (max-width: 600px){.easy_cookie_consent_content button{margin-left:0!important;display:block!important;width:100%!important;margin-top:3px}.easy_cookie_consent_content{border-radius:0!important;display:block!important}}");1>g.length&&a.error("The cookie_name parameter cannot be empty."),e+="<div class=\"easy_cookie_consent_content\">",k&&(e+="<p>"),e+=k,m&&n&&(e+=" <a href=\""+n+"\">"+m+"</a>"),e+="</p>",l&&(e+="<button>"+l+"</button>"),e+="</div>",!0!==p&&(a("head").append(r),q.append(e),a(j).css({color:o.popup.text,backgroundColor:o.popup.background}),a(j+" p > a[href]").css({color:o.link.text,backgroundColor:o.link.background}),a(j+" > button").css({color:o.button.text,backgroundColor:o.button.background}),q.on("click",j+" button",function(){f.setYears(g,"active")&&a(j).remove()}))}})(jQuery);