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