'Tabs',
'description' => 'Configuration for tabs',
'page callback' => 'drupal_get_form',
'page arguments' => array('tabs_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'tabs.admin.inc',
);
return $items;
}
/**
* Implements of hook_theme()
*/
function tabs_theme() {
return array(
'tabset' => array(
'render element' => 'element',
'file' => 'tabs.theme.inc',
),
'tabpage' => array(
'render element' => 'element',
'file' => 'tabs.theme.inc',
),
);
}
/**
* Process a tabset prior to rendering.
*
* Passes the tabset element through drupal_alter() so that modules can implement hook_tabs_alter().
*/
function tabs_pre_render_tabset($element) {
tabs_load();
// Assign a name, reading from the first parent (the key of this tabset element).
$name = $element['#tabset_name'] = drupal_clean_css_identifier(isset($element['#tabset_name']) && $element['#tabset_name'] ? $element['#tabset_name'] : (isset($element['#parents']) && count($element['#parents']) ? $element['#parents'][0] : 'tabset'));
// Add class.
if (!isset($element['#attributes'])) {
$element['#attributes'] = array();
}
$element['#attributes']['class'] = (isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' ' : '') . 'drupal-tabs js-hide' . (isset($element['#tabs_navigation']) && $element['#tabs_navigation'] ? ' tabs-navigation' : '');
// Allow other modules to alter the tabset before further processing.
drupal_alter('tabs', $element);
foreach (element_children($element) as $index => $key) {
if (isset($element[$key]['#type']) && $element[$key]['#type'] == 'tabpage') {
if (!isset($element[$key]['#content'])) {
$element[$key]['#content'] = '';
}
if (isset($element[$key]['#description']) && $element[$key]['#description']) {
$element[$key]['#content'] = '
' . $element[$key]['#description'] . '
' . $element[$key]['#content'];
unset($element[$key]['#description']);
}
$is_ajax = isset($element[$key]['#ajax_url']) && $element[$key]['#ajax_url'];
// Unset any empty tabs.
$content = trim($element[$key]['#content']);
if (!$is_ajax && empty($content) && !element_children($element[$key])) {
unset($element[$key]);
continue;
}
$element[$key]['#tabset_name'] = $element['#tabset_name'];
// If no tab_name is set and we use descriptive titles, use one.
if ((!isset($element[$key]['#tab_name']) || empty($element[$key]['#tab_name'])) && variable_get('tabs_descriptive_urls', 0)) {
// Clean out invalid characters.
$clean_title = preg_replace('/[^\sa-zA-Z0-9\ ]+/ ', ' ', $element[$key]['#title']);
$element[$key]['#tab_name'] = strtolower($clean_title);
}
// If the tab_name is still empty, set one.
if (!isset($element[$key]['#tab_name']) || empty($element[$key]['#tab_name'])) {
$element[$key]['#tab_name'] = $element['#tabset_name'] . '-tab-' . $index;
}
$element[$key]['#tab_name'] = drupal_clean_css_identifier($element[$key]['#tab_name']);
if (!isset($element[$key]['#attributes'])) {
$element[$key]['#attributes'] = array();
}
// If we are loading via AJAX we need to add a title attribute and set the url to the AJAX path.
if ($is_ajax) {
$element[$key]['#attributes']['#title'] = $element[$key]['#tab_name'];
$element[$key]['#url'] = $element[$key]['#ajax_url'];
}
// Otherwise we use a hash.
else {
$element[$key]['#url'] = '#' . $element[$key]['#tab_name'];
}
$element[$key]['#attributes']['class'] = (isset($element[$key]['#attributes']['class']) ? $element[$key]['#attributes']['class'] . ' ' : '') . $element[$key]['#tab_name'];
// Add the ui-tabs-selected class if this tab is selected.
if (isset($element[$key]['#selected']) && $element[$key]['#selected']) {
$element[$key]['#attributes']['class'] .= ' ui-tabs-selected';
}
$element[$key]['#index'] = $index;
}
}
return $element;
}
/**
* Add required js and css files.
*/
function tabs_load() {
static $loaded = FALSE;
if (!$loaded) {
$tabs_speed = variable_get('tabs_speed', 'fast');
if (is_numeric($tabs_speed)) {
$tabs_speed = (int) $tabs_speed;
}
$path = drupal_get_path('module', 'tabs');
drupal_add_library('system', 'ui.tabs');
drupal_add_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' => $tabs_speed,
'auto_height' => (bool) variable_get('tabs_auto_height', 0),
'next_text' => variable_get('tabs_nav_next', t('next')),
'previous_text' => variable_get('tabs_nav_prev', t('previous')),
'navigation_titles' => (bool) variable_get('tabs_navigation_titles', 0),
)
),
'setting'
);
drupal_add_css($path . '/drupal-tabs.css');
$loaded = TRUE;
}
}
/**
* Implements of hook_element_info().
*/
function tabs_element_info() {
$type = array();
$type['tabset'] = array(
'#tabs_navigation' => variable_get('tabs_navigation', 0) ? TRUE : FALSE,
'#pre_render' => array('tabs_pre_render_tabset'),
'#theme' => array('tabset'),
);
$type['tabpage'] = array(
'#theme' => array('tabpage'),
);
return $type;
}