Clone
cookie-min.js
YAHOO.namespace("util");YAHOO.util.Cookie={_createCookieString:function(L,J,K,G){var H=YAHOO.lang,I=encodeURIComponent(L)+"="+(K?encodeURIComponent(J):J);if(H.isObject(G)){if(G.expires instanceof Date){I+="; expires="+G.expires.toUTCString();}if(H.isString(G.path)&&G.path!==""){I+="; path="+G.path;}if(H.isString(G.domain)&&G.domain!==""){I+="; domain="+G.domain;}if(G.secure===true){I+="; secure";}}return I;},_createCookieHashString:function(H){var F=YAHOO.lang;if(!F.isObject(H)){throw new TypeError("Cookie._createCookieHashString(): Argument must be an object.");}var G=[];for(var E in H){if(F.hasOwnProperty(H,E)&&!F.isFunction(H[E])&&!F.isUndefined(H[E])){G.push(encodeURIComponent(E)+"="+encodeURIComponent(String(H[E])));}}return G.join("&");},_parseCookieHash:function(I){var J=I.split("&"),H=null,K={};if(I.length>0){for(var L=0,G=J.length;L<G;L++){H=J[L].split("=");K[decodeURIComponent(H[0])]=decodeURIComponent(H[1]);}}return K;},_parseCookieString:function(Q,O){var P={};if(YAHOO.lang.isString(Q)&&Q.length>0){var N=(O===false?function(A){return A;}:decodeURIComponent);var S=Q.split(/;\s/g),R=null,M=null,V=null;for(var L=0,U=S.length;L<U;L++){V=S[L].match(/([^=]+)=/i);if(V instanceof Array){try{R=decodeURIComponent(V[1]);M=N(S[L].substring(V[1].length+1));}catch(T){}}else{R=decodeURIComponent(S[L]);M="";}P[R]=M;}}return P;},exists:function(C){if(!YAHOO.lang.isString(C)||C===""){throw new TypeError("Cookie.exists(): Cookie name must be a non-empty string.");}var D=this._parseCookieString(document.cookie,true);return D.hasOwnProperty(C);},get:function(J,F){var G=YAHOO.lang,I;if(G.isFunction(F)){I=F;F={};}else{if(G.isObject(F)){I=F.converter;}else{F={};}}var H=this._parseCookieString(document.cookie,!F.raw);if(!G.isString(J)||J===""){throw new TypeError("Cookie.get(): Cookie name must be a non-empty string.");}if(G.isUndefined(H[J])){return null;}if(!G.isFunction(I)){return H[J];}else{return I(H[J]);}},getSub:function(F,I,J){var G=YAHOO.lang,H=this.getSubs(F);if(H!==null){if(!G.isString(I)||I===""){throw new TypeError("Cookie.getSub(): Subcookie name must be a non-empty string.");}if(G.isUndefined(H[I])){return null;}if(!G.isFunction(J)){return H[I];}else{return J(H[I]);}}else{return null;}},getSubs:function(F){var D=YAHOO.lang.isString;if(!D(F)||F===""){throw new TypeError("Cookie.getSubs(): Cookie name must be a non-empty string.");}var E=this._parseCookieString(document.cookie,false);if(D(E[F])){return this._parseCookieHash(E[F]);}return null;},remove:function(D,C){if(!YAHOO.lang.isString(D)||D===""){throw new TypeError("Cookie.remove(): Cookie name must be a non-empty string.");}C=YAHOO.lang.merge(C||{},{expires:new Date(0)});return this.set(D,"",C);},removeSub:function(L,I,G){var H=YAHOO.lang;G=G||{};if(!H.isString(L)||L===""){throw new TypeError("Cookie.removeSub(): Cookie name must be a non-empty string.");}if(!H.isString(I)||I===""){throw new TypeError("Cookie.removeSub(): Subcookie name must be a non-empty string.");}var J=this.getSubs(L);if(H.isObject(J)&&H.hasOwnProperty(J,I)){delete J[I];if(!G.removeIfEmpty){return this.setSubs(L,J,G);}else{for(var K in J){if(H.hasOwnProperty(J,K)&&!H.isFunction(J[K])&&!H.isUndefined(J[K])){return this.setSubs(L,J,G);}}return this.remove(L,G);}}else{return"";}},set:function(J,I,F){var G=YAHOO.lang;F=F||{};if(!G.isString(J)){throw new TypeError("Cookie.set(): Cookie name must be a string.");}if(G.isUndefined(I)){throw new TypeError("Cookie.set(): Value cannot be undefined.");}var H=this._createCookieString(J,I,!F.raw,F);document.cookie=H;return H;},setSub:function(L,J,K,G){var H=YAHOO.lang;if(!H.isString(L)||L===""){throw new TypeError("Cookie.setSub(): Cookie name must be a non-empty string.");}if(!H.isString(J)||J===""){throw new TypeError("Cookie.setSub(): Subcookie name must be a non-empty string.");}if(H.isUndefined(K)){throw new TypeError("Cookie.setSub(): Subcookie value cannot be undefined.");}var I=this.getSubs(L);if(!H.isObject(I)){I={};}I[J]=K;return this.setSubs(L,I,G);},setSubs:function(J,I,F){var G=YAHOO.lang;if(!G.isString(J)){throw new TypeError("Cookie.setSubs(): Cookie name must be a string.");}if(!G.isObject(I)){throw new TypeError("Cookie.setSubs(): Cookie value must be an object.");}var H=this._createCookieString(J,this._createCookieHashString(I),false,F);document.cookie=H;return H;}};YAHOO.register("cookie",YAHOO.util.Cookie,{version:"2.9.0",build:"2800"});