|
7 | 7 | * http://www.gnu.org/licenses/gpl.html |
8 | 8 | * |
9 | 9 | */ |
10 | | -jQuery.cookie = function (key, value, options) { |
| 10 | +(function($) { |
| 11 | + $.cookie = function (key, value, options) { |
11 | 12 |
|
12 | | - // key and at least value given, set cookie... |
13 | | - if (arguments.length > 1 && String(value) !== "[object Object]") { |
14 | | - options = jQuery.extend({}, options); |
| 13 | + // key and at least value given, set cookie... |
| 14 | + if (arguments.length > 1 && String(value) !== "[object Object]") { |
| 15 | + options = $.extend({}, options); |
15 | 16 |
|
16 | | - if (value === null || value === undefined) { |
17 | | - options.expires = -1; |
18 | | - } |
| 17 | + if (value === null || value === undefined) { |
| 18 | + options.expires = -1; |
| 19 | + } |
19 | 20 |
|
20 | | - if (typeof options.expires === 'number') { |
21 | | - var days = options.expires, t = options.expires = new Date(); |
22 | | - t.setDate(t.getDate() + days); |
23 | | - } |
| 21 | + if (typeof options.expires === 'number') { |
| 22 | + var days = options.expires, t = options.expires = new Date(); |
| 23 | + t.setDate(t.getDate() + days); |
| 24 | + } |
24 | 25 |
|
25 | | - value = String(value); |
| 26 | + value = String(value); |
26 | 27 |
|
27 | | - return (document.cookie = [ |
28 | | - encodeURIComponent(key), '=', |
29 | | - options.raw ? value : encodeURIComponent(value), |
30 | | - options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE |
31 | | - options.path ? '; path=' + options.path : '', |
32 | | - options.domain ? '; domain=' + options.domain : '', |
33 | | - options.secure ? '; secure' : '' |
34 | | - ].join('')); |
35 | | - } |
| 28 | + return (document.cookie = [ |
| 29 | + encodeURIComponent(key), '=', |
| 30 | + options.raw ? value : encodeURIComponent(value), |
| 31 | + 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' : '' |
| 35 | + ].join('')); |
| 36 | + } |
36 | 37 |
|
37 | | - // key and possibly options given, get cookie... |
38 | | - options = value || {}; |
39 | | - var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent; |
40 | | - return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null; |
41 | | -}; |
| 38 | + // key and possibly options given, get cookie... |
| 39 | + options = value || {}; |
| 40 | + var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent; |
| 41 | + return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null; |
| 42 | + }; |
| 43 | +})(jQuery); |
0 commit comments