Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the context additionally to the children when calling parseDocument #95

Closed
rodrigoaguilera opened this issue Nov 22, 2019 · 3 comments

Comments

@rodrigoaguilera
Copy link

When Drupal loads new elements into the document it provides an API to respond to that. In this case the new elements might contain bulmaJS classes. The problem is that context.querySelectorAll() only checks for children of the context and the BulmaJS bahaviours are not added when I call Bulma.parseDocument(context)

Solution
Check also the context

let elements = context.querySelectorAll('.dropdown');

        Bulma.each(elements, (element) => {
            Bulma(element).dropdown();
        });

if (context.classList.contains('dropdown')) {
  Bulma(context).dropdown();
}

Alternatives
I considered adding the context to the elements but a JS NodeList is a read-only thing.

Additional context
I currently workaround it by passing the parent of the context but this not the most optimal solution as it might be checking children twice.

I can try to provide the PR myself but you seems much more experienced with JS.

BTW: the following phrase in the documentation

Creating a plugin instance via the DOM API is as simple as creating the Bulma component via HTML and classes. The BulmaJS plugin will then pick up the element once it is loaded and set up all of the necessary features.

might create the confusion that BulmaJS is listening to modifications in the DOM. I would suggest something like:

Creating a plugin instance via the DOM API is as simple as creating the Bulma component via HTML and classes. Once the BulmaJS plugin is loaded in the page will then pick up the element and set up all of the necessary features. You are responsible for calling Bulma.parseDocument() if new elements are added after BulmaJS is loaded.

Thank you for such a great project!

@VizuaaLOG
Copy link
Owner

Sorry for the delay in replying. I'm just trying to understand what you're looking for. When Drupal fires the even that new elements have loaded are you not able to do the Bulma.parseDocument on those new elements? I'm assuming it gives you the new elements?

@rodrigoaguilera
Copy link
Author

Yes, Drupal gives me all the new elements. What I am facing is when The new element is the one that needs to be parsed that element is ignored by Bulma.parseDocument(newElementWithBulmaClasses). Only the children of the new element will be parsed

@VizuaaLOG
Copy link
Owner

Thank you for the suggestion, this has been implemented and is now in master ready for the 0.12 release. Should you wish to try it out please note master is generally not the most stable, however, documentation can be found within the 'master' section of the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants