4
4
|*|
5
5
|*| A complete cookies reader/writer framework with full unicode support.
6
6
|*|
7
- |*| https://developer.mozilla.org/en-US/docs/DOM/document.cookie
7
+ |*| Revision #1 - September 4, 2014
8
+ |*|
9
+ |*| https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
10
+ |*| https://developer.mozilla.org/User:fusionchess
8
11
|*|
9
12
|*| This framework is released under the GNU Public License, version 3 or later.
10
13
|*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
13
16
|*|
14
17
|*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
15
18
|*| * docCookies.getItem(name)
16
- |*| * docCookies.removeItem(name[, path] , domain)
19
+ |*| * docCookies.removeItem(name[, path[ , domain]] )
17
20
|*| * docCookies.hasItem(name)
18
21
|*| * docCookies.keys()
19
22
|*|
20
23
\*/
21
24
22
25
var docCookies = {
23
26
getItem : function ( sKey ) {
27
+ if ( ! sKey ) { return null ; }
24
28
return decodeURIComponent ( document . cookie . replace ( new RegExp ( "(?:(?:^|.*;)\\s*" + encodeURIComponent ( sKey ) . replace ( / [ \- \. \+ \* ] / g, "\\$&" ) + "\\s*\\=\\s*([^;]*).*$)|^.*$" ) , "$1" ) ) || null ;
25
29
} ,
26
30
setItem : function ( sKey , sValue , vEnd , sPath , sDomain , bSecure ) {
@@ -43,16 +47,17 @@ var docCookies = {
43
47
return true ;
44
48
} ,
45
49
removeItem : function ( sKey , sPath , sDomain ) {
46
- if ( ! sKey || ! this . hasItem ( sKey ) ) { return false ; }
47
- document . cookie = encodeURIComponent ( sKey ) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + ( sDomain ? "; domain=" + sDomain : "" ) + ( sPath ? "; path=" + sPath : "" ) ;
50
+ if ( ! this . hasItem ( sKey ) ) { return false ; }
51
+ document . cookie = encodeURIComponent ( sKey ) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + ( sDomain ? "; domain=" + sDomain : "" ) + ( sPath ? "; path=" + sPath : "" ) ;
48
52
return true ;
49
53
} ,
50
54
hasItem : function ( sKey ) {
55
+ if ( ! sKey ) { return false ; }
51
56
return ( new RegExp ( "(?:^|;\\s*)" + encodeURIComponent ( sKey ) . replace ( / [ \- \. \+ \* ] / g, "\\$&" ) + "\\s*\\=" ) ) . test ( document . cookie ) ;
52
57
} ,
53
- keys : /* optional method: you can safely remove it! */ function ( ) {
58
+ keys : function ( ) {
54
59
var aKeys = document . cookie . replace ( / ( (?: ^ | \s * ; ) [ ^ \= ] + ) (? = ; | $ ) | ^ \s * | \s * (?: \= [ ^ ; ] * ) ? (?: \1| $ ) / g, "" ) . split ( / \s * (?: \= [ ^ ; ] * ) ? ; \s * / ) ;
55
- for ( var nIdx = 0 ; nIdx < aKeys . length ; nIdx ++ ) { aKeys [ nIdx ] = decodeURIComponent ( aKeys [ nIdx ] ) ; }
60
+ for ( var nLen = aKeys . length , nIdx = 0 ; nIdx < nLen ; nIdx ++ ) { aKeys [ nIdx ] = decodeURIComponent ( aKeys [ nIdx ] ) ; }
56
61
return aKeys ;
57
62
}
58
63
} ;
0 commit comments