Update jquery.cookie

Created on 20 July 2015, over 9 years ago
Updated 18 August 2023, over 1 year ago

Per the discovery in #1857042: [jquery_update] 3rd party libraries β†’ , the current location of the jquery.cookie.js replacement file is replace/ui/external/jquery.cookie.js. I suspect that it was added there as part of the jQuery UI implementation ( #2534056: Remove unused and NON-MIT/GPL licensed or compatible code β†’ ).

It should really be it's own separately supported library replacement and updated to the latest supported version.

It appears that https://github.com/carhartl/jquery-cookie/ has moved to https://github.com/js-cookie/js-cookie/ and deducing from the following comment the last version that has jQuery support (which we'll need) is version 1.5.1: https://github.com/carhartl/jquery-cookie/issues/349#issuecomment-116822133

---

JS Cookie 2.0+ no longer has jQuery integration. Moving forward, we'll have to create our own jQuery wrapper that does essentially what was done in 1.5.1 with a little extra to provide BC support from the https://github.com/js-cookie/js-cookie/releases/tag/v2.0.0 changes:

/**
  * @file
  * Exposes Cookies to jQuery for backwards compatibility in Drupal.
  */
(function ($, Cookies, Drupal) {

  // Retrieve cookie settings.
  var settings = Drupal.settings.jquery_update && Drupal.settings.jquery_update.cookies || {
    // The js-cookie plugin broke BC, this setting adds expected behavior back in
    // based on https://github.com/js-cookie/js-cookie/releases/tag/v2.0.0
    backwardsCompatibility: true
  };

  // Handle raw values.
  var CookiesHandler = Cookies.withConverter(function(value) {
    if (settings.backwardsCompatibility && CookiesHandler.raw) {
      return value;
    }
  });

  // Let the default path be the current page.
  if (settings.backwardsCompatibility) {
    CookiesHandler.defaults.path = '';
  }

  // Expose to jQuery.
  $.cookie = CookiesHandler;

  // Return boolean if the cookie was removed.
  // @see https://github.com/carhartl/jquery-cookie/blob/master/src/jquery.cookie.js#L111
  if (settings.backwardsCompatibility) {
    $.removeCookie = function () {
      CookiesHandler.remove.apply(CookiesHandler, arguments);
      return CookiesHandler.get.apply(CookiesHandler, Array.prototype.slice.apply(arguments, [0, 1])) === void 0;
    };
  }
  else {
    $.removeCookie = CookiesHandler.remove;
  }

})(jQuery, Cookies, Drupal)
πŸ“Œ Task
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States markhalliwell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024