PageSourceSearch

https://subscribe.nybooks.com/ecom/common/javascript/cookie.js

js nybooks.com collected 2026-10-01 08:43:18 UTC 1,795 bytes, 72 lines download raw bytes

1/*jshint eqnull:true */
2/*!
3* jQuery Cookie Plugin v1.2
4* https://github.com/carhartl/jquery-cookie
5*
6* Copyright 2011, Klaus Hartl
7* Dual licensed under the MIT or GPL Version 2 licenses.
8* http://www.opensource.org/licenses/mit-license.php
9* http://www.opensource.org/licenses/GPL-2.0
10*/
11(function ($, document, undefined) {
12
13var pluses = /\+/g;
14
15function raw(s) {
16return s;
17}
18
19function decoded(s) {
20return decodeURIComponent(s.replace(pluses, ' '));
21}
22
23var config = $.cookie = function (key, value, options) {
24
25// write
26if (value !== undefined) {
27options = $.extend({}, config.defaults, options);
28
29if (value === null) {
30options.expires = -1;
31}
32
33if (typeof options.expires === 'number') {
34var days = options.expires, t = options.expires = new Date();
35t.setDate(t.getDate() + days);
36}
37
38value = config.json ? JSON.stringify(value) : String(value);
39
40return (document.cookie = [
41encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
42options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
43options.path ? '; path=' + options.path : '',
44options.domain ? '; domain=' + options.domain : '',
45options.secure ? '; secure' : ''
46].join(''));
47}
48
49// read
50var decode = config.raw ? raw : decoded;
51var cookies = document.cookie.split('; ');
52for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
53if (decode(parts.shift()) === key) {
54var cookie = decode(parts.join('='));
55return config.json ? JSON.parse(cookie) : cookie;
56}
57}
58
59return null;
60};
61
62config.defaults = {};
63
64$.removeCookie = function (key, options) {
65if ($.cookie(key) !== null) {
66$.cookie(key, null, options);
67return true;
68}
69return false;
70};
71
72})(jQuery, document);

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.