2018-01-28 16:40:49 +00:00
|
|
|
/**
|
|
|
|
* Cookie plugin
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
|
|
|
* Dual licensed under the MIT and GPL licenses:
|
|
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
jQuery.cookie = function(name, value, options) {
|
|
|
|
if (typeof value != 'undefined') { // name and value given, set cookie
|
|
|
|
options = options || {};
|
|
|
|
if (value === null) {
|
|
|
|
value = '';
|
|
|
|
options.expires = -1;
|
|
|
|
}
|
2019-01-16 17:45:30 +00:00
|
|
|
let expires = '';
|
2018-01-28 16:40:49 +00:00
|
|
|
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
2019-01-16 17:45:30 +00:00
|
|
|
let date;
|
2018-01-28 16:40:49 +00:00
|
|
|
if (typeof options.expires == 'number') {
|
|
|
|
date = new Date();
|
|
|
|
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
|
|
|
} else {
|
|
|
|
date = options.expires;
|
|
|
|
}
|
|
|
|
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
|
|
|
}
|
|
|
|
// CAUTION: Needed to parenthesize options.path and options.domain
|
|
|
|
// in the following expressions, otherwise they evaluate to undefined
|
|
|
|
// in the packed version for some reason...
|
2019-01-16 17:45:30 +00:00
|
|
|
const path = options.path ? '; path=' + (options.path) : '';
|
|
|
|
const domain = options.domain ? '; domain=' + (options.domain) : '';
|
|
|
|
const secure = options.secure ? '; secure' : '';
|
2018-01-28 16:40:49 +00:00
|
|
|
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
|
|
|
} else { // only name given, get cookie
|
2019-01-16 17:45:30 +00:00
|
|
|
let cookieValue = null;
|
2018-01-28 16:40:49 +00:00
|
|
|
if (document.cookie && document.cookie != '') {
|
2019-01-16 17:45:30 +00:00
|
|
|
const cookies = document.cookie.split(';');
|
|
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
|
|
const cookie = jQuery.trim(cookies[i]);
|
2018-01-28 16:40:49 +00:00
|
|
|
// Does this cookie string begin with the name we want?
|
|
|
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
|
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cookieValue;
|
|
|
|
}
|
|
|
|
};
|