'admin/settings/tabs', 'title' => t('Tabs'), 'description' => t('Configuration for tabs'), 'callback' => 'drupal_get_form', 'callback arguments' => array('tabs_admin_settings') ); } else { tabs_load(); } return $items; } /** * Menu callback for admin settings. */ function tabs_admin_settings() { $form = array(); $form['tabs_slide'] = array( '#type' => 'radios', '#title' => t('Slide effect'), '#description' => t('Apply slide effect when changing tabs.'), '#default_value' => variable_get('tabs_slide', 0), '#options' => array(t('disabled'), t('enabled')), ); $form['tabs_fade'] = array( '#type' => 'radios', '#title' => t('Fade effect'), '#description' => t('Apply fade effect when changing tabs.'), '#default_value' => variable_get('tabs_fade', 0), '#options' => array(t('disabled'), t('enabled')), ); $form['tabs_speed'] = array( '#type' => 'radios', '#title' => t('Effect speed'), '#description' => t('Speed at which to apply effects.'), '#default_value' => variable_get('tabs_speed', 'slow'), '#options' => array('slow' => t('slow'), 'fast' => t('fast')), ); $form['tabs_auto_height'] = array( '#type' => 'radios', '#title' => t('Fixed height'), '#description' => t('Set all tabs to have the height of the tallest tab. If not enabled, content will adjust to fit when tabs are changed. Note: fixed height is not fully compatible with slide and fade effects.'), '#default_value' => variable_get('tabs_auto_height', 0), '#options' => array(t('disabled'), t('enabled')), ); $form = system_settings_form($form); return $form; } function tabs_process_tabset($element) { static $names = array(); // Ensure name is unique. $i = 0; // Assign a name, reading from the first parent (the key of this tabset element). $name = $element['#tabset_name'] = ($element['#tabset_name'] ? $element['#tabset_name'] : (isset($element['#parents']) && count($element['#parents']) ? $element['#parents'][0] : 'tabset')); // In case we have duplicate names... while (in_array($element['#tabset_name'], $names)) { $element['#tabset_name'] = $name . $i; $i++; } $names[] = $element['#tabset_name']; $index = 1; // Sort the elements by weight. uasort($element, "_element_sort"); foreach (element_children($element) as $key) { if (isset($element[$key]['#type']) && $element[$key]['#type'] == 'tabpage') { $element[$key]['#tabset_name'] = $element['#tabset_name']; $element[$key]['#index'] = $index++; } } return $element; } function theme_tabset($element) { $output .= '
'; $output .= ''; $output .= $element['#children']; $output .= '
'; return $output; } function theme_tabpage($element) { $output .='
'; $output .= '

'. $element['#title'] .'

'; $output .= $element['#content'] . $element['#children']; $output .='
'; return $output; } /** * Add required js and css files. */ function tabs_load() { static $loaded = FALSE; if (!$loaded) { $path = drupal_get_path('module', 'tabs'); jstools_add_js( array( $path . '/jquery.tabs.pack.js', drupal_get_path('module', 'jstools') . '/jquery.history_remote.min.js', $path . '/tabs.js', ) ); drupal_add_js(array('tabs' => array('slide' => (bool) variable_get('tabs_slide', 0), 'fade' => (bool) variable_get('tabs_fade', 0), 'speed' => variable_get('tabs_speed', 'slow'), 'auto_height' => (bool) variable_get('tabs_auto_height', 0))), 'setting'); drupal_add_css($path . '/drupal-tabs.css'); drupal_add_css($path . '/tabs.css'); drupal_set_html_head(' '); $loaded = TRUE; } } /** * Render a tabset 'manually' (when not rendering as part of a regular form render). */ function tabs_render($form) { return drupal_render(form_builder('tabset', $form)); } /** * Implementation of hook_elements(). */ function tabs_elements() { $type = array(); $type['tabset'] = array('#process' => array('tabs_process_tabset' => array())); $type['tabpage'] = array('#content' => ''); return $type; }