1// TODO: Investigate replacing this with js-cookie module and referencing from confluence/api/cookie 2/** 3 * Cookie plugin 4 * 5 * Copyright (c) 2006 Klaus Hartl (stilbuero.de) 6 * Dual licensed under the MIT and GPL licenses: 7 * http://www.opensource.org/licenses/mit-license.php 8 * http://www.gnu.org/licenses/gpl.html 9 * 10 */ 11 12/** 13 * Create a cookie with the given name and value and other optional parameters. 14 * 15 * @example $.cookie('the_cookie', 'the_value'); 16 * @desc Set the value of a cookie. 17 * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true}); 18 * @desc Create a cookie with all available options. 19 * @example $.cookie('the_cookie', 'the_value'); 20 * @desc Create a session cookie. 21 * @example $.cookie('the_cookie', null); 22 * @desc Delete a cookie by passing null as value. 23 * 24 * @param String name The name of the cookie. 25 * @param String value The value of the cookie. 26 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. 27 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. 28 * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. 29 * If set to null or omitted, the cookie will be a session cookie and will not be retained 30 * when the the browser exits. 31 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). 32 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). 33 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will 34 * require a secure protocol (like HTTPS). 35 * @type undefined 36 * 37 * @name $.cookie 38 * @cat Plugins/Cookie 39 * @author Klaus Hartl/[email protected] 40 */ 41 42/** 43 * Get the value of a cookie with the given name. 44 * 45 * @example $.cookie('the_cookie'); 46 * @desc Get the value of a cookie. 47 * 48 * @param String name The name of the cookie. 49 * @return The value of the cookie. 50 * @type String 51 * 52 * @name $.cookie 53 * @cat Plugins/Cookie 54 * @author Klaus Hartl/[email protected] 55 */ 56jQuery.cookie = function(name, value, options) { 57 if (typeof value != 'undefined') { // name and value given, set cookie 58 options = options || {}; 59 if (value === null) { 60 value = ''; 61 options.expires = -1; 62 } 63 var expires = ''; 64 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { 65 var date; 66 if (typeof options.expires == 'number') { 67 date = new Date(); 68 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); 69 } else { 70 date = options.expires; 71 } 72 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE 73 } 74 var path = options.path ? '; path=' + options.path : ''; 75 var domain = options.domain ? '; domain=' + options.domain : ''; 76 var secure = options.secure ? '; secure' : ''; 77 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); 78 } else { // only name given, get cookie 79 var cookieValue = null; 80 if (document.cookie && document.cookie != '') { 81 var cookies = document.cookie.split(';'); 82 for (var i = 0; i < cookies.length; i++) { 83 var cookie = jQuery.trim(cookies[i]); 84 // Does this cookie string begin with the name we want? 85 if (cookie.substring(0, name.length + 1) == (name + '=')) { 86 cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); 87 break; 88 } 89 } 90 } 91 return cookieValue; 92 } 93};
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.