From: paladox Date: Mon, 21 Jul 2014 08:31:09 +0000 (+0000) Subject: Update jQuery Cookie to v1.3.1 X-Git-Tag: 1.31.0-rc.0~14716^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=23a4285be0e0d4c6b2a7fbff3d49f268b969a16d 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 --- diff --git a/RELEASE-NOTES-1.24 b/RELEASE-NOTES-1.24 index 119f1a24e4..647296c3dd 100644 --- a/RELEASE-NOTES-1.24 +++ b/RELEASE-NOTES-1.24 @@ -120,7 +120,7 @@ production. * (bug 67042) Added support for the HTML5 tag for East Asian typography. * Upgrade Sinon.JS to 1.10.3. * Added the es5-shim polyfill for older or non-compliant javascript engines. -* Upgrade jQuery Cookie to v1.2.0. +* Upgrade jQuery Cookie to v1.3.1. * (bug 20476) Add a "viewsuppressed" user right to be able to view suppressed content but not suppress it ("suppressrevision" right). * Added a new hook, "OutputPageScriptsForBottomQueue", to add modules to the diff --git a/resources/lib/jquery/jquery.cookie.js b/resources/lib/jquery/jquery.cookie.js index 95001fb0d4..3fb201c6a0 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; }