How to bind javascript to ctools modal load
I know this is an old question, but maybe this answer can help someone - I know I searched for an answer for a while.

I had a similar issue, I wanted to execute some javascript when a specific page of mine was rendered by ctools modal.

I found the answer in the help folder of the ctools module ctools/help/modal.html :


  If you need to do more than just render your modal, you can use a CTools $commands array. See the function ctools_modal_render() for more information on what you need to do here.


How to apply that to this situation: you need to grab the contents of the very small ctools_modal_render() function and use it to add commands to the array of commands that is executed in the function. This is the function:

function ctools_modal_render($title, $output) {
    $commands = array();
    $commands[] = ctools_modal_command_display($title, $output);
    print ajax_render($commands);
}


This is what my snippet looks like in my page - I wanted to add a body class among other things, so I could style the #modalBackdrop for the modal overlay based on context, so here's my modified page function:

function gc_alterations_modal_page($js=null){

    $page = array();

    $page['search-results'] = array(
        '#markup' =&gt; '&lt;p&gt;My Markup&lt;/p&gt;'
    );

    if( $js ) {
        // Required includes for ctools to work:
        ctools_include('modal');
        ctools_include('ajax');

        // alternate to using: ctools_modal_render('Search', $page);
        $commands = array();
        $commands[] = ajax_command_invoke('body', 'addClass', array('myclass-modal'));
        $commands[] = ctools_modal_command_display('Search', $page);
        print ajax_render($commands);
        return;
    }

    return $page;
}