| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 // $Id $ 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/klaus.hartl@stilbuero.de 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/klaus.hartl@stilbuero.de 57 */ 58 jQuery.cookie = function(name, value, options) { 59 if (typeof value != 'undefined') { // name and value given, set cookie 60 options = options || {}; 61 if (value === null) { 62 value = ''; 63 options.expires = -1; 64 } 65 var expires = ''; 66 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 67 var date; 68 if (typeof options.expires == 'number') { 69 date = new Date(); 70 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 71 } else { 72 date = options.expires; 73 } 74 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 75 } 76 // CAUTION: Needed to parenthesize options.path and options.domain 77 // in the following expressions, otherwise they evaluate to undefined 78 // in the packed version for some reason... 79 var path = options.path ? '; path=' + (options.path) : ''; 80 var domain = options.domain ? '; domain=' + (options.domain) : ''; 81 var secure = options.secure ? '; secure' : ''; 82 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 83 } else { // only name given, get cookie 84 var cookieValue = null; 85 if (document.cookie && document.cookie != '') { 86 var cookies = document.cookie.split(';'); 87 for (var i = 0; i < cookies.length; i++) { 88 var cookie = jQuery.trim(cookies[i]); 89 // Does this cookie string begin with the name we want? 90 if (cookie.substring(0, name.length + 1) == (name + '=')) { 91 cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 92 break; 93 } 94 } 95 } 96 return cookieValue; 97 } 98 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |