]>
git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blob - cmd/web/js/cookies.js
7 |*| A complete cookies reader/writer framework with full unicode support.
9 |*| Revision #1 - September 4, 2014
11 |*| https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
12 |*| https://developer.mozilla.org/User:fusionchess
14 |*| This framework is released under the GNU Public License, version 3 or later.
15 |*| http://www.gnu.org/licenses/gpl-3.0-standalone.html
19 |*| * docCookies.setItem(name, value[, end[, path[, domain[, secure]]]])
20 |*| * docCookies.getItem(name)
21 |*| * docCookies.removeItem(name[, path[, domain]])
22 |*| * docCookies.hasItem(name)
23 |*| * docCookies.keys()
28 getItem: function(sKey
) {
29 if (!sKey
) { return null; }
30 return decodeURIComponent(document
.cookie
.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey
).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
32 setItem: function(sKey
, sValue
, vEnd
, sPath
, sDomain
, bSecure
) {
33 if (!sKey
|| /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey
)) { return false; }
36 switch (vEnd
.constructor) {
38 sExpires
= vEnd
=== Infinity
? '; expires=Fri, 31 Dec 9999 23:59:59 GMT' : '; max-age=' + vEnd
;
41 sExpires
= '; expires=' + vEnd
;
44 sExpires
= '; expires=' + vEnd
.toUTCString();
48 document
.cookie
= encodeURIComponent(sKey
) + '=' + encodeURIComponent(sValue
) + sExpires
+ (sDomain
? '; domain=' + sDomain : '') + (sPath
? '; path=' + sPath : '') + (bSecure
? '; secure' : '');
51 removeItem: function(sKey
, sPath
, sDomain
) {
52 if (!this.hasItem(sKey
)) { return false; }
53 document
.cookie
= encodeURIComponent(sKey
) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain
? '; domain=' + sDomain : '') + (sPath
? '; path=' + sPath : '');
56 hasItem: function(sKey
) {
57 if (!sKey
) { return false; }
58 return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(sKey
).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document
.cookie
);
61 var aKeys
= document
.cookie
.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, '').split(/\s*(?:\=[^;]*)?;\s*/);
62 for (var nLen
= aKeys
.length
, nIdx
= 0; nIdx
< nLen
; nIdx
++) { aKeys
[nIdx
] = decodeURIComponent(aKeys
[nIdx
]); }