| 1 |
/*! |
| 2 |
* JavaScript Cookie v2.1.4 |
| 3 |
* https://github.com/js-cookie/js-cookie |
| 4 |
* |
| 5 |
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack |
| 6 |
* Released under the MIT license |
| 7 |
*/ |
| 8 |
;(function (factory) { |
| 9 |
var registeredInModuleLoader = false; |
| 10 |
if (typeof define === 'function' && define.amd) { |
| 11 |
define(factory); |
| 12 |
registeredInModuleLoader = true; |
| 13 |
} |
| 14 |
if (typeof exports === 'object') { |
| 15 |
module.exports = factory(); |
| 16 |
registeredInModuleLoader = true; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Customization for Charitable. |
| 21 |
* |
| 22 |
* @see https://github.com/Charitable/Charitable/issues/699 |
| 23 |
* @author David Bisset |
| 24 |
*/ |
| 25 |
registeredInModuleLoader = false; |
| 26 |
|
| 27 |
if (!registeredInModuleLoader) { |
| 28 |
var OldCookies = window.Cookies; |
| 29 |
var api = window.Cookies = factory(); |
| 30 |
api.noConflict = function () { |
| 31 |
window.Cookies = OldCookies; |
| 32 |
return api; |
| 33 |
}; |
| 34 |
} |
| 35 |
}(function () { |
| 36 |
function extend () { |
| 37 |
var i = 0; |
| 38 |
var result = {}; |
| 39 |
for (; i < arguments.length; i++) { |
| 40 |
var attributes = arguments[ i ]; |
| 41 |
for (var key in attributes) { |
| 42 |
result[key] = attributes[key]; |
| 43 |
} |
| 44 |
} |
| 45 |
return result; |
| 46 |
} |
| 47 |
|
| 48 |
function init (converter) { |
| 49 |
function api (key, value, attributes) { |
| 50 |
var result; |
| 51 |
if (typeof document === 'undefined') { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
// Write |
| 56 |
|
| 57 |
if (arguments.length > 1) { |
| 58 |
attributes = extend({ |
| 59 |
path: '/' |
| 60 |
}, api.defaults, attributes); |
| 61 |
|
| 62 |
if (typeof attributes.expires === 'number') { |
| 63 |
var expires = new Date(); |
| 64 |
expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5); |
| 65 |
attributes.expires = expires; |
| 66 |
} |
| 67 |
|
| 68 |
// We're using "expires" because "max-age" is not supported by IE |
| 69 |
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : ''; |
| 70 |
|
| 71 |
try { |
| 72 |
result = JSON.stringify(value); |
| 73 |
if (/^[\{\[]/.test(result)) { |
| 74 |
value = result; |
| 75 |
} |
| 76 |
} catch (e) {} |
| 77 |
|
| 78 |
if (!converter.write) { |
| 79 |
value = encodeURIComponent(String(value)) |
| 80 |
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent); |
| 81 |
} else { |
| 82 |
value = converter.write(value, key); |
| 83 |
} |
| 84 |
|
| 85 |
key = encodeURIComponent(String(key)); |
| 86 |
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent); |
| 87 |
key = key.replace(/[\(\)]/g, escape); |
| 88 |
|
| 89 |
var stringifiedAttributes = ''; |
| 90 |
|
| 91 |
for (var attributeName in attributes) { |
| 92 |
if (!attributes[attributeName]) { |
| 93 |
continue; |
| 94 |
} |
| 95 |
stringifiedAttributes += '; ' + attributeName; |
| 96 |
if (attributes[attributeName] === true) { |
| 97 |
continue; |
| 98 |
} |
| 99 |
stringifiedAttributes += '=' + attributes[attributeName]; |
| 100 |
} |
| 101 |
return (document.cookie = key + '=' + value + stringifiedAttributes); |
| 102 |
} |
| 103 |
|
| 104 |
// Read |
| 105 |
|
| 106 |
if (!key) { |
| 107 |
result = {}; |
| 108 |
} |
| 109 |
|
| 110 |
// To prevent the for loop in the first place assign an empty array |
| 111 |
// in case there are no cookies at all. Also prevents odd result when |
| 112 |
// calling "get()" |
| 113 |
var cookies = document.cookie ? document.cookie.split('; ') : []; |
| 114 |
var rdecode = /(%[0-9A-Z]{2})+/g; |
| 115 |
var i = 0; |
| 116 |
|
| 117 |
for (; i < cookies.length; i++) { |
| 118 |
var parts = cookies[i].split('='); |
| 119 |
var cookie = parts.slice(1).join('='); |
| 120 |
|
| 121 |
if (cookie.charAt(0) === '"') { |
| 122 |
cookie = cookie.slice(1, -1); |
| 123 |
} |
| 124 |
|
| 125 |
try { |
| 126 |
var name = parts[0].replace(rdecode, decodeURIComponent); |
| 127 |
cookie = converter.read ? |
| 128 |
converter.read(cookie, name) : converter(cookie, name) || |
| 129 |
cookie.replace(rdecode, decodeURIComponent); |
| 130 |
|
| 131 |
if (this.json) { |
| 132 |
try { |
| 133 |
cookie = JSON.parse(cookie); |
| 134 |
} catch (e) {} |
| 135 |
} |
| 136 |
|
| 137 |
if (key === name) { |
| 138 |
result = cookie; |
| 139 |
break; |
| 140 |
} |
| 141 |
|
| 142 |
if (!key) { |
| 143 |
result[name] = cookie; |
| 144 |
} |
| 145 |
} catch (e) {} |
| 146 |
} |
| 147 |
|
| 148 |
return result; |
| 149 |
} |
| 150 |
|
| 151 |
api.set = api; |
| 152 |
api.get = function (key) { |
| 153 |
return api.call(api, key); |
| 154 |
}; |
| 155 |
api.getJSON = function () { |
| 156 |
return api.apply({ |
| 157 |
json: true |
| 158 |
}, [].slice.call(arguments)); |
| 159 |
}; |
| 160 |
api.defaults = {}; |
| 161 |
|
| 162 |
api.remove = function (key, attributes) { |
| 163 |
api(key, '', extend(attributes, { |
| 164 |
expires: -1 |
| 165 |
})); |
| 166 |
}; |
| 167 |
|
| 168 |
api.withConverter = init; |
| 169 |
|
| 170 |
return api; |
| 171 |
} |
| 172 |
|
| 173 |
return init(function () {}); |
| 174 |
})); |