From 6c8cf7e60b7a5b6eddc3d7727d8ce36737892e32 Mon Sep 17 00:00:00 2001 From: Paul Isaris Date: Mon, 16 Dec 2024 10:25:06 +0200 Subject: [PATCH] Comments --- resources/js/cookies-consent.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/resources/js/cookies-consent.js b/resources/js/cookies-consent.js index 83b9f90..34f1209 100644 --- a/resources/js/cookies-consent.js +++ b/resources/js/cookies-consent.js @@ -146,7 +146,14 @@ document.addEventListener('DOMContentLoaded', function () { }); } - // Helper functions to manage cookies + // Helper functions to manage cookies: + + /** + * Set a cookie with a given name and value + * @param name The name of the cookie + * @param value The value of the cookie + * @param days The number of days until the cookie expires + */ function setCookie(name, value, days) { let expires = ""; if (days) { @@ -157,6 +164,10 @@ document.addEventListener('DOMContentLoaded', function () { document.cookie = name + "=" + (value || "") + expires + "; path=/"; } + /** + * Get the value of a cookie by its name if it exists + * @param name The name of the cookie to retrieve + */ function getCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); @@ -168,6 +179,10 @@ document.addEventListener('DOMContentLoaded', function () { return null; } + /** + * Erase a cookie by setting its expiry date to a past date + * @param name The name of the cookie to erase + */ function eraseCookie(name) { document.cookie = name + '=; Max-Age=-99999999;'; }