From: Tom Hughes Date: Thu, 6 Aug 2020 18:27:58 +0000 (+0100) Subject: Move jquery.cookie to be a yarn managed asset X-Git-Tag: live~2514 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/447c05fcb8e306b1be53b4108f816ac8d5663324 Move jquery.cookie to be a yarn managed asset --- diff --git a/Vendorfile b/Vendorfile index 858870145..d00557322 100644 --- a/Vendorfile +++ b/Vendorfile @@ -1,6 +1,5 @@ folder 'vendor/assets' do folder 'jquery' do - file 'jquery.cookie.js', 'https://raw.githubusercontent.com/carhartl/jquery-cookie/master/src/jquery.cookie.js' file 'jquery.throttle-debounce.js', 'https://raw.githubusercontent.com/cowboy/jquery-throttle-debounce/v1.1/jquery.ba-throttle-debounce.js' end diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4f52d08cd..d18ece0b1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -1,7 +1,7 @@ //= require jquery3 //= require jquery_ujs //= require jquery.timers -//= require jquery.cookie +//= require jquery.cookie/jquery.cookie //= require jquery.throttle-debounce //= require popper //= require bootstrap-sprockets diff --git a/package.json b/package.json index 4c1c823dc..39f39fad4 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "bs-custom-file-input": "^1.3.4", "html5shiv": "^3.7.3", "jquery-simulate": "^1.0.2", + "jquery.cookie": "^1.4.1", "leaflet": "^1.6.0", "leaflet.locatecontrol": "^0.71.1", "ohauth": "^0.2.2" diff --git a/test/javascripts/osm_test.js b/test/javascripts/osm_test.js index 991885758..83e750197 100644 --- a/test/javascripts/osm_test.js +++ b/test/javascripts/osm_test.js @@ -1,5 +1,5 @@ //= require jquery -//= require jquery.cookie +//= require jquery.cookie/jquery.cookie //= require osm //= require leaflet/dist/leaflet-src //= require leaflet.osm diff --git a/vendor/assets/jquery/jquery.cookie.js b/vendor/assets/jquery/jquery.cookie.js deleted file mode 100644 index 8218817b9..000000000 --- a/vendor/assets/jquery/jquery.cookie.js +++ /dev/null @@ -1,114 +0,0 @@ -/*! - * jQuery Cookie Plugin v1.4.1 - * https://github.com/carhartl/jquery-cookie - * - * Copyright 2006, 2014 Klaus Hartl - * Released under the MIT license - */ -(function (factory) { - if (typeof define === 'function' && define.amd) { - // AMD (Register as an anonymous module) - define(['jquery'], factory); - } else if (typeof exports === 'object') { - // Node/CommonJS - module.exports = factory(require('jquery')); - } else { - // Browser globals - factory(jQuery); - } -}(function ($) { - - var pluses = /\+/g; - - function encode(s) { - return config.raw ? s : encodeURIComponent(s); - } - - function decode(s) { - return config.raw ? s : decodeURIComponent(s); - } - - function stringifyCookieValue(value) { - return encode(config.json ? JSON.stringify(value) : String(value)); - } - - function parseCookieValue(s) { - if (s.indexOf('"') === 0) { - // This is a quoted cookie as according to RFC2068, unescape... - s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); - } - - try { - // Replace server-side written pluses with spaces. - // If we can't decode the cookie, ignore it, it's unusable. - // If we can't parse the cookie, ignore it, it's unusable. - s = decodeURIComponent(s.replace(pluses, ' ')); - return config.json ? JSON.parse(s) : s; - } catch(e) {} - } - - function read(s, converter) { - var value = config.raw ? s : parseCookieValue(s); - return $.isFunction(converter) ? converter(value) : value; - } - - var config = $.cookie = function (key, value, options) { - - // Write - - if (arguments.length > 1 && !$.isFunction(value)) { - options = $.extend({}, config.defaults, options); - - if (typeof options.expires === 'number') { - var days = options.expires, t = options.expires = new Date(); - t.setMilliseconds(t.getMilliseconds() + days * 864e+5); - } - - return (document.cookie = [ - encode(key), '=', stringifyCookieValue(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 : '', - options.secure ? '; secure' : '' - ].join('')); - } - - // Read - - var result = key ? undefined : {}, - // To prevent the for loop in the first place assign an empty array - // in case there are no cookies at all. Also prevents odd result when - // calling $.cookie(). - cookies = document.cookie ? document.cookie.split('; ') : [], - i = 0, - l = cookies.length; - - for (; i < l; i++) { - var parts = cookies[i].split('='), - name = decode(parts.shift()), - cookie = parts.join('='); - - if (key === name) { - // If second argument (value) is a function it's a converter... - result = read(cookie, value); - break; - } - - // Prevent storing a cookie that we couldn't decode. - if (!key && (cookie = read(cookie)) !== undefined) { - result[name] = cookie; - } - } - - return result; - }; - - config.defaults = {}; - - $.removeCookie = function (key, options) { - // Must not alter options, thus extending a fresh object... - $.cookie(key, '', $.extend({}, options, { expires: -1 })); - return !$.cookie(key); - }; - -})); diff --git a/yarn.lock b/yarn.lock index f2d12886a..6529c1b34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -449,6 +449,11 @@ jquery-simulate@^1.0.2: resolved "https://registry.yarnpkg.com/jquery-simulate/-/jquery-simulate-1.0.2.tgz#2174b859b75123a0ac6d8ab3a9a6fb4ad7e82898" integrity sha512-Bq610fSrwTwvH5d06z5oskYaX/79s0BNrKiJZjZOiXRib3iL4ZkSn/wvLwzhf3P9KeXCEpk9wlIaGui/1arOpQ== +jquery.cookie@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/jquery.cookie/-/jquery.cookie-1.4.1.tgz#d63dce209eab691fe63316db08ca9e47e0f9385b" + integrity sha1-1j3OIJ6raR/mMxbbCMqeR+D5OFs= + js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"