jackmoore/colorbox — Issue #124: colorbox crashes when called via delegate() or live()
Author: neokio
Created: 2011-10-21 12:19:06+00:00
State: open

Hi there! I'm migrating all my code from Shadowbox to Colorbox because of its unmitigated awesomeness. In doing so, I've run into a show-stopper.

I've tested the following on Chrome 14.0.835.202, Firefox 3.6.8 and Safari 5.0.4. Both Chrome and Firefox crash with an "unresponsive script", Chrome seems to not have any problems.

My web app is running jQuery v1.6.4 and ColorBox v1.3.18. Here's the colorbox call loaded via `$(function(){ ... });`:

$('body').delegate('.showbox', 'click' ,function(event){
$.colorbox({
opacity: 0.8,
href: $(this).data('url'),
title: $(this).data('title')
});
event.preventDefault();
});

I use .delegate() because the HTML is refreshed every minute via AJAX.
The HTML looks like this (theres a long list of these, dynamically generated of course):

o# 123

This seems to work great at first. I click the order link, and colorbox opens the order. I close the box, open another order, and it opens again, reluctantly. I close and open a third time, and it basically crashes my browser (Chrome).

If I remove the ajax and just use static links, it still crashes.
If I change .delegate() to .live(), it still crashes.

Any ideas, other than taking colorbox out of the delegate() loop and calling $.colorbox.remove() and then $.colorbox.init() via callback every time I refresh the page content?