1/** 2 * jQuery Cookie plugin 3 * 4 * Copyright (c) 2010 Klaus Hartl (stilbuero.de) 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 */ 10jQuery.cookie = function (key, value, options) { 11 12 // key and at least value given, set cookie... 13 if (arguments.length > 1 && String(value) !== "[object Object]") { 14 options = jQuery.extend({}, options); 15 16 if (value === null || value === undefined) { 17 options.expires = -1; 18 } 19 20 if (typeof options.expires === 'number') { 21 var days = options.expires, t = options.expires = new Date(); 22 t.setDate(t.getDate() + days); 23 } 24 25 value = String(value); 26 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 } 36 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}; 42