Merge pull request #967 from solgenomics/topic/expression_atlas_export
[sgn.git] / js / jquery / cookie.js
blobc4f99af00854e29666f9721b1d582d623fbfdafb
1 /*!
2 * jQuery Cookie Plugin v1.3.1
3 * https://github.com/carhartl/jquery-cookie
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);
16 }(function ($) {
18 var pluses = /\+/g;
20 function raw(s) {
21 return s;
24 function decoded(s) {
25 return decodeURIComponent(s.replace(pluses, ' '));
28 function converted(s) {
29 if (s.indexOf('"') === 0) {
30 // This is a quoted cookie as according to RFC2068, unescape
31 s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
33 try {
34 return config.json ? JSON.parse(s) : s;
35 } catch(er) {}
38 var config = $.cookie = function (key, value, options) {
40 // write
41 if (value !== undefined) {
42 options = $.extend({}, config.defaults, options);
44 if (typeof options.expires === 'number') {
45 var days = options.expires, t = options.expires = new Date();
46 t.setDate(t.getDate() + days);
49 value = config.json ? JSON.stringify(value) : String(value);
51 return (document.cookie = [
52 config.raw ? key : encodeURIComponent(key),
53 '=',
54 config.raw ? value : encodeURIComponent(value),
55 options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
56 options.path ? '; path=' + options.path : '',
57 options.domain ? '; domain=' + options.domain : '',
58 options.secure ? '; secure' : ''
59 ].join(''));
62 // read
63 var decode = config.raw ? raw : decoded;
64 var cookies = document.cookie.split('; ');
65 var result = key ? undefined : {};
66 for (var i = 0, l = cookies.length; i < l; i++) {
67 var parts = cookies[i].split('=');
68 var name = decode(parts.shift());
69 var cookie = decode(parts.join('='));
71 if (key && key === name) {
72 result = converted(cookie);
73 break;
76 if (!key) {
77 result[name] = converted(cookie);
81 return result;
84 config.defaults = {};
86 $.removeCookie = function (key, options) {
87 if ($.cookie(key) !== undefined) {
88 // Must not alter options, thus extending a fresh object...
89 $.cookie(key, '', $.extend({}, options, { expires: -1 }));
90 return true;
92 return false;
95 }));