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