Var COOKIE = (function (){ Var getDateString = function (offset ){ Var date = new Date (); Date. setTime (+ date + offset * 1000 ); Return date. toGMTString (); }, GetCookies = function (){ Var cookie = document. cookie | '', Subs = cookie. split (/; s? /), _ Subs, cks = {}; For (var I = 0; I <subs. length, subs [I]; I ++ ){ _ Subs = subs [I]. split ('= ') Cks [unescape (_ subs [0])] = unescape (_ subs. slice (1). join ('= ')); } Return cks; } Return {
Refresh: function (){ This. cookies = getCookies (); Return this; }, Has: function (key ){ Return this. cookies [key]! = Null; }, Get: function (key ){ Return this. cookies [key]; }, Set: function (key, value, expire, path, domain, secure ){ Var myck = escape (key) + '=' + escape (value = null? '': Value ); If (! IsNaN (expire = parseFloat (expire ))) Myck + = '; expires =' + getDateString (expire ); If (path) myck + = '; path =' + path; If (domain & domain! = Location. hostname) myck + = '; domain =' + domain; If (secure) myck + = '; secure '; Document. cookie = myck; Return this. refresh (). has (key ); }, Remove: function (key, path, domain ){ Var paths = [], Domains = [], Arr, self = this; If (path ){ Paths = [path]; } Else { Arr = location. pathname. match (/.*? /|. + $/G ); This. each (arr, function (I ){ Var; Paths. push (a = arr. slice (0, I + 1). join ('')); If (/[^/] +/$/. test ()){ Paths. push (a. slice (0,-1 )); } If (/[^/] $/. test ()){ Paths. push (a + '/'); } }); } If (domain ){
Domains = [domain]; } Else { Arr = location. hostname. split ('.'); This. each (arr, function (I ){ Domains. push (arr. slice (-I). join ('.')); }); Domains. push ('.' + domains [0]); } This. each (paths, function (){
Var path = this + ''; Self. each (domains, function (){ Self. set (key, '',-1000, path, this + ''); }); }); Return !! Path | !! Domain |! This. has (key );
}, Clear: function (path, domain ){ For (var key in this. cookies ){ This. remove (key, path, domain ); } Return !! Path | !! Domain | function (){ For (var key in this. cookies ){ Return false; } Return true; }. Call (this ); }, Each: function (arr, func ){ Var I = 0, j = arr. length; For (; I <j; I ++ ){ If (func. call (arr [I], I) === false ){ Break; } } } }. Refresh (); })(); |