Update jQuery Cookie to v1.3.1
authorpaladox <thomasmulhall410@yahoo.com>
Mon, 21 Jul 2014 08:31:09 +0000 (08:31 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Mon, 28 Jul 2014 19:28:17 +0000 (20:28 +0100)
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

RELEASE-NOTES-1.24
resources/lib/jquery/jquery.cookie.js

index 119f1a2..647296c 100644 (file)
@@ -120,7 +120,7 @@ production.
 * (bug 67042) Added support for the HTML5 <rtc> 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
index 95001fb..3fb201c 100644 (file)
@@ -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) {
 
        }
 
        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;
                                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 : '',
                        ].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;
                }