|
11 | 11 | $.cookie = function(key, value, options) { |
12 | 12 |
|
13 | 13 | // key and at least value given, set cookie... |
14 | | - if (arguments.length > 1 && (Object.prototype.toString.call(value) === "[object String]" || value === null || value === undefined)) { |
| 14 | + if (arguments.length > 1 && (Object.prototype.toString.call(value) === '[object String]' || value === null || value === undefined)) { |
15 | 15 | options = $.extend({}, options); |
16 | 16 |
|
17 | 17 | if (value === null || value === undefined) { |
|
26 | 26 | value = String(value); |
27 | 27 |
|
28 | 28 | return (document.cookie = [ |
29 | | - encodeURIComponent(key), '=', |
30 | | - options.raw ? value : encodeURIComponent(value), |
| 29 | + encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), |
31 | 30 | options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE |
32 | | - options.path ? '; path=' + options.path : '', |
33 | | - options.domain ? '; domain=' + options.domain : '', |
34 | | - options.secure ? '; secure' : '' |
| 31 | + options.path ? '; path=' + options.path : '', |
| 32 | + options.domain ? '; domain=' + options.domain : '', |
| 33 | + options.secure ? '; secure' : '' |
35 | 34 | ].join('')); |
36 | 35 | } |
37 | 36 |
|
38 | 37 | // key and possibly options given, get cookie... |
39 | 38 | options = value || {}; |
40 | 39 | var decode = options.raw ? function(s) { return s; } : decodeURIComponent; |
41 | 40 |
|
42 | | - var parts = document.cookie.split('; '); |
43 | | - for (var i = 0, part; part = parts[i]; i++) { |
44 | | - var pair = part.split('='); |
45 | | - if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB |
| 41 | + var pairs = document.cookie.split('; '); |
| 42 | + for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) { |
| 43 | + if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined |
46 | 44 | } |
47 | 45 | return null; |
48 | 46 | }; |
|
0 commit comments