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

Not working for dynamically created container #23

Closed
skizzo opened this issue Jan 23, 2016 · 6 comments
Closed

Not working for dynamically created container #23

skizzo opened this issue Jan 23, 2016 · 6 comments

Comments

@skizzo
Copy link

skizzo commented Jan 23, 2016

Hi,
how can I use Chocolat on a div that contains dynamically created (jQuery / .html() function) images? After calling the .Chocolat() function on the div with dynamic content and clicking on a link, the page redirects to the image instead of opening it in the Chocolat lightbox.
Thanks!

@nicolas-t
Copy link
Owner

Hi,

There is no "refresh" function for the moment.
One solution would be to call chocolat $('selector').Chocolat() after elements are dynamically added.

Maybe i can help you more if you provide some code snippets.

Best regards,

@matyus
Copy link

matyus commented Jan 24, 2016

I think I'm having the same issue?

An example would be:

$('#container').load('/foo.html #container .image');

$('#container').Chocolat();

Let's say I'm on index.html, and I load an array of elements (.image) into the #container on index.html… when I call Chocolat() it doesn't register the dynamically loaded elements.

@matyus
Copy link

matyus commented Jan 24, 2016

I suspect there's an issue with this.element.find(this.settings.imageSelector); in the constructor. With dynamically loaded content, you'd need to opt for delegation, so you'd have to do something like this.element.on('click.chocolat', this.settings.imageSelector, function(){}); but then of course things get more complicated when trying to find the index of the given element.

@nicolas-t
Copy link
Owner

@matyus Hi !
In your case you just need to use deferred callback for example :

$('#container').load('/foo.html #container .image', function() {
    $('#container').Chocolat();
});

@matyus
Copy link

matyus commented Jan 24, 2016

@nicolas-t oh wow, thanks! I totally forgot .load takes a callback.

@nicolas-t
Copy link
Owner

i'm closing, feel free to reopen if you have any question

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

No branches or pull requests

3 participants