Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Dec 16, 2024
1 parent 660ce46 commit 6c8cf7e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion resources/js/cookies-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(';');
Expand All @@ -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;';
}
Expand Down

0 comments on commit 6c8cf7e

Please sign in to comment.