From e11e52b447cd6891763cc5efc18d7ac13c7566a3 Mon Sep 17 00:00:00 2001
From: Guillaume AGNIERAY <dev@agnieray.net>
Date: Fri, 24 Sep 2021 00:35:26 +0200
Subject: [PATCH] Replace jQuery Cookie with JS Cookie; closes #1569

---
 galette/includes/galette.inc.php        |  5 ++++-
 galette/templates/default/desktop.tpl   | 14 ++++++++++----
 galette/templates/default/telemetry.tpl | 21 +++++++++++++++------
 gulpfile.js                             |  2 +-
 package-lock.json                       |  8 ++++----
 package.json                            |  2 +-
 6 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/galette/includes/galette.inc.php b/galette/includes/galette.inc.php
index 0864ca39..90053532 100644
--- a/galette/includes/galette.inc.php
+++ b/galette/includes/galette.inc.php
@@ -117,7 +117,10 @@ if (!isset($_COOKIE['show_galette_dashboard'])) {
     setcookie(
         'show_galette_dashboard',
         true,
-        time() + 31536000 //valid for a year
+        [
+            'expires'   => time() + 31536000, //valid for a year
+            'path'      => '/'
+        ]
     );
 }
 
diff --git a/galette/templates/default/desktop.tpl b/galette/templates/default/desktop.tpl
index ce66055d..cbf2c3b9 100644
--- a/galette/templates/default/desktop.tpl
+++ b/galette/templates/default/desktop.tpl
@@ -80,10 +80,13 @@
             $(function() {
                 $('#show_dashboard').change(function(){
                     var _checked = $(this).is(':checked');
-                    $.cookie(
+                    Cookies.set(
                         'show_galette_dashboard',
                         (_checked ? 1 : 0),
-                        { expires: 365 }
+                        {
+                            expires: 365,
+                            path: '/'
+                        }
                     );
                     if ( !_checked ) {
                         var _url = '{path_for name="members"}';
@@ -94,10 +97,13 @@
     {if not $hide_telemetry}
                 $('#hide_telemetry').change(function(){
                     var _checked = $(this).is(':checked');
-                    $.cookie(
+                    Cookies.set(
                         'hide_galette_telemetry',
                         (_checked ? 1 : 0),
-                        { expires: 365 }
+                        {
+                            expires: 365,
+                            path: '/'
+                        }
                     );
                     var _url = '{path_for name="dashboard"}';
                     window.location.replace(_url);
diff --git a/galette/templates/default/telemetry.tpl b/galette/templates/default/telemetry.tpl
index fdd0b94c..2c34f933 100644
--- a/galette/templates/default/telemetry.tpl
+++ b/galette/templates/default/telemetry.tpl
@@ -26,10 +26,13 @@
     {/if}
     {if isset($renew_telemetry)}
                                         $('#renewbox').remove();
-                                        $.cookie(
+                                        Cookies.set(
                                             'renew_telemetry',
                                             1,
-                                            { expires: 365 }
+                                            {
+                                                expires: 365,
+                                                path: '/'
+                                            }
                                         );
     {/if}
                                     }
@@ -73,18 +76,24 @@
                 });
     {if isset($renew_telemetry)}
             $('#norenew').on('click', function() {
-                $.cookie(
+                Cookies.set(
                     'renew_telemetry',
                     1,
-                    { expires: 365 }
+                    {
+                        expires: 365,
+                        path: '/'
+                    }
                 );
                 window.location.reload();
             });
             $('#renewlater').on('click', function() {
-                $.cookie(
+                Cookies.set(
                     'renew_telemetry',
                     1,
-                    { expires: 182 }
+                    {
+                        expires: 182,
+                        path: '/'
+                    }
                 );
                 window.location.reload();
             });
diff --git a/gulpfile.js b/gulpfile.js
index e335fc27..3cc0ca86 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -26,7 +26,7 @@ var main_scripts = [
     './node_modules/jquery/dist/jquery.js',
     './node_modules/jquery-ui-dist/jquery-ui.js',
     './node_modules/jquery-ui/ui/i18n/*',
-    './node_modules/jquery.cookie/jquery.cookie.js',
+    './node_modules/js-cookie/dist/js.cookie.min.js',
     './node_modules/microplugin/src/microplugin.js',
     './node_modules/sifter/sifter.js',
     './node_modules/selectize/dist/js/selectize.min.js',
diff --git a/package-lock.json b/package-lock.json
index 6944d2b3..f590f366 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2690,10 +2690,10 @@
       "resolved": "https://registry.npmjs.org/jquery-ui-dist/-/jquery-ui-dist-1.12.1.tgz",
       "integrity": "sha1-XAgV08xvkP9fqvWyaKbiO0ypBPo="
     },
-    "jquery.cookie": {
-      "version": "1.4.1",
-      "resolved": "https://registry.npmjs.org/jquery.cookie/-/jquery.cookie-1.4.1.tgz",
-      "integrity": "sha1-1j3OIJ6raR/mMxbbCMqeR+D5OFs="
+    "js-cookie": {
+      "version": "3.0.1",
+      "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz",
+      "integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw=="
     },
     "json-schema-traverse": {
       "version": "0.4.1",
diff --git a/package.json b/package.json
index 1fad3eac..ebb27db7 100644
--- a/package.json
+++ b/package.json
@@ -38,7 +38,7 @@
     "jquery": "^3.5.0",
     "jquery-ui": "^1.12.1",
     "jquery-ui-dist": "^1.12.1",
-    "jquery.cookie": "^1.4.1",
+    "js-cookie": "^3.0.1",
     "jstree": "^3.3.9",
     "selectize": "^0.12.6",
     "summernote": "^0.8.18"
-- 
2.30.2

