Drupal provides a few custom events for AJAX modals. Even though the modal itself is provided by jQuery UI library, these events are custom and are provided by Drupal itself.
There are a few events you can use here:
dialog:beforecreate
dialog:aftercreate
dialog:beforeclose
dialog:afterclose
All of them are triggered on the window. Below is sample code that can be used in a custom theme or custom module:
(function ($, Drupal) { Drupal.behaviors.sampleModalReaction = { attach: function(context) { $(window) .once() .on('dialog:aftercreate', function(dialog, $element, settings) { }); } }; })(jQuery, Drupal);
You can read the source code in /core/misc/dialog/dialog.js
file to understand how everything works.