colorbox icon indicating copy to clipboard operation
colorbox copied to clipboard

How to reinitialize colorbox?

Open kevzettler opened this issue 12 years ago • 9 comments

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.

kevzettler avatar Aug 02 '13 19:08 kevzettler

I think you should be able to call the remove method, then assign it to your new elements. For example:

$.colorbox.remove();
$('.example').colorbox();

jackmoore avatar Aug 02 '13 20:08 jackmoore

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?

markusfalk avatar Nov 13 '13 15:11 markusfalk

What happens to colorbox instances when I call colorbox on them again? without the remove();

markusfalk avatar Nov 13 '13 15:11 markusfalk

You should bind a script to your links, where you refresh the colorbox like in @jackmoore 's code.

bdbch avatar Jan 30 '14 08:01 bdbch

@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.

bdbch avatar Jan 30 '14 08:01 bdbch

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.

goshoo avatar Feb 05 '15 14:02 goshoo

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.

martinthogersen avatar Nov 26 '16 16:11 martinthogersen

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.

mh-nichts avatar Dec 07 '16 13:12 mh-nichts

I'm also looking for a way to remove colorbox by selector

Karmalakas avatar Dec 23 '16 08:12 Karmalakas