doevisualizations
Version:
Data Visualization Library based on RequireJS and D3.js (v4+)
66 lines (65 loc) • 2.33 kB
JavaScript
/*!
* jQuery++ - 2.0.2
* http://jquerypp.com
* Copyright (c) 2016 Bitovi
* Wed, 06 Apr 2016 00:03:57 GMT
* Licensed MIT
*/
/*jquerypp@2.0.2#dom/cookie/cookie*/
define(['jquery'], function ($) {
$.cookie = function (name, value, options) {
if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
if (typeof value == 'object' && JSON.stringify) {
value = JSON.stringify(value);
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
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();
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [
name,
'=',
encodeURIComponent(value),
expires,
path,
domain,
secure
].join('');
} else {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = $.trim(cookies[i]);
if (cookie.substring(0, name.length + 1) == name + '=') {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
if (cookieValue && cookieValue.match(/^\s*\{/)) {
try {
cookieValue = JSON.parse(cookieValue);
} catch (e) {
}
}
return cookieValue;
}
};
return $;
});