Issue #3118726 by AndyF, lauriii, jungle, xjm, bnjmnm, catch, mradcliffe, effulgentsia: Upgrade to js.cookie 3
parent
2643ac4be3
commit
629abc963b
|
@ -1,3 +1,2 @@
|
|||
/*! js-cookie v2.2.1 | MIT */
|
||||
|
||||
!function(a){var b;if("function"==typeof define&&define.amd&&(define(a),b=!0),"object"==typeof exports&&(module.exports=a(),b=!0),!b){var c=window.Cookies,d=window.Cookies=a();d.noConflict=function(){return window.Cookies=c,d}}}(function(){function a(){for(var a=0,b={};a<arguments.length;a++){var c=arguments[a];for(var d in c)b[d]=c[d]}return b}function b(a){return a.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}function c(d){function e(){}function f(b,c,f){if("undefined"!=typeof document){f=a({path:"/"},e.defaults,f),"number"==typeof f.expires&&(f.expires=new Date(1*new Date+864e5*f.expires)),f.expires=f.expires?f.expires.toUTCString():"";try{var g=JSON.stringify(c);/^[\{\[]/.test(g)&&(c=g)}catch(j){}c=d.write?d.write(c,b):encodeURIComponent(c+"").replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),b=encodeURIComponent(b+"").replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var h="";for(var i in f)f[i]&&(h+="; "+i,!0!==f[i]&&(h+="="+f[i].split(";")[0]));return document.cookie=b+"="+c+h}}function g(a,c){if("undefined"!=typeof document){for(var e={},f=document.cookie?document.cookie.split("; "):[],g=0;g<f.length;g++){var h=f[g].split("="),i=h.slice(1).join("=");c||'"'!==i.charAt(0)||(i=i.slice(1,-1));try{var j=b(h[0]);if(i=(d.read||d)(i,j)||b(i),c)try{i=JSON.parse(i)}catch(k){}if(e[j]=i,a===j)break}catch(k){}}return a?e[a]:e}}return e.set=f,e.get=function(a){return g(a,!1)},e.getJSON=function(a){return g(a,!0)},e.remove=function(b,c){f(b,"",a(c,{expires:-1}))},e.defaults={},e.withConverter=c,e}return c(function(){})});
|
||||
/*! js-cookie v3.0.0-rc.0 | MIT */
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var r=e.Cookies,n=e.Cookies=t();n.noConflict=function(){return e.Cookies=r,n}}())}(this,function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var t={read:function(e){return e.replace(/%3B/g,";")},write:function(e){return e.replace(/;/g,"%3B")}};return function r(n,i){function o(r,o,u){if("undefined"!=typeof document){"number"==typeof(u=e({},i,u)).expires&&(u.expires=new Date(Date.now()+864e5*u.expires)),u.expires&&(u.expires=u.expires.toUTCString()),r=t.write(r).replace(/=/g,"%3D"),o=n.write(String(o),r);var c="";for(var f in u)u[f]&&(c+="; "+f,!0!==u[f]&&(c+="="+u[f].split(";")[0]));return document.cookie=r+"="+o+c}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],i={},o=0;o<r.length;o++){var u=r[o].split("="),c=u.slice(1).join("="),f=t.read(u[0]).replace(/%3D/g,"=");if(i[f]=n.read(c,f),e===f)break}return e?i[e]:i}},remove:function(t,r){o(t,"",e({},r,{expires:-1}))},withAttributes:function(t){return r(this.converter,e({},this.attributes,t))},withConverter:function(t){return r(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(i)},converter:{value:Object.freeze(n)}})}(t,{path:"/"})});
|
||||
|
|
|
@ -659,10 +659,10 @@ drupal.dialog.off_canvas:
|
|||
|
||||
js-cookie:
|
||||
remote: https://github.com/js-cookie/js-cookie
|
||||
version: "v2.2.1"
|
||||
version: "v3.0.0-rc0"
|
||||
license:
|
||||
name: MIT
|
||||
url: https://github.com/js-cookie/js-cookie/blob/v2.2.1/MIT-LICENSE.txt
|
||||
url: https://github.com/js-cookie/js-cookie/blob/v3.0.0-rc.0/LICENSE
|
||||
gpl-compatible: true
|
||||
js:
|
||||
assets/vendor/js-cookie/js.cookie.min.js: {}
|
||||
|
|
|
@ -31,18 +31,26 @@
|
|||
*
|
||||
* @param {string} value
|
||||
* The cookie value to parse.
|
||||
* @param {boolean} parseJson
|
||||
* Whether cookie value should be parsed from JSON.
|
||||
*
|
||||
* @return {string}
|
||||
* The cookie value for the reader to return.
|
||||
*/
|
||||
const parseCookieValue = value => {
|
||||
const parseCookieValue = (value, parseJson) => {
|
||||
if (value.indexOf('"') === 0) {
|
||||
value = value
|
||||
.slice(1, -1)
|
||||
.replace(/\\"/g, '"')
|
||||
.replace(/\\\\/g, '\\');
|
||||
}
|
||||
return decodeURIComponent(value.replace(/\+/g, ' '));
|
||||
|
||||
try {
|
||||
value = decodeURIComponent(value.replace(/\+/g, ' '));
|
||||
return parseJson ? JSON.parse(value) : value;
|
||||
} catch (e) {
|
||||
// Exceptions on JSON parsing should be ignored.
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -60,16 +68,27 @@
|
|||
* A function that takes the cookie value for further processing.
|
||||
* @param {boolean} readUnsanitized
|
||||
* Uses the unsanitized value when set to true.
|
||||
* @param {boolean} parseJson
|
||||
* Whether cookie value should be parsed from JSON.
|
||||
*
|
||||
* @return {string}
|
||||
* The cookie value that js-cookie will return.
|
||||
*/
|
||||
const reader = (cookieValue, cookieName, converter, readUnsanitized) => {
|
||||
const value = readUnsanitized ? cookieValue : parseCookieValue(cookieValue);
|
||||
const reader = (
|
||||
cookieValue,
|
||||
cookieName,
|
||||
converter,
|
||||
readUnsanitized,
|
||||
parseJson,
|
||||
) => {
|
||||
const value = readUnsanitized
|
||||
? cookieValue
|
||||
: parseCookieValue(cookieValue, parseJson);
|
||||
|
||||
if (converter !== undefined && isFunction(converter)) {
|
||||
return converter(value, cookieName);
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
|
@ -111,26 +130,19 @@
|
|||
* Use the core/js-cookie library instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3104677
|
||||
* @see https://github.com/js-cookie/js-cookie/blob/v2.2.1/README.md
|
||||
* @see https://github.com/js-cookie/js-cookie/blob/v3.0.0-rc.0/README.md
|
||||
*/
|
||||
$.cookie = (key, value = undefined, options = undefined) => {
|
||||
Drupal.deprecationError({
|
||||
message: `jQuery.cookie() ${deprecatedMessageSuffix}`,
|
||||
});
|
||||
// Key should be only encoded if it exists and when not in a raw mode.
|
||||
key = key && !$.cookie.raw ? encodeURIComponent(key) : key;
|
||||
if (value !== undefined && !isFunction(value)) {
|
||||
// The caller is setting a cookie value and not trying to retrieve the
|
||||
// cookie value using a converter callback.
|
||||
const attributes = { ...$.cookie.defaults, ...options };
|
||||
|
||||
if (!$.cookie.json) {
|
||||
// An object that is passed in must be typecast to a string when the
|
||||
// "json" option is not set because js-cookie will always stringify
|
||||
// JSON cookie values.
|
||||
value = String(value);
|
||||
}
|
||||
|
||||
// If the expires value is a non-empty string, it needs to be converted
|
||||
// to a Date() object before being sent to js-cookie.
|
||||
if (typeof attributes.expires === 'string' && attributes.expires !== '') {
|
||||
attributes.expires = new Date(attributes.expires);
|
||||
}
|
||||
|
@ -139,6 +151,9 @@
|
|||
write: cookieValue => encodeURIComponent(cookieValue),
|
||||
});
|
||||
|
||||
value =
|
||||
$.cookie.json && !$.cookie.raw ? JSON.stringify(value) : String(value);
|
||||
|
||||
return cookieSetter.set(key, value, attributes);
|
||||
}
|
||||
|
||||
|
@ -146,13 +161,29 @@
|
|||
// which has security implications, but remains in place for
|
||||
// backwards-compatibility.
|
||||
const userProvidedConverter = value;
|
||||
const cookiesShim = cookies.withConverter((cookieValue, cookieName) =>
|
||||
reader(cookieValue, cookieName, userProvidedConverter, $.cookie.raw),
|
||||
);
|
||||
const cookiesShim = cookies.withConverter({
|
||||
read: (cookieValue, cookieName) =>
|
||||
reader(
|
||||
cookieValue,
|
||||
cookieName,
|
||||
userProvidedConverter,
|
||||
$.cookie.raw,
|
||||
$.cookie.json,
|
||||
),
|
||||
});
|
||||
|
||||
return $.cookie.json === true
|
||||
? cookiesShim.getJSON(key)
|
||||
: cookiesShim.get(key);
|
||||
if (key !== undefined) {
|
||||
return cookiesShim.get(key);
|
||||
}
|
||||
|
||||
const results = cookiesShim.get();
|
||||
Object.keys(results).forEach(resultKey => {
|
||||
if (results[resultKey] === undefined) {
|
||||
delete results[resultKey];
|
||||
}
|
||||
});
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -195,7 +226,7 @@
|
|||
* Use the core/js-cookie library instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3104677
|
||||
* @see https://github.com/js-cookie/js-cookie/blob/v2.2.1/README.md
|
||||
* @see https://github.com/js-cookie/js-cookie/blob/v3.0.0-rc.0/README.md
|
||||
*/
|
||||
$.removeCookie = (key, options) => {
|
||||
Drupal.deprecationError({
|
||||
|
|
|
@ -18,16 +18,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|||
return Object.prototype.toString.call(obj) === '[object Function]';
|
||||
};
|
||||
|
||||
var parseCookieValue = function parseCookieValue(value) {
|
||||
var parseCookieValue = function parseCookieValue(value, parseJson) {
|
||||
if (value.indexOf('"') === 0) {
|
||||
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
||||
}
|
||||
|
||||
return decodeURIComponent(value.replace(/\+/g, ' '));
|
||||
try {
|
||||
value = decodeURIComponent(value.replace(/\+/g, ' '));
|
||||
return parseJson ? JSON.parse(value) : value;
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
var reader = function reader(cookieValue, cookieName, converter, readUnsanitized) {
|
||||
var value = readUnsanitized ? cookieValue : parseCookieValue(cookieValue);
|
||||
var reader = function reader(cookieValue, cookieName, converter, readUnsanitized, parseJson) {
|
||||
var value = readUnsanitized ? cookieValue : parseCookieValue(cookieValue, parseJson);
|
||||
|
||||
if (converter !== undefined && isFunction(converter)) {
|
||||
return converter(value, cookieName);
|
||||
|
@ -42,14 +45,11 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|||
Drupal.deprecationError({
|
||||
message: "jQuery.cookie() ".concat(deprecatedMessageSuffix)
|
||||
});
|
||||
key = key && !$.cookie.raw ? encodeURIComponent(key) : key;
|
||||
|
||||
if (value !== undefined && !isFunction(value)) {
|
||||
var attributes = _objectSpread({}, $.cookie.defaults, {}, options);
|
||||
|
||||
if (!$.cookie.json) {
|
||||
value = String(value);
|
||||
}
|
||||
|
||||
if (typeof attributes.expires === 'string' && attributes.expires !== '') {
|
||||
attributes.expires = new Date(attributes.expires);
|
||||
}
|
||||
|
@ -59,14 +59,28 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|||
return encodeURIComponent(cookieValue);
|
||||
}
|
||||
});
|
||||
value = $.cookie.json && !$.cookie.raw ? JSON.stringify(value) : String(value);
|
||||
return cookieSetter.set(key, value, attributes);
|
||||
}
|
||||
|
||||
var userProvidedConverter = value;
|
||||
var cookiesShim = cookies.withConverter(function (cookieValue, cookieName) {
|
||||
return reader(cookieValue, cookieName, userProvidedConverter, $.cookie.raw);
|
||||
var cookiesShim = cookies.withConverter({
|
||||
read: function read(cookieValue, cookieName) {
|
||||
return reader(cookieValue, cookieName, userProvidedConverter, $.cookie.raw, $.cookie.json);
|
||||
}
|
||||
});
|
||||
return $.cookie.json === true ? cookiesShim.getJSON(key) : cookiesShim.get(key);
|
||||
|
||||
if (key !== undefined) {
|
||||
return cookiesShim.get(key);
|
||||
}
|
||||
|
||||
var results = cookiesShim.get();
|
||||
Object.keys(results).forEach(function (resultKey) {
|
||||
if (results[resultKey] === undefined) {
|
||||
delete results[resultKey];
|
||||
}
|
||||
});
|
||||
return results;
|
||||
};
|
||||
|
||||
$.cookie.defaults = _objectSpread({
|
||||
|
|
Loading…
Reference in New Issue