How to reinitialize colorbox?
Hi i'm using colorbox on a site that utilizes turbo-links. It seems that just including the colorbox script creates a bunch of html divs to render it. When I change pages using turbolinks they wipe these initial divs and colorbox can bot be called again. Hoping there is a manuel method to initialize colorbox that I am missing.
I think you should be able to call the remove method, then assign it to your new elements. For example:
$.colorbox.remove();
$('.example').colorbox();
Can you explain what you mean with: "and colorbox can bot be called again".
I thought just to call it again would do the trick?
What happens to colorbox instances when I call colorbox on them again? without the remove();
You should bind a script to your links, where you refresh the colorbox like in @jackmoore 's code.
@markusfalk I think changing the page destroys all colorbox-divs which are necessary for colorbox to trigger itself. They just need to be refreshed after switchting pages per js.
Hi,
I have 2 div elemets with images and I want to remove and add colorbox for these divs separately. I would be happy if there is something like
$.colorbox.remove('selector') or $.colorbox.remove('parent-element-selector').
Thanks in advance.
JavaScript applications are getting more and more popular, and plugins should support removing, when it's no longer needed.
E.g. from Ember:
export default Ember.Component.extend({
didInsertElement() {
this.$().find('a').colorbox({ ... })
},
willClearRender() {
this.$().find('a').colorbox('destroy') // <= This should be possible.
}
})
I can only remove colorbox from the entire page. However, I have several different galleries, and only want to remove one of them. Basically colorbox should provide a way to remove the plugin for the same selector for which it's added.
Hello, I would also be very interested in a way to target a specific element for which to destroy the colorbox, without changing anything for other elements. Please let us know if we should create a different issue than this one, as it's a bit different from the inital question.
I'm also looking for a way to remove colorbox by selector