ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

jquery.cookie.js
Go to the documentation of this file.
1
31 jQuery.cookie = function(name, value, options) {
32 if (typeof value != 'undefined') { // name and value given, set cookie
33 options = options || {};
34 if (value === null) {
35 value = '';
36 options.expires = -1;
37 }
38 var expires = '';
39 if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
40 var date;
41 if (typeof options.expires == 'number') {
42 date = new Date();
43 date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
44 } else {
45 date = options.expires;
46 }
47 expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
48 }
49 // CAUTION: Needed to parenthesize options.path and options.domain
50 // in the following expressions, otherwise they evaluate to undefined
51 // in the packed version for some reason...
52 var path = options.path ? '; path=' + (options.path) : '';
53 var domain = options.domain ? '; domain=' + (options.domain) : '';
54 var secure = options.secure ? '; secure' : '';
55 document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
56 } else { // only name given, get cookie
57 var cookieValue = null;
58 if (document.cookie && document.cookie != '') {
59 var cookies = document.cookie.split(';');
60 for (var i = 0; i < cookies.length; i++) {
61 var cookie = jQuery.trim(cookies[i]);
62 // Does this cookie string begin with the name we want?
63 if (cookie.substring(0, name.length + 1) == (name + '=')) {
64 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
65 break;
66 }
67 }
68 }
69 return cookieValue;
70 }
71 };