Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Put the reset/edit logic inside the cookie.js file to keep modal.js o…
…nly for the modal handling
  • Loading branch information
Debatty-Tom committed Oct 21, 2025
commit bc3831791ade5a22d63114ab569b27da11d483c1
2 changes: 1 addition & 1 deletion dist/cookies.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion resources/js/Cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class LaravelCookieConsent {

constructor(config) {
this.config = config;
document.addEventListener('DOMContentLoaded', () => this.initActionButtons())
}

acceptAll() {
Expand Down Expand Up @@ -82,10 +83,24 @@ class LaravelCookieConsent {
}
});
}

initActionButtons() {
const actionButtons = document.querySelectorAll('[data-cookie-action]');
actionButtons.forEach((button) => {
if (button.dataset.cookieAction === 'reset'){
button.addEventListener('submit', (event) => {
event.preventDefault();
if (document.querySelector('#cookies-policy')) return;
this.reset();
});
}
// TODO: add edit case with PR:103
});
}
}

/*
Config is set to 1 here, but it is modified by ScriptController depending on the different actions.
*/
window.LaravelCookieConsent = new LaravelCookieConsent({config:1});
window.LaravelCookieConsent = new LaravelCookieConsent({config: 1});
window.dispatchEvent(new Event('LARAVEL_COOKIE_CONSENT_SCRIPT_LOAD'));
19 changes: 5 additions & 14 deletions resources/js/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class LaravelCookieModal {

constructor(translations) {
this.translations = translations;

}

init() {
Expand Down Expand Up @@ -39,20 +40,15 @@ class LaravelCookieModal {

return {
root: root,
reset: document.querySelector('[data-cookie-button]'),
customize: root.querySelector('.cookies__btn--customize'),
details: root.querySelectorAll('.cookies__details'),
acceptAll: root.querySelector('.cookiesBtn--accept'),
acceptEssentials: root.querySelector('.cookiesBtn--essentials'),
configure: root.querySelector('.cookies__customize'),
translations: this.translations,
};
}

addEventListeners() {
if (this.elements.reset) {
this.elements.reset.addEventListener('submit', (event) => this.resetCookies(event))
}
for (let i = 0; i < this.elements.details.length; i++) {
this.elements.details[i].addEventListener('click', (event) => this.toggleExpand(event, event.target, false));
}
Expand Down Expand Up @@ -119,8 +115,8 @@ class LaravelCookieModal {
if (hide) return;

event.target.textContent = isOpen
? this.elements.translations.more
: this.elements.translations.less
? this.translations.more
: this.translations.less
}

hideNotice(hide, isOpen) {
Expand Down Expand Up @@ -160,16 +156,11 @@ class LaravelCookieModal {
}
})(this.elements.root), 210);
}

resetCookies(event) {
event.preventDefault();
if (document.querySelector('#cookies-policy')) return;
window.LaravelCookieConsent.reset()
}
}

/*
"Translations" is set to 1 here, but is modified by the ScriptController depending on the current locale.
"Translations" is set to 1 here, but is modified by the cookieManager depending
on the current locale while calling this script.
*/
window.LaravelCookieModal = new LaravelCookieModal({translations:1});
window.LaravelCookieModal.init();
Expand Down