1 /*jshint eqnull:true */
3 * jQuery Cookie Plugin v1.2
4 * https://github.com/carhartl/jquery-cookie
6 * Copyright 2011, Klaus Hartl
7 * Dual licensed under the MIT or GPL Version 2 licenses.
8 * http://www.opensource.org/licenses/mit-license.php
9 * http://www.opensource.org/licenses/GPL-2.0
11 (function ($, document
, undefined) {
20 return decodeURIComponent(s
.replace(pluses
, ' '));
23 $.cookie = function (key
, value
, options
) {
25 // key and at least value given, set cookie...
26 if (value
!== undefined && !/Object/.test(Object
.prototype.toString
.call(value
))) {
27 options
= $.extend({}, $.cookie
.defaults
, options
);
33 if (typeof options
.expires
=== 'number') {
34 var days
= options
.expires
, t
= options
.expires
= new Date();
35 t
.setDate(t
.getDate() + days
);
38 value
= String(value
);
40 return (document
.cookie
= [
41 encodeURIComponent(key
), '=', options
.raw
? value
: encodeURIComponent(value
),
42 options
.expires
? '; expires=' + options
.expires
.toUTCString() : '', // use expires attribute, max-age is not supported by IE
43 options
.path
? '; path=' + options
.path
: '',
44 options
.domain
? '; domain=' + options
.domain
: '',
45 options
.secure
? '; secure' : ''
49 // key and possibly options given, get cookie...
50 options
= value
|| $.cookie
.defaults
|| {};
51 var decode
= options
.raw
? raw
: decoded
;
52 var cookies
= document
.cookie
.split('; ');
53 for (var i
= 0, parts
; (parts
= cookies
[i
] && cookies
[i
].split('=')); i
++) {
54 if (decode(parts
.shift()) === key
) {
55 return decode(parts
.join('='));
62 $.cookie
.defaults
= {};
64 $.removeCookie = function (key
, options
) {
65 if ($.cookie(key
, options
) !== null) {
66 $.cookie(key
, null, options
);