Skip to content
New issue

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

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

Already on GitHub? # to your account

Add ability to optionally traverse the DOM #70

Closed
rodrigoaguilera opened this issue Mar 26, 2019 · 4 comments
Closed

Add ability to optionally traverse the DOM #70

rodrigoaguilera opened this issue Mar 26, 2019 · 4 comments
Milestone

Comments

@rodrigoaguilera
Copy link

rodrigoaguilera commented Mar 26, 2019

I'm trying to integrate this library with the Drupal Javascript system in the following project
https://www.drupal.org/project/drulma
and I want to avoid unnecessary calls to traverseDOM. The dom is traversed on the loading of Bulmajs, then when I load this concept of "Drupal behaviors" and then after every ajax call that modifies markup.

Solution that I'd like
I am not very experienced with javascript modules but maybe separate this piece

document.addEventListener('DOMContentLoaded', () => {
    Bulma.traverseDOM();
});

from the core to a BulmajsInit file.

I think this will also benefit people who only use the library to make JS calls and do not want the markup inspected.

Another cool addition to the traverseDOM function (or separate it to a different method) would be the possibility to start traversing from a different element instead of document in case you know what parts need to be traversed (again, when drupal load a new piece of markup with ajax).

What do think?

Great work with the project :)

@VizuaaLOG
Copy link
Owner

Hey @rodrigoaguilera,

Thank you for the suggestion. I've been thinking about this. Rather than splitting that bit into it's own file I think the best way is to do something like this:

window.bulmaOptions = {
    autoParseDocument: false // default is true
}

If the above is included before the BulmaJS script is executed the core can check and prevent the automatic DOM parsing from running.

This also prevents minimal changes to how the core works, as if someone wishes to manually cause the DOM parsing to run they can still call Bulma.traverseDOM().

Another cool addition to the traverseDOM function (or separate it to a different method) would be the possibility to start traversing from a different element instead of document in case you know what parts need to be traversed (again, when drupal load a new piece of markup with ajax).

I do like this idea, as it would provide a way to scope the parsing should the flexibility be required. I think expanding the traverseDOM function to accept an optional root parameter. This would default to the document body.

What do you think of the above changes? Would that work for you, it would also help improve the flexibility of the library for others integrating it into a different platform, similar to yourself.

@VizuaaLOG VizuaaLOG added this to the 0.10.0 milestone Mar 27, 2019
@rodrigoaguilera
Copy link
Author

I like the bulmaOptions idea even better!

Everything sounds good and it feels like the changes would be minimal.
I feel like submitting the PRs myself will only slow things down but if you are busy I can give it a try.

@VizuaaLOG
Copy link
Owner

Hey @rodrigoaguilera

Thank you again for your suggestion. Both of these features are now in master and will be included in the next 0.10.0 release.

@rodrigoaguilera
Copy link
Author

Woah, thanks to you!

I will try it soon

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants