PageSourceSearch

https://portal.colocrossing.com/js/jquery.cookie.js

js colocrossing.com collected 2026-10-03 21:19:24 UTC 4,116 bytes, 104 lines download raw bytes

1/*jslint browser: true */ /*global jQuery: true */
2
3/**
4 * jQuery Cookie plugin
5 *
6 * Copyright (c) 2010 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// TODO JsDoc
14
15/**
16 * Create a cookie with the given key and value and other optional parameters.
17 *
18 * @example $.cookie('the_cookie', 'the_value');
19 * @desc Set the value of a cookie.
20 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
21 * @desc Create a cookie with all available options.
22 * @example $.cookie('the_cookie', 'the_value');
23 * @desc Create a session cookie.
24 * @example $.cookie('the_cookie', null);
25 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
26 *       used when the cookie was set.
27 *
28 * @param String key The key of the cookie.
29 * @param String value The value of the cookie.
30 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
31 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
32 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
33 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
34 *                             when the the browser exits.
35 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
36 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
37 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
38 *                        require a secure protocol (like HTTPS).
39 * @type undefined
40 *
41 * @name $.cookie
42 * @cat Plugins/Cookie
43 * @author Klaus Hartl/[email protected]
44 * 
45 * 
46 * @param String expires_type The type of expire number provided.  Either days (default) or minutes
47 * 
48 */
49
50/**
51 * Get the value of a cookie with the given key.
52 *
53 * @example $.cookie('the_cookie');
54 * @desc Get the value of a cookie.
55 *
56 * @param String key The key of the cookie.
57 * @return The value of the cookie.
58 * @type String
59 *
60 * @name $.cookie
61 * @cat Plugins/Cookie
62 * @author Klaus Hartl/[email protected]
63 */
64jQuery.cookie = function (key, value, options) {
65
66    // key and at least value given, set cookie...
67    if (arguments.length > 1 && String(value) !== "[object Object]") {
68        options = jQuery.extend({}, options);
69
70        if (value === null || value === undefined) {
71            options.expires = -1;
72        }
73
74        if (typeof options.expires === 'number') {
75            if(options.expires_type === null || options.expires_type === "days")
76            {
77                var days = options.expires, t = options.expires = new Date();
78                t.setDate(t.getDate() + days);
79            }
80            else
81            {
82                var minutes = options.expires, t = options.expires = new Date();
83                t.setMinutes(t.getMinutes() + minutes);
84            }
85            
86        }
87
88        value = String(value);
89
90        return (document.cookie = [
91            encodeURIComponent(key), '=',
92            options.raw ? value : encodeURIComponent(value),
93            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
94            options.path ? '; path=' + options.path : '',
95            options.domain ? '; domain=' + options.domain : '',
96            options.secure ? '; secure' : ''
97        ].join(''));
98    }
99
100    // key and possibly options given, get cookie...
101    options = value || {};
102    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
103    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
104};

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.