You are here

function dialog_ajax_render_alter in Dialog 7

Implement hook_ajax_render_alter().

Using the xLazyLoader library and command, load additional css and javascript into the page.

TODO: Deal with overloading one theme's css onto another.

File

./dialog.module, line 105
The Dialog module provides an API for displaying and interacting with jQuery UI Dialog modals.

Code

function dialog_ajax_render_alter(&$commands) {
  if (dialog_display()) {
    $loader = array();
    $allowed_media = array(
      'all',
      'screen',
    );

    // Inject additional JavaScript and CSS to the browser's client.
    $css = drupal_add_css();
    drupal_alter('css', $css);
    foreach ($css as $data => $options) {
      if ($options['type'] == 'file' && in_array($options['media'], $allowed_media)) {
        $loader['css'][] = base_path() . $options['data'];
      }
    }
    $scripts = drupal_add_js();
    drupal_alter('js', $scripts);
    foreach ($scripts as $data => $options) {
      if ($options['type'] == 'file') {
        $loader['js'][] = base_path() . $options['data'];
      }
    }
    if (!empty($loader)) {
      array_unshift($commands, dialog_command_xlazyloader($loader));
    }

    // Prepend status messages to the dialog content.
    $commands[] = ajax_command_prepend('#dialog', theme('status_messages'));
  }
}