// $Id: vertical-tabs.js,v 1.7 2009/08/31 05:51:08 dries Exp $
(function ($) {
/**
* This script transforms a set of fieldsets into a stack of vertical
* tabs. Another tab pane can be selected by clicking on the respective
* tab.
*
* Each tab may have a summary which can be updated by another
* script. For that to work, each fieldset has an associated
* 'verticalTabCallback' (with jQuery.data() attached to the fieldset),
* which is called every time the user performs an update to a form
* element inside the tab pane.
*/
Drupal.behaviors.verticalTabs = {
attach: function (context) {
$('.vertical-tabs-panes', context).once('vertical-tabs', function () {
var focusID = $(':hidden.vertical-tabs-active-tab', this).val();
var tabfocus; // Refactoring names - too much "focus"
// Create the tab column.
var tablist = $('
');
$(this).wrap('').before(tablist);
// Transform each fieldset into a tab.
$('> fieldset', this).each(function () {
var vtab = new Drupal.verticalTab({
title: $('> legend', this).text(),
fieldset: $(this)
});
tablist.append(vtab.item);
$(this)
.removeClass('collapsible collapsed')
.addClass('vertical-tabs-pane')
.data('verticalTab', vtab);
if (this.id == focusID) {
tabfocus = $(this);
}
});
$('> li:first', tablist).addClass('first');
$('> li:last', tablist).addClass('last');
if (!tabfocus) {
tabfocus = $('> .vertical-tabs-pane:first', this);
}
tabfocus.data('verticalTab').focus();
});
}
};
/**
* The vertical tab object represents a single tab within a tab group.
*
* @param settings
* An object with the following keys:
* - title: The name of the tab.
* - fieldset: The jQuery object of the fieldset that is the tab pane.
*/
Drupal.verticalTab = function (settings) {
var self = this;
$.extend(this, settings, Drupal.theme('verticalTab', settings));
this.link.click(function () {
self.focus();
return false;
});
// Keyboard events added:
// Pressing the Enter key will open the tab pane
this.link.keydown(function(event) {
if (event.keyCode == 13) {
self.focus();
// Set focus on the first input field of the visible fieldset/tab pane
$("fieldset.vertical-tabs-pane :file").css({background:"yellow"});
$("fieldset.vertical-tabs-pane :input:visible:enabled:first").focus();
location.hash = "#edit-upload";
return false;
}
});
// Pressing the Enter key lets you leave the tab again
this.fieldset.keydown(function(event) {
// Enter key should not trigger inside