share/views/public/plugins/js-cookie/js/js.cookie.js in rbbt-rest-1.8.140 vs share/views/public/plugins/js-cookie/js/js.cookie.js in rbbt-rest-1.8.142
- old
+ new
@@ -1,22 +1,27 @@
/*!
- * JavaScript Cookie v2.1.0
+ * JavaScript Cookie v2.2.1
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/
-(function (factory) {
+;(function (factory) {
+ var registeredInModuleLoader;
if (typeof define === 'function' && define.amd) {
define(factory);
- } else if (typeof exports === 'object') {
+ registeredInModuleLoader = true;
+ }
+ if (typeof exports === 'object') {
module.exports = factory();
- } else {
- var _OldCookies = window.Cookies;
+ registeredInModuleLoader = true;
+ }
+ if (!registeredInModuleLoader) {
+ var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
- window.Cookies = _OldCookies;
+ window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
@@ -29,113 +34,126 @@
}
}
return result;
}
+ function decode (s) {
+ return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
+ }
+
function init (converter) {
- function api (key, value, attributes) {
- var result;
+ function api() {}
- // Write
+ function set (key, value, attributes) {
+ if (typeof document === 'undefined') {
+ return;
+ }
- if (arguments.length > 1) {
- attributes = extend({
- path: '/'
- }, api.defaults, attributes);
+ attributes = extend({
+ path: '/'
+ }, api.defaults, attributes);
- if (typeof attributes.expires === 'number') {
- var expires = new Date();
- expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
- attributes.expires = expires;
- }
+ if (typeof attributes.expires === 'number') {
+ attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
+ }
- try {
- result = JSON.stringify(value);
- if (/^[\{\[]/.test(result)) {
- value = result;
- }
- } catch (e) {}
+ // We're using "expires" because "max-age" is not supported by IE
+ attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
- if (!converter.write) {
- value = encodeURIComponent(String(value))
- .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
- } else {
- value = converter.write(value, key);
+ try {
+ var result = JSON.stringify(value);
+ if (/^[\{\[]/.test(result)) {
+ value = result;
}
+ } catch (e) {}
- key = encodeURIComponent(String(key));
- key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
- key = key.replace(/[\(\)]/g, escape);
+ value = converter.write ?
+ converter.write(value, key) :
+ encodeURIComponent(String(value))
+ .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
- return (document.cookie = [
- key, '=', value,
- attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
- attributes.path && '; path=' + attributes.path,
- attributes.domain && '; domain=' + attributes.domain,
- attributes.secure ? '; secure' : ''
- ].join(''));
+ key = encodeURIComponent(String(key))
+ .replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
+ .replace(/[\(\)]/g, escape);
+
+ var stringifiedAttributes = '';
+ for (var attributeName in attributes) {
+ if (!attributes[attributeName]) {
+ continue;
+ }
+ stringifiedAttributes += '; ' + attributeName;
+ if (attributes[attributeName] === true) {
+ continue;
+ }
+
+ // Considers RFC 6265 section 5.2:
+ // ...
+ // 3. If the remaining unparsed-attributes contains a %x3B (";")
+ // character:
+ // Consume the characters of the unparsed-attributes up to,
+ // not including, the first %x3B (";") character.
+ // ...
+ stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}
- // Read
+ return (document.cookie = key + '=' + value + stringifiedAttributes);
+ }
- if (!key) {
- result = {};
+ function get (key, json) {
+ if (typeof document === 'undefined') {
+ return;
}
+ var jar = {};
// To prevent the for loop in the first place assign an empty array
- // in case there are no cookies at all. Also prevents odd result when
- // calling "get()"
+ // in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
- var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
- var name = parts[0].replace(rdecode, decodeURIComponent);
var cookie = parts.slice(1).join('=');
- if (cookie.charAt(0) === '"') {
+ if (!json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
- cookie = converter.read ?
- converter.read(cookie, name) : converter(cookie, name) ||
- cookie.replace(rdecode, decodeURIComponent);
+ var name = decode(parts[0]);
+ cookie = (converter.read || converter)(cookie, name) ||
+ decode(cookie);
- if (this.json) {
+ if (json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
+ jar[name] = cookie;
+
if (key === name) {
- result = cookie;
break;
}
-
- if (!key) {
- result[name] = cookie;
- }
} catch (e) {}
}
- return result;
+ return key ? jar[key] : jar;
}
- api.get = api.set = api;
- api.getJSON = function () {
- return api.apply({
- json: true
- }, [].slice.call(arguments));
+ api.set = set;
+ api.get = function (key) {
+ return get(key, false /* read as raw */);
};
- api.defaults = {};
-
+ api.getJSON = function (key) {
+ return get(key, true /* read as json */);
+ };
api.remove = function (key, attributes) {
- api(key, '', extend(attributes, {
+ set(key, '', extend(attributes, {
expires: -1
}));
};
+
+ api.defaults = {};
api.withConverter = init;
return api;
}