2 * jQuery Cookie Plugin v1.3.1
3 * https://github.com/carhartl/jquery-cookie
5 * Copyright 2013 Klaus Hartl
6 * Released under the MIT license
9 if (typeof define
=== 'function' && define
.amd
) {
10 // AMD. Register as anonymous module.
11 define(['jquery'], factory
);
25 return decodeURIComponent(s
.replace(pluses
, ' '));
28 function converted(s
) {
29 if (s
.indexOf('"') === 0) {
30 // This is a quoted cookie as according to RFC2068, unescape
31 s
= s
.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g
, '\\');
34 return config
.json
? JSON
.parse(s
) : s
;
38 var config
= $.cookie = function (key
, value
, options
) {
41 if (value
!== undefined) {
42 options
= $.extend({}, config
.defaults
, options
);
44 if (typeof options
.expires
=== 'number') {
45 var days
= options
.expires
, t
= options
.expires
= new Date();
46 t
.setDate(t
.getDate() + days
);
49 value
= config
.json
? JSON
.stringify(value
) : String(value
);
51 return (document
.cookie
= [
52 config
.raw
? key
: encodeURIComponent(key
),
54 config
.raw
? value
: encodeURIComponent(value
),
55 options
.expires
? '; expires=' + options
.expires
.toUTCString() : '', // use expires attribute, max-age is not supported by IE
56 options
.path
? '; path=' + options
.path
: '',
57 options
.domain
? '; domain=' + options
.domain
: '',
58 options
.secure
? '; secure' : ''
63 var decode
= config
.raw
? raw
: decoded
;
64 var cookies
= document
.cookie
.split('; ');
65 var result
= key
? undefined : {};
66 for (var i
= 0, l
= cookies
.length
; i
< l
; i
++) {
67 var parts
= cookies
[i
].split('=');
68 var name
= decode(parts
.shift());
69 var cookie
= decode(parts
.join('='));
71 if (key
&& key
=== name
) {
72 result
= converted(cookie
);
77 result
[name
] = converted(cookie
);
86 $.removeCookie = function (key
, options
) {
87 if ($.cookie(key
) !== undefined) {
88 // Must not alter options, thus extending a fresh object...
89 $.cookie(key
, '', $.extend({}, options
, { expires
: -1 }));