diff --git a/misc/vertical-tabs.js b/misc/vertical-tabs.js index 82dcd2c..064b142 100644 --- a/misc/vertical-tabs.js +++ b/misc/vertical-tabs.js @@ -38,6 +38,34 @@ Drupal.behaviors.verticalTabs = { $(this) .removeClass('collapsible collapsed') .addClass('vertical-tabs-pane') + // Override the default state:visible handler. + .bind('state:visible', function(e) { + if (e.trigger) { + // Get the id of the fieldset. + var id = $(e.target).closest('.form-item, .form-submit, .form-wrapper').attr('id'); + if (id) { + // Get the corresponding vertical_tab button. + var vertical_tab_button = $('li#vertical-tab-button-' + id); + if (vertical_tab_button) { + // Hide or show that instead of the fieldset. + vertical_tab_button[e.value ? 'show' : 'hide'](); + // If the vertical_tab_button was currently selected, select + // the one above (or below if there is none above). + if (!e.value && vertical_tab_button.hasClass('selected')) { + var prev_button = vertical_tab_button.prev(); + if (prev_button.length != 0) { + prev_button.children().click(); + } + else { + vertical_tab_button.next().children().click(); + } + } + // Don't bubble this up to the default handler. + return false; + } + } + } + }) .data('verticalTab', vertical_tab); if (this.id == focusID) { tab_focus = $(this); @@ -193,7 +221,7 @@ Drupal.verticalTab.prototype = { */ Drupal.theme.prototype.verticalTab = function (settings) { var tab = {}; - tab.item = $('
  • ') + tab.item = $('
  • ') .append(tab.link = $('') .append(tab.title = $('').text(settings.title)) .append(tab.summary = $('')