PageSourceSearch

https://fataoptkt.ru/g/libs/jquery-cookie/1.4.0/jquery.cookie.js

js fataoptkt.ru collected 2026-09-24 12:20:27 UTC 3,065 bytes, 113 lines download raw bytes

vendor: 3,065 bytes, lines 1-113
1/*!
2 * jQuery Cookie Plugin v1.4.0
3 * https://github.com/carhartl/jquery-cookie
4 *
5 * Copyright 2013 Klaus Hartl
6 * Released under the MIT license
7 */
8(function (factory) {
9	if (typeof define === 'function' && define.amd) {
10		// AMD. Register as anonymous module.
11		define(['jquery'], factory);
12	} else {
13		// Browser globals.
14		factory(jQuery);
15	}
16}(function ($) {
17
18	var pluses = /\+/g;
19
20	function encode(s) {
21		return config.raw ? s : encodeURIComponent(s);
22	}
23
24	function decode(s) {
25		return config.raw ? s : decodeURIComponent(s);
26	}
27
28	function stringifyCookieValue(value) {
29		return encode(config.json ? JSON.stringify(value) : String(value));
30	}
31
32	function parseCookieValue(s) {
33		if (s.indexOf('"') === 0) {
34			// This is a quoted cookie as according to RFC2068, unescape...
35			s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
36		}
37
38		try {
39			// Replace server-side written pluses with spaces.
40			// If we can't decode the cookie, ignore it, it's unusable.
41			// If we can't parse the cookie, ignore it, it's unusable.
42			s = decodeURIComponent(s.replace(pluses, ' '));
43			return config.json ? JSON.parse(s) : s;
44		} catch(e) {}
45	}
46
47	function read(s, converter) {
48		var value = config.raw ? s : parseCookieValue(s);
49		return $.isFunction(converter) ? converter(value) : value;
50	}
51
52	var config = $.cookie = function (key, value, options) {
53
54		// Write
55		if (value !== undefined && !$.isFunction(value)) {
56			options = $.extend({}, config.defaults, options);
57
58			if (typeof options.expires === 'number') {
59				var days = options.expires, t = options.expires = new Date();
60				t.setDate(t.getDate() + days);
61			}
62
63			return (document.cookie = [
64				encode(key), '=', stringifyCookieValue(value),
65				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
66				options.path    ? '; path=' + options.path : '',
67				options.domain  ? '; domain=' + options.domain : '',
68				options.secure  ? '; secure' : ''
69			].join(''));
70		}
71
72		// Read
73
74		var result = key ? undefined : {};
75
76		// To prevent the for loop in the first place assign an empty array
77		// in case there are no cookies at all. Also prevents odd result when
78		// calling $.cookie().
79		var cookies = document.cookie ? document.cookie.split('; ') : [];
80
81		for (var i = 0, l = cookies.length; i < l; i++) {
82			var parts = cookies[i].split('=');
83			var name = decode(parts.shift());
84			var cookie = parts.join('=');
85
86			if (key && key === name) {
87				// If second argument (value) is a function it's a converter...
88				result = read(cookie, value);
89				break;
90			}
91
92			// Prevent storing a cookie that we couldn't decode.
93			if (!key && (cookie = read(cookie)) !== undefined) {
94				result[name] = cookie;
95			}
96		}
97
98		return result;
99	};
100
101	config.defaults = {};
102
103	$.removeCookie = function (key, options) {
104		if ($.cookie(key) === undefined) {
105			return false;
106		}
107
108		// Must not alter options, thus extending a fresh object...
109		$.cookie(key, '', $.extend({}, options, { expires: -1 }));
110		return !$.cookie(key);
111	};
112
113}));

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.