diff --git a/core/misc/collapse.js b/core/misc/collapse.js index 767325e..4d408f2 100644 --- a/core/misc/collapse.js +++ b/core/misc/collapse.js @@ -21,6 +21,7 @@ // Expand details 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 (this.$node.find('.error' + anchor).length) { this.$node.attr('open', true); } @@ -140,6 +141,32 @@ } }; + /** + * Set all hash links that target details to expand them. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Attaches behavior for the details element. + */ + Drupal.behaviors.watchHashLinks = { + attach: function (context) { + $(context).on('click', $('a[href^="#"]').not('.vertical-tabs__menu-item.is-selected a'), function(event) { + var $item = $(event.target.hash); + + if (event.target.hash != '#' && $item.length) { + $item.parents('details').attr('open', true).find('> summary').attr({ + 'aria-expanded': true, + 'aria-pressed': true + }); + $item.parents('.vertical-tabs__pane').each(function(index, pane) { + $(pane).data('verticalTab').focus(); + }); + } + }); + } + }; + // Expose constructor in the public space. Drupal.CollapsibleDetails = CollapsibleDetails;