You are here

function quicktabs_render in Quick Tabs 6.3

Same name and namespace in other branches
  1. 6.2 quicktabs.module \quicktabs_render()
  2. 7.2 quicktabs.module \quicktabs_render()

Render quicktabs.

1 call to quicktabs_render()
theme_quicktabs in ./quicktabs.module
Theme function to output quicktabs.

File

./quicktabs.module, line 179

Code

function quicktabs_render($quicktabs) {

  // Allow other modules to alter the Quicktabs instance before it gets output.
  drupal_alter('quicktabs', $quicktabs);

  // convert views arguments to an array, retrieving %-style args from url
  $quicktabs['tabs'] = _quicktabs_prepare_views_args($quicktabs['tabs']);
  if ($quicktabs['hide_empty_tabs'] && !$quicktabs['ajax']) {

    // Remove empty tabpgages.
    foreach ($quicktabs['tabs'] as $key => $tab) {
      $contents = quicktabs_render_tabpage($tab, TRUE);
      if (empty($contents)) {
        $quicktabs['tabs'][$key] = NULL;
      }
      else {
        $quicktabs['tabs'][$key]['rendered'] = $contents;
      }
    }
  }
  $tabs_count = count($quicktabs['tabs']);
  if ($tabs_count <= 0) {
    return '';
  }
  if ($quicktabs['style'] == 'default') {
    $quicktabs['style'] = variable_get('quicktabs_tabstyle', 'nostyle');
  }
  quicktabs_add_css($quicktabs['style']);
  $javascript = drupal_add_js('misc/progress.js', 'core');
  if (!isset($javascript['setting'][1]['quicktabs']) || !array_key_exists('qt_' . $quicktabs['machine_name'], $javascript['setting'][1]['quicktabs'])) {

    // Only the tabs are used in quicktabs.js
    $settings = array(
      'tabs' => $quicktabs['ajax'] ? $quicktabs['tabs'] : quicktabs_array_fill_keys(array_keys(array_filter($quicktabs['tabs'])), 0),
    );
    drupal_add_js(array(
      'quicktabs' => array(
        'qt_' . $quicktabs['machine_name'] => $settings,
      ),
    ), 'setting');
  }
  drupal_add_js(drupal_get_path('module', 'quicktabs') . '/js/quicktabs.js');
  $attributes = drupal_attributes(array(
    'id' => 'quicktabs-' . $quicktabs['machine_name'],
    'class' => 'quicktabs_wrapper quicktabs-style-' . drupal_strtolower($quicktabs['style']),
  ));
  $output = '<div' . $attributes . '>';
  $active_tab = _quicktabs_get_active_tab($quicktabs);
  $output .= theme('quicktabs_tabs', $quicktabs, $active_tab);

  // The main content area, each quicktab container needs a unique id.
  $attributes = drupal_attributes(array(
    'id' => 'quicktabs_container_' . $quicktabs['machine_name'],
    'class' => 'quicktabs_main quicktabs-style-' . drupal_strtolower($quicktabs['style']),
  ));
  $output .= '<div' . $attributes . '>';
  if ($quicktabs['ajax']) {

    // Prepare ajax views.
    _quicktabs_prepare_views($quicktabs['tabs']);

    // Render only the active tabpage.
    if (isset($active_tab)) {
      $attributes = drupal_attributes(array(
        'id' => 'quicktabs_tabpage_' . $quicktabs['machine_name'] . '_' . $active_tab,
        'class' => 'quicktabs_tabpage',
      ));
      $output .= '<div' . $attributes . '>' . quicktabs_render_tabpage($quicktabs['tabs'][$active_tab]) . '</div>';
    }

    // We need page preprocessing to populate Drupal.quicktabs.scripts when js aggregation is on.
    quicktabs_has_rendered_ajax_tab(TRUE);
  }
  else {

    // Render all tabpgages.
    foreach ($quicktabs['tabs'] as $key => $tab) {
      $attributes = drupal_attributes(array(
        'id' => 'quicktabs_tabpage_' . $quicktabs['machine_name'] . '_' . $key,
        'class' => 'quicktabs_tabpage' . ($active_tab == $key ? '' : ' quicktabs-hide'),
      ));
      $tab_content = isset($tab['rendered']) ? $tab['rendered'] : quicktabs_render_tabpage($tab);
      $output .= '<div' . $attributes . '>' . $tab_content . '</div>';
    }
  }
  $output .= '</div></div>';
  return $output;
}