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
8 (function ($, document
, undefined) {
17 return unRfc2068(decodeURIComponent(s
.replace(pluses
, ' ')));
20 function unRfc2068(value
) {
21 if (value
.indexOf('"') === 0) {
22 // This is a quoted cookie as according to RFC2068, unescape
23 value
= value
.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g
, '\\');
28 function fromJSON(value
) {
29 return config
.json
? JSON
.parse(value
) : value
;
32 var config
= $.cookie = function (key
, value
, options
) {
35 if (value
!== undefined) {
36 options
= $.extend({}, config
.defaults
, options
);
42 if (typeof options
.expires
=== 'number') {
43 var days
= options
.expires
, t
= options
.expires
= new Date();
44 t
.setDate(t
.getDate() + days
);
47 value
= config
.json
? JSON
.stringify(value
) : String(value
);
49 return (document
.cookie
= [
50 encodeURIComponent(key
), '=', config
.raw
? value
: encodeURIComponent(value
),
51 options
.expires
? '; expires=' + options
.expires
.toUTCString() : '', // use expires attribute, max-age is not supported by IE
52 options
.path
? '; path=' + options
.path
: '',
53 options
.domain
? '; domain=' + options
.domain
: '',
54 options
.secure
? '; secure' : ''
59 var decode
= config
.raw
? raw
: decoded
;
60 var cookies
= document
.cookie
.split('; ');
61 var result
= key
? null : {};
62 for (var i
= 0, l
= cookies
.length
; i
< l
; i
++) {
63 var parts
= cookies
[i
].split('=');
64 var name
= decode(parts
.shift());
65 var cookie
= decode(parts
.join('='));
67 if (key
&& key
=== name
) {
68 result
= fromJSON(cookie
);
73 result
[name
] = fromJSON(cookie
);
82 $.removeCookie = function (key
, options
) {
83 if ($.cookie(key
) !== null) {
84 $.cookie(key
, null, options
);