Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
/ * *
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2022-03-04 13:17:47 +00:00
function ownKeys ( object , enumerableOnly ) { var keys = Object . keys ( object ) ; if ( Object . getOwnPropertySymbols ) { var symbols = Object . getOwnPropertySymbols ( object ) ; enumerableOnly && ( symbols = symbols . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( object , sym ) . enumerable ; } ) ) , keys . push . apply ( keys , symbols ) ; } return keys ; }
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
2022-03-04 13:17:47 +00:00
function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = null != arguments [ i ] ? arguments [ i ] : { } ; i % 2 ? ownKeys ( Object ( source ) , ! 0 ) . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) : Object . getOwnPropertyDescriptors ? Object . defineProperties ( target , Object . getOwnPropertyDescriptors ( source ) ) : ownKeys ( Object ( source ) ) . forEach ( function ( key ) { Object . defineProperty ( target , key , Object . getOwnPropertyDescriptor ( source , key ) ) ; } ) ; } return target ; }
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
( function ( $ , Drupal , cookies ) {
var deprecatedMessageSuffix = "is deprecated in Drupal 9.0.0 and will be removed in Drupal 10.0.0. Use the core/js-cookie library instead. See https://www.drupal.org/node/3104677" ;
var isFunction = function isFunction ( obj ) {
return Object . prototype . toString . call ( obj ) === '[object Function]' ;
} ;
2020-04-30 17:06:52 +00:00
var parseCookieValue = function parseCookieValue ( value , parseJson ) {
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
if ( value . indexOf ( '"' ) === 0 ) {
value = value . slice ( 1 , - 1 ) . replace ( /\\"/g , '"' ) . replace ( /\\\\/g , '\\' ) ;
}
2020-04-30 17:06:52 +00:00
try {
value = decodeURIComponent ( value . replace ( /\+/g , ' ' ) ) ;
return parseJson ? JSON . parse ( value ) : value ;
} catch ( e ) { }
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
} ;
2020-04-30 17:06:52 +00:00
var reader = function reader ( cookieValue , cookieName , converter , readUnsanitized , parseJson ) {
var value = readUnsanitized ? cookieValue : parseCookieValue ( cookieValue , parseJson ) ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
if ( converter !== undefined && isFunction ( converter ) ) {
return converter ( value , cookieName ) ;
}
return value ;
} ;
$ . cookie = function ( key ) {
var value = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : undefined ;
var options = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : undefined ;
Drupal . deprecationError ( {
message : "jQuery.cookie() " . concat ( deprecatedMessageSuffix )
} ) ;
2020-04-30 17:06:52 +00:00
key = key && ! $ . cookie . raw ? encodeURIComponent ( key ) : key ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
if ( value !== undefined && ! isFunction ( value ) ) {
2020-06-02 23:10:25 +00:00
var attributes = _objectSpread ( _objectSpread ( { } , $ . cookie . defaults ) , options ) ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
if ( typeof attributes . expires === 'string' && attributes . expires !== '' ) {
attributes . expires = new Date ( attributes . expires ) ;
}
var cookieSetter = cookies . withConverter ( {
write : function write ( cookieValue ) {
return encodeURIComponent ( cookieValue ) ;
}
} ) ;
2020-04-30 17:06:52 +00:00
value = $ . cookie . json && ! $ . cookie . raw ? JSON . stringify ( value ) : String ( value ) ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
return cookieSetter . set ( key , value , attributes ) ;
}
var userProvidedConverter = value ;
2020-04-30 17:06:52 +00:00
var cookiesShim = cookies . withConverter ( {
read : function read ( cookieValue , cookieName ) {
return reader ( cookieValue , cookieName , userProvidedConverter , $ . cookie . raw , $ . cookie . json ) ;
}
} ) ;
if ( key !== undefined ) {
return cookiesShim . get ( key ) ;
}
var results = cookiesShim . get ( ) ;
Object . keys ( results ) . forEach ( function ( resultKey ) {
if ( results [ resultKey ] === undefined ) {
delete results [ resultKey ] ;
}
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
} ) ;
2020-04-30 17:06:52 +00:00
return results ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
} ;
$ . cookie . defaults = _objectSpread ( {
path : ''
} , cookies . defaults ) ;
$ . cookie . json = false ;
$ . cookie . raw = false ;
$ . removeCookie = function ( key , options ) {
Drupal . deprecationError ( {
message : "jQuery.removeCookie() " . concat ( deprecatedMessageSuffix )
} ) ;
2020-06-02 23:10:25 +00:00
cookies . remove ( key , _objectSpread ( _objectSpread ( { } , $ . cookie . defaults ) , options ) ) ;
Issue #2550717 by mradcliffe, bnjmnm, finnsky, Manuel Garcia, lauriii, longwave, tedbow, silesky, catch, xjm, droplet, johndevman, nod_, marassa: [JS] Replace jQuery.cookie with JS-cookie and provide a BC layer
2020-03-13 20:00:18 +00:00
return ! cookies . get ( key ) ;
} ;
} ) ( jQuery , Drupal , window . Cookies ) ;