Path: blob/main/static/src/gs/public/hextris/vendor/js.cookie.js
1345 views
/*!1* JavaScript Cookie v2.0.0-pre2* https://github.com/js-cookie/js-cookie3*4* Copyright 2006, 2015 Klaus Hartl5* Released under the MIT license6*/7(function (factory) {8if (typeof define === 'function' && define.amd) {9define(factory);10} else if (typeof exports === 'object') {11module.exports = factory();12} else {13var _OldCookies = window.Cookies;14var api = window.Cookies = factory(window.jQuery);15api.noConflict = function () {16window.Cookies = _OldCookies;17return api;18};19}20}(function () {21function extend () {22var i = 0;23var result = {};24for (; i < arguments.length; i++) {25var attributes = arguments[ i ];26for (var key in attributes) {27result[key] = attributes[key];28}29}30return result;31}3233function init (converter) {34function api (key, value, attributes) {35var result;3637// Write3839if (arguments.length > 1) {40attributes = extend({41path: '/'42}, api.defaults, attributes);4344if (typeof attributes.expires === 'number') {45var expires = new Date();46expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);47attributes.expires = expires;48}4950try {51result = JSON.stringify(value);52if (/^[\{\[]/.test(result)) {53value = result;54}55} catch (e) {}5657value = encodeURIComponent(String(value));58value = value.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);5960key = encodeURIComponent(String(key));61key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);62key = key.replace(/[\(\)]/g, escape);6364return (document.cookie = [65key, '=', value,66attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE67attributes.path && '; path=' + attributes.path,68attributes.domain && '; domain=' + attributes.domain,69attributes.secure && '; secure'70].join(''));71}7273// Read7475if (!key) {76result = {};77}7879// To prevent the for loop in the first place assign an empty array80// in case there are no cookies at all. Also prevents odd result when81// calling "get()"82var cookies = document.cookie ? document.cookie.split('; ') : [];83var rdecode = /(%[0-9A-Z]{2})+/g;84var i = 0;8586for (; i < cookies.length; i++) {87var parts = cookies[i].split('=');88var name = parts[0].replace(rdecode, decodeURIComponent);89var cookie = parts.slice(1).join('=');9091if (cookie.charAt(0) === '"') {92cookie = cookie.slice(1, -1);93}9495cookie = converter && converter(cookie, name) || cookie.replace(rdecode, decodeURIComponent);9697if (this.json) {98try {99cookie = JSON.parse(cookie);100} catch (e) {}101}102103if (key === name) {104result = cookie;105break;106}107108if (!key) {109result[name] = cookie;110}111}112113return result;114}115116api.get = api.set = api;117api.getJSON = function () {118return api.apply({119json: true120}, [].slice.call(arguments));121};122api.defaults = {};123124api.remove = function (key, attributes) {125api(key, '', extend(attributes, {126expires: -1127}));128};129130api.withConverter = init;131132return api;133}134135return init();136}));137138139