Bugzilla – Attachment 129749 Details for
Bug 29940
Phase out jquery.cookie.js in the OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29940: Phase out jquery.cookie.js in the OPAC
Bug-29940-Phase-out-jquerycookiejs-in-the-OPAC.patch (text/plain), 14.18 KB, created by
Owen Leonard
on 2022-01-25 13:10:53 UTC
(
hide
)
Description:
Bug 29940: Phase out jquery.cookie.js in the OPAC
Filename:
MIME Type:
Creator:
Owen Leonard
Created:
2022-01-25 13:10:53 UTC
Size:
14.18 KB
patch
obsolete
>From b501626bca6f366115c2e7c99ba58fc97ffc6863 Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Tue, 25 Jan 2022 12:32:28 +0000 >Subject: [PATCH] Bug 29940: Phase out jquery.cookie.js in the OPAC > >This patch replaces the use of jquery.cookie.js in the OPAC with the >newer js-cookie plugin. The patch adds the latest version of the >js-cookie library and removes the old jquery.cookie plugin. > >To test, apply the patch and go to the advanced search page in the OPAC. > >- Perform a search using a number of different limits and settings, e.g. > keyword, item type, and sort-by. >- On the search results page you should see at the top of the results > list a link to "Return to the last advanced search." >- The link should take you back to the advanced search page with all the > same settings filled into the form. >- A search with the "More options" view enabled in the advanced search > form should result in a link which returns to the "More options" view. >- Searching via the "quick search" form at the top of the page should > clear the cookies which were set in order to remember the advanced > search. See > https://developer.mozilla.org/en-US/docs/Tools/Storage_Inspector for > information on viewing your browser's stored cookies. >--- > .../bootstrap/en/includes/opac-bottom.inc | 8 +- > .../bootstrap/en/modules/opac-advsearch.tt | 20 ++- > .../lib/jquery/plugins/jquery.cookie.min.js | 2 - > .../lib/js-cookie/js.cookie-3.0.1.js | 147 ++++++++++++++++++ > .../lib/js-cookie/js.cookie-3.0.1.min.js | 2 + > 5 files changed, 162 insertions(+), 17 deletions(-) > delete mode 100644 koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js > create mode 100644 koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.js > create mode 100644 koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.min.js > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >index e4aaccf54a..963b7df1ce 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc >@@ -295,14 +295,14 @@ $.widget.bridge('uitooltip', $.ui.tooltip); > </script> > [% END %] > >-[% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %] >+[% Asset.js("lib/js-cookie/js.cookie-3.0.1.min.js") | $raw %] > <script> > $(document).ready(function() { > if($('#searchsubmit').length) { > $(document).on("click", '#searchsubmit', function(e) { >- jQuery.removeCookie("form_serialized", { path: '/'}); >- jQuery.removeCookie("form_serialized_limits", { path: '/'}); >- jQuery.removeCookie("search_path_code", { path: '/'}); >+ Cookies.remove("form_serialized", { path: '/'}); >+ Cookies.remove("form_serialized_limits", { path: '/'}); >+ Cookies.remove("search_path_code", { path: '/'}); > }); > } > }); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt >index b4ac896084..9c84490325 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt >@@ -449,7 +449,6 @@ > > [% BLOCK jsinclude %] > [% Asset.js("lib/jquery/plugins/jquery.deserialize.min.js") | $raw %] >-[% Asset.js("lib/jquery/plugins/jquery.cookie.min.js") | $raw %] > <script> > $(document).ready(function() { > [% IF search_groups %] >@@ -472,12 +471,11 @@ $(document).ready(function() { > [% END %] > > $('#advsearches').tabs(); >- jQuery.cookie.json = true; > > $('.search-term-row .search-term-input select[name="op"]').first().prop("disabled",true).hide(); > > [% IF ( ReturnToSearch ) %] >- if (form_serialized = jQuery.cookie("form_serialized")) { >+ if (form_serialized = JSON.parse( Cookies.get("form_serialized") ) ) { > // Add missing term inputs if there were more than 3 > var count = (form_serialized.match(/&q=/g) || []).length; > for(var i = 3 ; i < count ; i++) { >@@ -485,7 +483,7 @@ $(document).ready(function() { > } > $('#advsearch form').deserialize(form_serialized); > } >- if (form_serialized_limits = jQuery.cookie("form_serialized_limits")) { >+ if (form_serialized_limits = JSON.parse( Cookies.get("form_serialized_limits") ) ) { > $('#language-limit') .val(form_serialized_limits[0]); > $('#branchloop') .val(form_serialized_limits[1]); > $('#subtype_audience') .val(form_serialized_limits[2]); >@@ -496,9 +494,9 @@ $(document).ready(function() { > } > [% ELSE %] > //Clear all form cookies >- jQuery.removeCookie("form_serialized", { path: '/'}); >- jQuery.removeCookie("form_serialized_limits", { path: '/'}); >- jQuery.removeCookie("search_path_code", { path: '/'}); >+ Cookies.remove("form_serialized", { path: '/'}); >+ Cookies.remove("form_serialized_limits", { path: '/'}); >+ Cookies.remove("search_path_code", { path: '/'}); > [% END %] > $('#advsearch form').submit(function() { > $('[name^="limit"]').each(function(){ >@@ -514,18 +512,18 @@ $(document).ready(function() { > } > }); > form_serialized = $(this).serialize(); >- jQuery.cookie("form_serialized", form_serialized,{ path: '/'}); >+ Cookies.set("form_serialized", JSON.stringify( form_serialized ), { path: '/'}); > form_serialized_limits = [ > $('#language-limit').val(), $('#branchloop').val(), > $('#subtype_audience').val(), $('#subtype_content').val(), > $('#subtype_format').val(), $('#subtype_additional').val(), > $('#locloop').val() > ]; >- jQuery.cookie("form_serialized_limits", form_serialized_limits,{ path: '/'}); >+ Cookies.set("form_serialized_limits", JSON.stringify( form_serialized_limits ),{ path: '/'}); > [% IF ( expanded_options ) %] >- jQuery.cookie("search_path_code", 'exs',{ path: '/'}); >+ Cookies.set("search_path_code", JSON.stringify('exs'), { path: '/'}); > [% ELSE %] >- jQuery.cookie("search_path_code", 'ads',{ path: '/'}); >+ Cookies.set("search_path_code", JSON.stringify('ads'), { path: '/'}); > [% END %] > }); > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js b/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js >deleted file mode 100644 >index 36d6b65eed..0000000000 >--- a/koha-tmpl/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.cookie.min.js >+++ /dev/null >@@ -1,2 +0,0 @@ >-/*! jquery.cookie v1.4.1 | MIT */ >-!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?a(require("jquery")):a(jQuery)}(function(a){function b(a){return h.raw?a:encodeURIComponent(a)}function c(a){return h.raw?a:decodeURIComponent(a)}function d(a){return b(h.json?JSON.stringify(a):String(a))}function e(a){0===a.indexOf('"')&&(a=a.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\"));try{return a=decodeURIComponent(a.replace(g," ")),h.json?JSON.parse(a):a}catch(b){}}function f(b,c){var d=h.raw?b:e(b);return a.isFunction(c)?c(d):d}var g=/\+/g,h=a.cookie=function(e,g,i){if(void 0!==g&&!a.isFunction(g)){if(i=a.extend({},h.defaults,i),"number"==typeof i.expires){var j=i.expires,k=i.expires=new Date;k.setTime(+k+864e5*j)}return document.cookie=[b(e),"=",d(g),i.expires?"; expires="+i.expires.toUTCString():"",i.path?"; path="+i.path:"",i.domain?"; domain="+i.domain:"",i.secure?"; secure":""].join("")}for(var l=e?void 0:{},m=document.cookie?document.cookie.split("; "):[],n=0,o=m.length;o>n;n++){var p=m[n].split("="),q=c(p.shift()),r=p.join("=");if(e&&e===q){l=f(r,g);break}e||void 0===(r=f(r))||(l[q]=r)}return l};h.defaults={},a.removeCookie=function(b,c){return void 0===a.cookie(b)?!1:(a.cookie(b,"",a.extend({},c,{expires:-1})),!a.cookie(b))}}); >diff --git a/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.js b/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.js >new file mode 100644 >index 0000000000..d36c82be1f >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.js >@@ -0,0 +1,147 @@ >+/*! js-cookie v3.0.1 | MIT */ >+; >+(function (global, factory) { >+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : >+ typeof define === 'function' && define.amd ? define(factory) : >+ (global = global || self, (function () { >+ var current = global.Cookies; >+ var exports = global.Cookies = factory(); >+ exports.noConflict = function () { global.Cookies = current; return exports; }; >+ }())); >+}(this, (function () { 'use strict'; >+ >+ /* eslint-disable no-var */ >+ function assign (target) { >+ for (var i = 1; i < arguments.length; i++) { >+ var source = arguments[i]; >+ for (var key in source) { >+ target[key] = source[key]; >+ } >+ } >+ return target >+ } >+ /* eslint-enable no-var */ >+ >+ /* eslint-disable no-var */ >+ var defaultConverter = { >+ read: function (value) { >+ if (value[0] === '"') { >+ value = value.slice(1, -1); >+ } >+ return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent) >+ }, >+ write: function (value) { >+ return encodeURIComponent(value).replace( >+ /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, >+ decodeURIComponent >+ ) >+ } >+ }; >+ /* eslint-enable no-var */ >+ >+ /* eslint-disable no-var */ >+ >+ function init (converter, defaultAttributes) { >+ function set (key, value, attributes) { >+ if (typeof document === 'undefined') { >+ return >+ } >+ >+ attributes = assign({}, defaultAttributes, attributes); >+ >+ if (typeof attributes.expires === 'number') { >+ attributes.expires = new Date(Date.now() + attributes.expires * 864e5); >+ } >+ if (attributes.expires) { >+ attributes.expires = attributes.expires.toUTCString(); >+ } >+ >+ key = encodeURIComponent(key) >+ .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent) >+ .replace(/[()]/g, escape); >+ >+ var stringifiedAttributes = ''; >+ for (var attributeName in attributes) { >+ if (!attributes[attributeName]) { >+ continue >+ } >+ >+ stringifiedAttributes += '; ' + attributeName; >+ >+ if (attributes[attributeName] === true) { >+ continue >+ } >+ >+ // Considers RFC 6265 section 5.2: >+ // ... >+ // 3. If the remaining unparsed-attributes contains a %x3B (";") >+ // character: >+ // Consume the characters of the unparsed-attributes up to, >+ // not including, the first %x3B (";") character. >+ // ... >+ stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]; >+ } >+ >+ return (document.cookie = >+ key + '=' + converter.write(value, key) + stringifiedAttributes) >+ } >+ >+ function get (key) { >+ if (typeof document === 'undefined' || (arguments.length && !key)) { >+ return >+ } >+ >+ // To prevent the for loop in the first place assign an empty array >+ // in case there are no cookies at all. >+ var cookies = document.cookie ? document.cookie.split('; ') : []; >+ var jar = {}; >+ for (var i = 0; i < cookies.length; i++) { >+ var parts = cookies[i].split('='); >+ var value = parts.slice(1).join('='); >+ >+ try { >+ var foundKey = decodeURIComponent(parts[0]); >+ jar[foundKey] = converter.read(value, foundKey); >+ >+ if (key === foundKey) { >+ break >+ } >+ } catch (e) {} >+ } >+ >+ return key ? jar[key] : jar >+ } >+ >+ return Object.create( >+ { >+ set: set, >+ get: get, >+ remove: function (key, attributes) { >+ set( >+ key, >+ '', >+ assign({}, attributes, { >+ expires: -1 >+ }) >+ ); >+ }, >+ withAttributes: function (attributes) { >+ return init(this.converter, assign({}, this.attributes, attributes)) >+ }, >+ withConverter: function (converter) { >+ return init(assign({}, this.converter, converter), this.attributes) >+ } >+ }, >+ { >+ attributes: { value: Object.freeze(defaultAttributes) }, >+ converter: { value: Object.freeze(converter) } >+ } >+ ) >+ } >+ >+ var api = init(defaultConverter, { path: '/' }); >+ /* eslint-enable no-var */ >+ >+ return api; >+ >+}))); >diff --git a/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.min.js b/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.min.js >new file mode 100644 >index 0000000000..90a7672232 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/lib/js-cookie/js.cookie-3.0.1.min.js >@@ -0,0 +1,2 @@ >+/*! js-cookie v3.0.1 | MIT */ >+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,(function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}return function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(r,t)+c}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(o[u]=n.read(c,u),e===u)break}catch(e){}}return e?o[e]:o}},remove:function(t,n){r(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})})); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29940
:
129749
|
129835
|
129890
|
129891
|
131838
|
131839