1// $Id: jquery.cookie.js,v 1.1.4.1 2010/01/12 15:32:29 attheshow Exp $ 2 3/** 4 * Cookie plugin 5 * 6 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) 7 * Dual licensed under the MIT and GPL licenses: 8 * http://www.opensource.org/licenses/mit-license.php 9 * http://www.gnu.org/licenses/gpl.html 10 * 11 */ 12 13/** 14 * Create a cookie with the given name and value and other optional parameters. 15 * 16 * @example $.cookie('the_cookie', 'the_value'); 17 * @desc Set the value of a cookie. 18 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); 19 * @desc Create a cookie with all available options. 20 * @example $.cookie('the_cookie', 'the_value'); 21 * @desc Create a session cookie. 22 * @example $.cookie('the_cookie', null); 23 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain 24 * used when the cookie was set. 25 * 26 * @param String name The name of the cookie. 27 * @param String value The value of the cookie. 28 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. 29 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. 30 * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. 31 * If set to null or omitted, the cookie will be a session cookie and will not be retained 32 * when the the browser exits. 33 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). 34 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). 35 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will 36 * require a secure protocol (like HTTPS). 37 * @type undefined 38 * 39 * @name $.cookie 40 * @cat Plugins/Cookie 41 * @author Klaus Hartl/[email protected] 42 */ 43 44/** 45 * Get the value of a cookie with the given name. 46 * 47 * @example $.cookie('the_cookie'); 48 * @desc Get the value of a cookie. 49 * 50 * @param String name The name of the cookie. 51 * @return The value of the cookie. 52 * @type String 53 * 54 * @name $.cookie 55 * @cat Plugins/Cookie 56 * @author Klaus Hartl/[email protected] 57 */ 58(function ($) { 59 jQuery.cookie = function(name, value, options) { 60 if (typeof value != 'undefined') { // name and value given, set cookie 61 options = options || {}; 62 if (value === null) { 63 value = ''; 64 options.expires = -1; 65 } 66 var expires = ''; 67 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 68 var date; 69 if (typeof options.expires == 'number') { 70 date = new Date(); 71 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 72 } else { 73 date = options.expires; 74 } 75 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 76 } 77 // CAUTION: Needed to parenthesize options.path and options.domain 78 // in the following expressions, otherwise they evaluate to undefined 79 // in the packed version for some reason... 80 var path = options.path ? '; path=' + (options.path) : ''; 81 var domain = options.domain ? '; domain=' + (options.domain) : ''; 82 var secure = options.secure ? '; secure' : ''; 83 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 84 } else { // only name given, get cookie 85 var cookieValue = null; 86 if (document.cookie && document.cookie != '') { 87 var cookies = document.cookie.split(';'); 88 for (var i = 0; i < cookies.length; i++) { 89 var cookie = jQuery.trim(cookies[i]); 90 // Does this cookie string begin with the name we want? 91 if (cookie.substring(0, name.length + 1) == (name + '=')) { 92 cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 93 break; 94 } 95 } 96 } 97 return cookieValue; 98 } 99 }; 100})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.