diff --git a/js/misc/_collapse.js b/js/misc/_collapse.js index 66b754f..ed37fc5 100644 --- a/js/misc/_collapse.js +++ b/js/misc/_collapse.js @@ -30,13 +30,14 @@ Drupal.collapseScrollIntoView = function (node) { Drupal.behaviors.collapse = { attach: function (context, settings) { - $('fieldset.collapsible', context).once('collapse', function () { - var $fieldset = $(this); + $('fieldset.collapsible > .panel-collapse', context).once('collapse', function () { + var $fieldset = $(this).parent(), + $body = $(this); // Expand fieldset if there are errors inside, or if it contains an // element that is targeted by the URI fragment identifier. var anchor = location.hash && location.hash != '#' ? ', ' + location.hash : ''; if ($fieldset.find('.error' + anchor).length) { - $fieldset.removeClass('collapsed'); + $body.removeClass('collapsed'); } var summary = $(''); @@ -52,7 +53,7 @@ Drupal.behaviors.collapse = { var $legend = $('> legend .fieldset-legend', this); $('') - .append($fieldset.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide')) + .append($body.hasClass('collapsed') ? Drupal.t('Show') : Drupal.t('Hide')) .prependTo($legend); $fieldset.find('[data-toggle=collapse]').on('click', function (e) { @@ -60,24 +61,22 @@ Drupal.behaviors.collapse = { }); // Bind Bootstrap events with Drupal core events. - $fieldset + $body .append(summary) .on('show.bs.collapse', function () { - $fieldset - .removeClass('collapsed') - .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Hide')); + $body.removeClass('collapsed'); + $fieldset.find('> legend span.fieldset-legend-prefix').html(Drupal.t('Hide')); }) .on('shown.bs.collapse', function () { - $fieldset.trigger({ type: 'collapsed', value: false }); + $body.trigger({ type: 'collapsed', value: false }); Drupal.collapseScrollIntoView($fieldset.get(0)); }) .on('hide.bs.collapse', function () { - $fieldset - .addClass('collapsed') - .find('> legend span.fieldset-legend-prefix').html(Drupal.t('Show')); + $body.addClass('collapsed'); + $fieldset.find('> legend span.fieldset-legend-prefix').html(Drupal.t('Show')); }) .on('hidden.bs.collapse', function () { - $fieldset.trigger({ type: 'collapsed', value: true }); + $body.trigger({ type: 'collapsed', value: true }); }); }); } diff --git a/templates/bootstrap/bootstrap-panel.tpl.php b/templates/bootstrap/bootstrap-panel.tpl.php index 656fa20..3035e31 100644 --- a/templates/bootstrap/bootstrap-panel.tpl.php +++ b/templates/bootstrap/bootstrap-panel.tpl.php @@ -12,7 +12,7 @@ - + @@ -21,7 +21,7 @@ -
+
diff --git a/templates/bootstrap/bootstrap-panel.vars.php b/templates/bootstrap/bootstrap-panel.vars.php index 2317077..87de5e1 100644 --- a/templates/bootstrap/bootstrap-panel.vars.php +++ b/templates/bootstrap/bootstrap-panel.vars.php @@ -37,22 +37,27 @@ function bootstrap_preprocess_bootstrap_panel(&$variables) { $variables['collapsed'] = FALSE; if (isset($element['#collapsed'])) { $variables['collapsed'] = $element['#collapsed']; + // Remove collapsed class since we only want it to apply to the fieldset + // body element. + if ($index = array_search('collapsed', $attributes['class'])) { + unset($attributes['class'][$index]); + $attributes['class'] = array_values($attributes['class']); + } } // Force grouped fieldsets to not be collapsible (for vertical tabs). if (!empty($element['#group'])) { $variables['collapsible'] = FALSE; $variables['collapsed'] = FALSE; } - // Collapsible elements need an ID, so generate one if necessary. - if (!isset($attributes['id']) && $variables['collapsible']) { + + // Generate an ID for the fieldset wrapper and body elements. + if (!isset($attributes['id'])) { $attributes['id'] = drupal_html_id('bootstrap-panel'); } + $variables['body_id'] = drupal_html_id($attributes['id'] . '--body'); - // Set the target if the element has an id. - $variables['target'] = NULL; - if (isset($attributes['id'])) { - $variables['target'] = '#' . $attributes['id'] . ' > .collapse'; - } + // Set the target to the fieldset body element. + $variables['target'] = '#' . $variables['body_id']; // Build the panel content. $variables['content'] = $element['#children'];