Should allow options container as Node el
JSteunou opened this issue · 8 comments
I already have my container node when instantiate bricks.js, would be useful to directly give it instead of adding special attribute on it in order to create a unique selector.
you can use whatever CSS selector you'd like to select it - it doesn't have to be a data attribute. see the container
option documentation
You get me wrong. My use case is something like this: I'm in a view, already having a variable pointing to a NodeElement. I dont know its class attribute. I would like to be able to do so
var bricks = new Bricks({
container: myEl,
// ...
});
instead of
myEl.setAttribute('data-bricks', 1234);
var bricks = new Bricks({
container: '[data-bricks="1234"]',
// ...
});
I could play with class instead of data attribute but I dont want to pollute it for nothing.
My point is: I already have my NodeElement, no need to run querySelector
a second time.
my mistake. unfortunately this isn't as easy as it may seem, because I need the CSS selector representation of the container to build the selector for the children elements. see these lines in the source.
will leave this open, as an enhancement, because i'll have to look into doing this selection with only a node as reference, instead of a selector.
@callmecavs This would still be very very simple:
Instead of document.querySelectorAll(selectors.all)
; you would go for container.querySelectorAll('*')
(or in this case container.children
).
This would also be a major performance improvement (selecting *
is slow)
@gjuchault the solution is already in this PR #17 since a couple months :(
I've come up with my own PR.
It's non breaking, with package.json, site and docs update
Avoid to update package.json, min files, dist files, in a PR.
Good practice is to only update src, doc, tests
@gjuchault @JSteunou replied to both of your pull requests. my apologies for the delay - the latest version includes support for this.