aboutsummaryrefslogtreecommitdiffstats
path: root/resources/lib/jquery/jquery.cookie.js
diff options
context:
space:
mode:
authorpaladox <thomasmulhall410@yahoo.com>2014-07-21 08:31:09 +0000
committerTimo Tijhof <krinklemail@gmail.com>2014-07-28 20:28:17 +0100
commit23a4285be0e0d4c6b2a7fbff3d49f268b969a16d (patch)
tree1eceefccef7c77fe26e8914b588f5cfa612c887f /resources/lib/jquery/jquery.cookie.js
parentd1d3d6087876f694450c75223dbb7308ca02d575 (diff)
downloadmediawikicore-23a4285be0e0d4c6b2a7fbff3d49f268b969a16d.tar.gz
mediawikicore-23a4285be0e0d4c6b2a7fbff3d49f268b969a16d.zip
Update jQuery Cookie to v1.3.1
Source * https://github.com/carhartl/jquery-cookie/blob/v1.3.1/jquery.cookie.js Change log * https://github.com/carhartl/jquery-cookie/blob/v1.3.1/CHANGELOG.md Notable changes: * Removed the "raw" option from $.cookie. This can now only be set globally via $.cookie.raw * Bugfix: Properly handle RFC 2068 quoted cookie values. * New: $.cookie() returns all available cookie. We should eventually upgrade to v1.4.1, but that has a breaking change. Namely, it drops support for $.cookie('key', null) which needs to be replaced by $.removeCookie which didn't exist until v1.2.0. Change-Id: Ic664dbe7b1be2c9dd67d0f50599c36fa2dab8449
Diffstat (limited to 'resources/lib/jquery/jquery.cookie.js')
-rw-r--r--resources/lib/jquery/jquery.cookie.js62
1 files changed, 40 insertions, 22 deletions
diff --git a/resources/lib/jquery/jquery.cookie.js b/resources/lib/jquery/jquery.cookie.js
index 95001fb0d4bc..3fb201c6a013 100644
--- a/resources/lib/jquery/jquery.cookie.js
+++ b/resources/lib/jquery/jquery.cookie.js
@@ -1,12 +1,9 @@
-/*jshint eqnull:true */
/*!
- * jQuery Cookie Plugin v1.2
+ * jQuery Cookie Plugin v1.3.1
* https://github.com/carhartl/jquery-cookie
*
- * Copyright 2011, Klaus Hartl
- * Dual licensed under the MIT or GPL Version 2 licenses.
- * http://www.opensource.org/licenses/mit-license.php
- * http://www.opensource.org/licenses/GPL-2.0
+ * Copyright 2013 Klaus Hartl
+ * Released under the MIT license
*/
(function ($, document, undefined) {
@@ -17,14 +14,26 @@
}
function decoded(s) {
- return decodeURIComponent(s.replace(pluses, ' '));
+ return unRfc2068(decodeURIComponent(s.replace(pluses, ' ')));
}
- $.cookie = function (key, value, options) {
+ function unRfc2068(value) {
+ if (value.indexOf('"') === 0) {
+ // This is a quoted cookie as according to RFC2068, unescape
+ value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+ }
+ return value;
+ }
+
+ function fromJSON(value) {
+ return config.json ? JSON.parse(value) : value;
+ }
- // key and at least value given, set cookie...
- if (value !== undefined && !/Object/.test(Object.prototype.toString.call(value))) {
- options = $.extend({}, $.cookie.defaults, options);
+ var config = $.cookie = function (key, value, options) {
+
+ // write
+ if (value !== undefined) {
+ options = $.extend({}, config.defaults, options);
if (value === null) {
options.expires = -1;
@@ -35,10 +44,10 @@
t.setDate(t.getDate() + days);
}
- value = String(value);
+ value = config.json ? JSON.stringify(value) : String(value);
return (document.cookie = [
- encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
@@ -46,23 +55,32 @@
].join(''));
}
- // key and possibly options given, get cookie...
- options = value || $.cookie.defaults || {};
- var decode = options.raw ? raw : decoded;
+ // read
+ var decode = config.raw ? raw : decoded;
var cookies = document.cookie.split('; ');
- for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
- if (decode(parts.shift()) === key) {
- return decode(parts.join('='));
+ var result = key ? null : {};
+ for (var i = 0, l = cookies.length; i < l; i++) {
+ var parts = cookies[i].split('=');
+ var name = decode(parts.shift());
+ var cookie = decode(parts.join('='));
+
+ if (key && key === name) {
+ result = fromJSON(cookie);
+ break;
+ }
+
+ if (!key) {
+ result[name] = fromJSON(cookie);
}
}
- return null;
+ return result;
};
- $.cookie.defaults = {};
+ config.defaults = {};
$.removeCookie = function (key, options) {
- if ($.cookie(key, options) !== null) {
+ if ($.cookie(key) !== null) {
$.cookie(key, null, options);
return true;
}