Drupal Ctools - trigger jquery on modal events

1.9k Views Asked by At

I would like to add JQuery events when the CTools modal is launched or closed. It's simple to add an event to the launch or close click

$('.ctools-use-modal').on('click',function () {
 $('body').addClass('modal-open');
});

But for closing the modal it becomes cumbersome b/c there are so many ways it can be closed. It seems like there must be a CTools event listener or something? Thanks for your advice...

1

There are 1 best solutions below

0
Chris On

CTools dispatches the event "CToolsDetachBehaviors" when the modal gets closed. Careful though, the event is fired BEFORE the closing animation has finished.

Here's a sample implementation:

$(document).on("CToolsDetachBehaviors", function() {
    console.log("Modal has closed");                    
});