Chris@0: /**
Chris@0: * DO NOT EDIT THIS FILE.
Chris@0: * See the following change record for more information,
Chris@0: * https://www.drupal.org/node/2815083
Chris@0: * @preserve
Chris@0: **/
Chris@0:
Chris@0: (function ($, Modernizr, Drupal) {
Chris@0: function CollapsibleDetails(node) {
Chris@0: this.$node = $(node);
Chris@0: this.$node.data('details', this);
Chris@0:
Chris@17: var anchor = window.location.hash && window.location.hash !== '#' ? ', ' + window.location.hash : '';
Chris@0: if (this.$node.find('.error' + anchor).length) {
Chris@0: this.$node.attr('open', true);
Chris@0: }
Chris@0:
Chris@0: this.setupSummary();
Chris@0:
Chris@0: this.setupLegend();
Chris@0: }
Chris@0:
Chris@0: $.extend(CollapsibleDetails, {
Chris@0: instances: []
Chris@0: });
Chris@0:
Chris@0: $.extend(CollapsibleDetails.prototype, {
Chris@0: setupSummary: function setupSummary() {
Chris@0: this.$summary = $('');
Chris@0: this.$node.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this)).trigger('summaryUpdated');
Chris@0: },
Chris@0: setupLegend: function setupLegend() {
Chris@0: var $legend = this.$node.find('> summary');
Chris@0:
Chris@0: $('').append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show')).prependTo($legend).after(document.createTextNode(' '));
Chris@0:
Chris@0: $('').attr('href', '#' + this.$node.attr('id')).prepend($legend.contents()).appendTo($legend);
Chris@0:
Chris@0: $legend.append(this.$summary).on('click', $.proxy(this.onLegendClick, this));
Chris@0: },
Chris@0: onLegendClick: function onLegendClick(e) {
Chris@0: this.toggle();
Chris@0: e.preventDefault();
Chris@0: },
Chris@0: onSummaryUpdated: function onSummaryUpdated() {
Chris@0: var text = $.trim(this.$node.drupalGetSummary());
Chris@0: this.$summary.html(text ? ' (' + text + ')' : '');
Chris@0: },
Chris@0: toggle: function toggle() {
Chris@0: var _this = this;
Chris@0:
Chris@0: var isOpen = !!this.$node.attr('open');
Chris@0: var $summaryPrefix = this.$node.find('> summary span.details-summary-prefix');
Chris@0: if (isOpen) {
Chris@0: $summaryPrefix.html(Drupal.t('Show'));
Chris@0: } else {
Chris@0: $summaryPrefix.html(Drupal.t('Hide'));
Chris@0: }
Chris@0:
Chris@0: setTimeout(function () {
Chris@0: _this.$node.attr('open', !isOpen);
Chris@0: }, 0);
Chris@0: }
Chris@0: });
Chris@0:
Chris@0: Drupal.behaviors.collapse = {
Chris@0: attach: function attach(context) {
Chris@0: if (Modernizr.details) {
Chris@0: return;
Chris@0: }
Chris@0: var $collapsibleDetails = $(context).find('details').once('collapse').addClass('collapse-processed');
Chris@0: if ($collapsibleDetails.length) {
Chris@0: for (var i = 0; i < $collapsibleDetails.length; i++) {
Chris@0: CollapsibleDetails.instances.push(new CollapsibleDetails($collapsibleDetails[i]));
Chris@0: }
Chris@0: }
Chris@0: }
Chris@0: };
Chris@0:
Chris@0: var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e, $target) {
Chris@0: $target.parents('details').not('[open]').find('> summary').trigger('click');
Chris@0: };
Chris@0:
Chris@0: $('body').on('formFragmentLinkClickOrHashChange.details', handleFragmentLinkClickOrHashChange);
Chris@0:
Chris@0: Drupal.CollapsibleDetails = CollapsibleDetails;
Chris@0: })(jQuery, Modernizr, Drupal);