forked from ekdevdes/storage.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookies.js
2 lines (2 loc) · 1.55 KB
/
cookies.js
1
2
// Copyright (c) 2012 Florian H., https://github.com/js-coder https://github.com/js-coder/cookie.js
!function(h,j){function c(){return c.get.apply(c,arguments)}var g={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},d:function(a){return a===Object(a)},e:function(a){return Array.prototype.slice.call(a)},c:Object.keys||function(a){var e=[],b="";for(b in a)a.hasOwnProperty(b)&&e.push(b);return e},a:function(a,e){return a===j?e:a}};c.set=function(a,e,b){if(g.d(a))for(var d in a)a.hasOwnProperty(d)&&this.set(d,a[d]);else{b=b||{};d=b.b||"";var f=typeof d,c=b.path?";path="+b.path:"",i=b.domain?";domain="+b.domain:"",b=b.g?";secure":"";"string"===f&&""!==d?d=";expires="+d:"number"==f?(f=new Date,f.setTime(f.getTime()+86400*d),d=";expires="+f.toGMTString()):d.hasOwnProperty("toGMTString")&&(d=";expires="+d.toGMTString());h.cookie=escape(a)+"="+escape(e)+d+c+i+b}return this};c.remove=function(a){for(var a=g.isArray(a)?a:g.e(arguments),e=0,b=a.length;e<b;e++)this.set(a[e],"",{b:-1});return this};c.empty=function(){return this.remove(g.c(this.all()))};c.get=function(a,e){var e=e||j,b=this.all();if(g.isArray(a)){for(var d={},c=0,h=a.length;c<h;c++){var i=a[c];d[i]=g.a(b[i],e)}return d}return g.a(b[a],e)};c.all=function(){if(""===h.cookie)return{};for(var a=h.cookie.split("; "),c={},b=0,d=a.length;b<d;b++){var f=a[b].split("=");c[f[0]]=unescape(f[1])}return c};c.enabled=function(){var a="b"===c.set("a","b").get("a");c.remove("a");return a};"function"===typeof define&&define.f?define(function(){return c}):window.cookie=c}(document);