diff --git a/core/misc/vertical-tabs.js b/core/misc/vertical-tabs.js index c7ad2fd..6ed4ceb 100644 --- a/core/misc/vertical-tabs.js +++ b/core/misc/vertical-tabs.js @@ -43,6 +43,7 @@ var $this = $(this).addClass('vertical-tabs__panes'); var focusID = $this.find(':hidden.vertical-tabs__active-tab').val(); var tab_focus; + var tab_pane_set = $(this); // Check if there are some details that can be converted to // vertical-tabs. @@ -53,7 +54,19 @@ // Create the tab column. var tab_list = $(''); - $this.wrap('
').before(tab_list); + tab_pane_set + .wrap('
') + .before(tab_list) + // If there are no visible tabs panes, hide the whole vertical-tabs area. + .bind('updateTabPaneSet', function() { + var tab_set = tab_pane_set.parent(); + tab_set.show(); + var $fieldsets = $('> fieldset:visible', this); + if ($fieldsets.length == 0) { + tab_set.hide(); + } + }); + // Transform each details into a tab. $details.each(function () { @@ -69,6 +82,26 @@ // the style won't apply to them if prop() is used. .attr('open', true) .addClass('vertical-tabs__pane') + // Override the default state:visible handler. + .bind('state:visible', function(e) { + if (e.target == this && e.trigger) { + // Get the id of the fieldset. + var id = $(e.target).closest('.form-item, .form-submit, .form-wrapper').attr('id'); + if (id) { + // Hide or show that instead of the fieldset. + if (!e.value) { + vertical_tab.tabHide().updateSummary(); + } + else if(e.value) { + vertical_tab.item.show(); + vertical_tab.updateSummary(); + } + tab_pane_set.trigger('updateTabPaneSet'); + // Don't bubble this up to the default handler. + e.preventDefault(); + } + } + }) .data('verticalTab', vertical_tab); if (this.id === focusID) { tab_focus = $that;