Skip to content

Conversation

Debatty-Tom
Copy link
Contributor

@Debatty-Tom Debatty-Tom commented Oct 3, 2025

Cover #26, #28, and PR #89 which solve #47 and #63. Transitions on the cookie modal don’t work without JavaScript.

Refactor script.js file by creating a modal object. Each logic is now in a dedicated file and we make sure document is fully loaded before doing everything.

Copy link
Member

@toonvandenbos toonvandenbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, this will be a new major update since it comes with some breaking changes.

return;
}

this.getValues();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to this.getUIElements() instead of this.getValues(). Ideally, all DOM elements are stored in the same this.elements object, such as:

this.elements = this.getUIElements(document.querySelector('#cookies-policy'));

if(! this.elements) {
    return;
}

This elements object can then be further used like this: this.elements.root, this.elements.reset, ...

The current this.text attribute should be renamed to this.translations and parsed after this.elements has been set, such as:

this.translations = this.getUITranslations();
getUITranslations() {
    let value = this.elements.root.getAttribute('data-text');
    this.elements.root.removeAttribute('data-text');
    return JSON.parse(value);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: maybe getUITranslations will not be necessary, take a look at this comment below.

Comment on lines 72 to 80
@if(!$isReset)
<script data-cookie-consent>
let element = document.querySelector('#cookies-policy');
if (element) {
element.classList.add('cookies--pre-init');
element.classList.add('cookies--closing');
}
</script>
@endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like this at all. Should be handled inside the modal.js init method. In all cases, the #cookies-policy element should be hidden when JS is enabled and the modal's script has not been initiated.

return view('cookie-consent::cookies', [
'cookies' => $this->registrar,
'policy' => $policy,
'isReset' => $isReset,
Copy link
Member

@toonvandenbos toonvandenbos Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of providing a isReset attribute, it would be better to provide a RenderingContext (Enum) value to the view. This way developers can hook in all the possible modal rendering contexts:

enum CookieConsentState
{
    // User has yet to configure consent
    case Pending;

    // User has defined a consent configuration
    case Configured;

    // User has configured consent but wants to show the modal in order to eventually make changes
    case Updating;

    // User had configured consent but chose to reset the settings (similar to "pending")
    case Reset;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing other open PRs, this would be more related to PR #99. Please add this enum there.

In this PR's contect, I don't think isReset is still needed here because of this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that the suggested CookieConsentState::Updating is related to issue #58 and its linked PR #103, which will however not be merged in its current state.

Comment on lines 9 to 12
public function __invoke(Request $request)
{

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both routes leading to this controller have named methods, the __invoke method can be removed.

Comment on lines 20 to 24
public function getModalScript()
{
$content = file_get_contents(LCC_ROOT . '/dist/modal.js');
return response($content)->header('Content-Type', 'application/javascript');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use this opportunity to pass the translation strings to the modal's constructor, like we did for the API routes configuration in getCookiesScript() ?

@Debatty-Tom Debatty-Tom changed the base branch from main to 2.x October 21, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants