PageSourceSearch

https://www.0375123.com/template/pc/main/default/js/jquery.cookie.js

js 0375123.com collected 2026-10-09 04:38:06 UTC 4,245 bytes, 94 lines download raw bytes

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

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.