website/core/misc/collapsedfb4.js
2023-09-30 09:40:37 +02:00

62 lines
No EOL
2.4 KiB
JavaScript

/**
* DO NOT EDIT THIS FILE.
* See the following change record for more information,
* https://www.drupal.org/node/2815083
* @preserve
**/
(function ($, Modernizr, Drupal) {
function CollapsibleDetails(node) {
this.$node = $(node);
this.$node.data('details', this);
var anchor = window.location.hash && window.location.hash !== '#' ? ", ".concat(window.location.hash) : '';
if (this.$node.find(".error".concat(anchor)).length) {
this.$node.attr('open', true);
}
this.setupSummaryPolyfill();
}
$.extend(CollapsibleDetails, {
instances: []
});
$.extend(CollapsibleDetails.prototype, {
setupSummaryPolyfill: function setupSummaryPolyfill() {
var $summary = this.$node.find('> summary');
$summary.attr('tabindex', '-1');
$('<span class="details-summary-prefix visually-hidden"></span>').append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show')).prependTo($summary).after(document.createTextNode(' '));
$('<a class="details-title"></a>').attr('href', "#".concat(this.$node.attr('id'))).prepend($summary.contents()).appendTo($summary);
$summary.append(this.$summary).on('click', $.proxy(this.onSummaryClick, this));
},
onSummaryClick: function onSummaryClick(e) {
this.toggle();
e.preventDefault();
},
toggle: function toggle() {
var _this = this;
var isOpen = !!this.$node.attr('open');
var $summaryPrefix = this.$node.find('> summary span.details-summary-prefix');
if (isOpen) {
$summaryPrefix.html(Drupal.t('Show'));
} else {
$summaryPrefix.html(Drupal.t('Hide'));
}
setTimeout(function () {
_this.$node.attr('open', !isOpen);
}, 0);
}
});
Drupal.behaviors.collapse = {
attach: function attach(context) {
if (Modernizr.details) {
return;
}
once('collapse', 'details', context).forEach(function (detail) {
detail.classList.add('collapse-processed');
CollapsibleDetails.instances.push(new CollapsibleDetails(detail));
});
}
};
var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e, $target) {
$target.parents('details').not('[open]').find('> summary').trigger('click');
};
$('body').on('formFragmentLinkClickOrHashChange.details', handleFragmentLinkClickOrHashChange);
Drupal.CollapsibleDetails = CollapsibleDetails;
})(jQuery, Modernizr, Drupal);