I have a page which retrieves some new content from server thru ajax.

In the newly added content, the colorbox is not working. i think this is becoz they are newly added element and not yet being processed by the colorbox module. So those new elements only have the "colorbox-load" class but not "colorbox-load init-colorbox-load-processed-processed cboxElement".

is the any way i could apply colorbox on them?

Thanks

Comments

frjo’s picture

Status: Active » Closed (won't fix)

Closing old issues that doesn't seem to affect a lot of users.

Heihachi88’s picture

Issue summary: View changes
Status: Closed (won't fix) » Needs review

Not working with Drupal 7 Ajax framework. When you load content by the link click and your new content is appearing, colorbox is not working it just has a class colorbox.

gregory_kapustin’s picture

You have to have a trigger after your ajax content is loaded.

For example, commerce_ajax_cart gives a trigger when it updates the cart :

Drupal.ajax.prototype.commands.commerceAjaxCartFireTrigger = function(ajax, response, status) {
	jQuery(window).trigger('commerce_ajax_cart_update',response.data)
}

This way, i can trigger in JS on this event and attach behaviors to my loaded content.

Drupal.behaviors.MYMODULE = {
        attach: function(context, settings) {
            $(window).on('commerce_ajax_cart_update', function(data) {
                setTimeout(function() {
                    $("myajaxloadedcontent").find('.colorbox-load').each(function () {
                        var params = $.urlParams($(this).attr('href'));
                        $(this).colorbox($.extend({}, settings.colorbox, params));
                    });
                }, 2000);
            });
        }
    }
frjo’s picture

Status: Needs review » Closed (outdated)