Skip to content

Commit 6ae9a22

Browse files
committed
update with latest code from MDN
1 parent a1922b5 commit 6ae9a22

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docCookies.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
|*|
55
|*| A complete cookies reader/writer framework with full unicode support.
66
|*|
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
811
|*|
912
|*| This framework is released under the GNU Public License, version 3 or later.
1013
|*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
@@ -13,14 +16,15 @@
1316
|*|
1417
|*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
1518
|*| * docCookies.getItem(name)
16-
|*| * docCookies.removeItem(name[, path], domain)
19+
|*| * docCookies.removeItem(name[, path[, domain]])
1720
|*| * docCookies.hasItem(name)
1821
|*| * docCookies.keys()
1922
|*|
2023
\*/
2124

2225
var docCookies = {
2326
getItem: function (sKey) {
27+
if (!sKey) { return null; }
2428
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
2529
},
2630
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
@@ -43,16 +47,17 @@ var docCookies = {
4347
return true;
4448
},
4549
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 : "");
4852
return true;
4953
},
5054
hasItem: function (sKey) {
55+
if (!sKey) { return false; }
5156
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
5257
},
53-
keys: /* optional method: you can safely remove it! */ function () {
58+
keys: function () {
5459
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]); }
5661
return aKeys;
5762
}
5863
};

0 commit comments

Comments
 (0)