Hi Humaan,
Greetings from another Perth frontender.
I've noticed an annoying bug with Modaal: I have a project where I dynamically add/create or remove elements to a list based on user filtering. A very basic webapp.
Some of these elements contains anchor links that are supposed to open modals. So because these links are not in the markup on page load, I have to use JavaScript to open the modals rather than using the data attributes. I also have to delegate the click handlers like this:
$(document).on('click', 'selector', e => {
e.preventDefault();
$(e.currentTarget).modaal();
});
And well, that doesn't work, I have to click twice for it to open the modal. The first click does some modal initialisation stuff, but doesn't go as far as opening it.
I've found a workaround that looks like:
$(document).on('click', 'selector', e => {
e.preventDefault();
if(!$(e.currentTarget).data('modaal-scope')) {
$(e.currentTarget).modaal();
setTimeout(()=> $(e.currentTarget).trigger('click'), 20);
} else {
$(e.currentTarget).modaal();
}
});
And it works, but it lacks elegance.
I think a static method to open a modal, one that doesn't rely on an anchor/modal coupling, could solve this. Something like Modaal.open('selector'). Or you might want to investigate the way your register your events handlers.
Anyway, thanks for your great plugin.
Hi Humaan,
Greetings from another Perth frontender.
I've noticed an annoying bug with Modaal: I have a project where I dynamically add/create or remove elements to a list based on user filtering. A very basic webapp.
Some of these elements contains anchor links that are supposed to open modals. So because these links are not in the markup on page load, I have to use JavaScript to open the modals rather than using the data attributes. I also have to delegate the click handlers like this:
And well, that doesn't work, I have to click twice for it to open the modal. The first click does some modal initialisation stuff, but doesn't go as far as opening it.
I've found a workaround that looks like:
And it works, but it lacks elegance.
I think a static method to open a modal, one that doesn't rely on an anchor/modal coupling, could solve this. Something like
Modaal.open('selector'). Or you might want to investigate the way your register your events handlers.Anyway, thanks for your great plugin.