You are here

function theme_panels_ajax_tab_ajax in Panels Ajax Tabs 7

Theme function that renders the AHAH markup for a mini-panel.

1 theme call to theme_panels_ajax_tab_ajax()
panels_ajax_tab_ajax in ./panels_ajax_tab.module
AJAX callback for rendering tab.

File

./panels_ajax_tab.module, line 306
Allows users to create and manage Panels Ajax Tabs.

Code

function theme_panels_ajax_tab_ajax($vars) {

  // Grab all CSS for later comparison before clearing it.
  $previous_css = drupal_add_css();

  // Clear the JavaScript & CSS not related to the pane being rendered.
  drupal_static_reset('drupal_add_js');
  drupal_static_reset('drupal_add_css');

  // Render the pane.
  $mini = $vars['minipanel'];
  $layout = panels_get_layout($mini->display->layout);
  if (empty($mini->display->cache_key)) {
    $mini->display->cache_key = $mini->name;
  }
  $panels_output = panels_render_display($mini->display);

  // Grab new CSS files related to this pane.
  $css = drupal_add_css();

  // Assign a unique basename to new stylesheets.
  foreach ($css as $key => $item) {
    if ($item['type'] == 'file') {

      // If not defined, force a unique basename for this file.
      $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']);
      $item['basename'] = $basename;
      $css[$key] = $item;
    }
  }

  // Iterate through previous CSS stylesheets, and add any with matching
  // basenames to allow, for proper overrides when calling drupal_get_css($css).
  foreach ($previous_css as $key => $item) {
    if ($item['type'] == 'file') {

      // If not defined, force a unique basename for this file.
      $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']);
      $item['basename'] = $basename;
      $previous_css[$key] = $item;
      foreach ($css as $key2 => $item2) {

        // Make sure to append previous stylesheets with matching basenames
        // to the new CSS array.
        if ($item['basename'] == $item2['basename']) {
          $css[$key] = $previous_css[$key];
        }
      }
    }
  }
  $output = '';
  $output .= '<?xml version="1.0" encoding="UTF-8" ?>';
  $output .= '
    <html version="HTML+RDFa+MathML 1.1"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:dc="http://purl.org/dc/terms/"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:og="http://ogp.me/ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:sioc="http://rdfs.org/sioc/ns#"
    xmlns:sioct="http://rdfs.org/sioc/types#"
    xmlns:skos="http://www.w3.org/2004/02/skos/core#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:mml="http://www.w3.org/1998/Math/MathML">
  ';
  $output .= '<head>';

  // Need to call page alter so that modules like google analytics can add js
  // We only invoke the page alter if url_enabled is true.
  if ($vars['url_enabled']) {
    $page = array();
    drupal_alter('page', $page);
  }

  // Get the javascript and filter out the default misc/drupal.js -
  // it's already been added by the calling page.
  $javascript = drupal_add_js();
  unset($javascript['misc/drupal.js']);

  // Add the javascript.
  $output .= drupal_get_js('header', $javascript);

  // Add CSS.
  $output .= drupal_get_css($css);
  if (isset($layout['css'])) {
    $output .= "<link rel='stylesheet' type='text/css' href='" . base_path() . $layout['path'] . '/' . $layout['css'] . "' />";
  }
  $output .= '</head>';

  // Print the output of the panel.
  $output .= '<body>';
  $output .= theme('status_messages');
  $output .= '<div class="panels-ajax-tab-panel panels-ajax-tab-panel-' . str_replace('_', '-', $mini->name) . '">';
  $output .= $panels_output;
  $output .= '</div>';
  $output .= drupal_get_js('footer', $javascript);
  $output .= '</body></html>';
  return $output;
}