array( 'closeText' => t('Close Window'), 'closeImage' => theme('image', ctools_image_path('icon-close-window.png'), t('Close window'), t('Close window')), 'throbber' => theme('image', ctools_image_path('throbber.gif'), t('Loading...'), t('Loading')), )); drupal_add_js($settings, 'setting'); ctools_add_js('dimensions'); ctools_add_js('mc'); ctools_add_js('ajax-responder'); ctools_add_js('modal'); ctools_add_css('modal'); $done = TRUE; } /** * Place HTML within the modal. * * @param $title * The title of the modal. * @param $html * The html to place within the modal. */ function ctools_modal_command_display($title, $html) { return array( 'command' => 'modal_display', 'title' => $title, 'output' => $html, ); } /** * Dismiss the modal. */ function ctools_modal_command_dismiss() { return array( 'command' => 'modal_dismiss', ); } /** * Render an image as a button link. This will automatically apply an AJAX class * to the link and add the appropriate javascript to make this happen. * * @param $image * The path to an image to use that will be sent to theme('image') for rendering. * @param $dest * The destination of the link. * @param $alt * The alt text of the link. * @param $class * Any class to apply to the link. @todo this should be a options array. */ function ctools_modal_image_button($image, $dest, $alt, $class = '') { return ctools_ajax_text_button(theme('image', $image), $dest, $alt, $class, 'ctools-use-modal'); } /** * Render text as a link. This will automatically apply an AJAX class * to the link and add the appropriate javascript to make this happen. * * Note: 'html' => true so be sure any text is vetted! Chances are these kinds of buttons will * not use user input so this is a very minor concern. * * @param $image * The path to an image to use that will be sent to theme('image') for rendering. * @param $dest * The destination of the link. * @param $alt * The alt text of the link. * @param $class * Any class to apply to the link. @todo this should be a options array. */ function ctools_modal_text_button($text, $dest, $alt, $class = '') { return ctools_ajax_text_button($text, $dest, $alt, $class, 'ctools-use-modal'); } /** * Wrap a form so that we can use it properly with AJAX. Essentially if the * form wishes to render, it automatically does that, otherwise it returns * so we can see submission results. */ function ctools_modal_form_wrapper($form_id, &$form_state) { ctools_include('form'); ctools_include('modal'); // This won't override settings already in. $form_state += array( 're_render' => FALSE, 'no_redirect' => !empty($form_state['ajax']), ); $output = ctools_build_form($form_id, $form_state); if (!empty($form_state['ajax']) && empty($form_state['executed'])) { return ctools_modal_form_render($form_state, $output); } return $output; } /** * Render a form into an AJAX display. */ function ctools_modal_form_render($form_state, $output) { $title = empty($form_state['title']) ? '' : $form_state['title']; // If there are messages for the form, render them. if ($messages = theme('status_messages')) { $output = '
' . $output; } return array(ctools_modal_command_display($title, $output)); }