2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Modernizr, Drupal) {
9 function CollapsibleDetails(node) {
11 this.$node.data('details', this);
13 var anchor = window.location.hash && window.location.hash !== '#' ? ', ' + window.location.hash : '';
14 if (this.$node.find('.error' + anchor).length) {
15 this.$node.attr('open', true);
23 $.extend(CollapsibleDetails, {
27 $.extend(CollapsibleDetails.prototype, {
28 setupSummary: function setupSummary() {
29 this.$summary = $('<span class="summary"></span>');
30 this.$node.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this)).trigger('summaryUpdated');
32 setupLegend: function setupLegend() {
33 var $legend = this.$node.find('> summary');
35 $('<span class="details-summary-prefix visually-hidden"></span>').append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show')).prependTo($legend).after(document.createTextNode(' '));
37 $('<a class="details-title"></a>').attr('href', '#' + this.$node.attr('id')).prepend($legend.contents()).appendTo($legend);
39 $legend.append(this.$summary).on('click', $.proxy(this.onLegendClick, this));
41 onLegendClick: function onLegendClick(e) {
45 onSummaryUpdated: function onSummaryUpdated() {
46 var text = $.trim(this.$node.drupalGetSummary());
47 this.$summary.html(text ? ' (' + text + ')' : '');
49 toggle: function toggle() {
52 var isOpen = !!this.$node.attr('open');
53 var $summaryPrefix = this.$node.find('> summary span.details-summary-prefix');
55 $summaryPrefix.html(Drupal.t('Show'));
57 $summaryPrefix.html(Drupal.t('Hide'));
60 setTimeout(function () {
61 _this.$node.attr('open', !isOpen);
66 Drupal.behaviors.collapse = {
67 attach: function attach(context) {
68 if (Modernizr.details) {
71 var $collapsibleDetails = $(context).find('details').once('collapse').addClass('collapse-processed');
72 if ($collapsibleDetails.length) {
73 for (var i = 0; i < $collapsibleDetails.length; i++) {
74 CollapsibleDetails.instances.push(new CollapsibleDetails($collapsibleDetails[i]));
80 var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e, $target) {
81 $target.parents('details').not('[open]').find('> summary').trigger('click');
84 $('body').on('formFragmentLinkClickOrHashChange.details', handleFragmentLinkClickOrHashChange);
86 Drupal.CollapsibleDetails = CollapsibleDetails;
87 })(jQuery, Modernizr, Drupal);