diff options
Diffstat (limited to 'core/misc/collapse.js')
-rw-r--r-- | core/misc/collapse.js | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/core/misc/collapse.js b/core/misc/collapse.js index 3c09ab18b77e..bf312b97cea4 100644 --- a/core/misc/collapse.js +++ b/core/misc/collapse.js @@ -9,21 +9,19 @@ function CollapsibleDetails(node) { this.$node = $(node); this.$node.data('details', this); + var anchor = window.location.hash && window.location.hash !== '#' ? ", ".concat(window.location.hash) : ''; - var anchor = window.location.hash && window.location.hash !== '#' ? ', ' + window.location.hash : ''; - if (this.$node.find('.error' + anchor).length) { + if (this.$node.find(".error".concat(anchor)).length) { this.$node.attr('open', true); } this.setupSummary(); - this.setupLegend(); } $.extend(CollapsibleDetails, { instances: [] }); - $.extend(CollapsibleDetails.prototype, { setupSummary: function setupSummary() { this.$summary = $('<span class="summary"></span>'); @@ -31,11 +29,8 @@ }, setupLegend: function setupLegend() { var $legend = this.$node.find('> summary'); - $('<span class="details-summary-prefix visually-hidden"></span>').append(this.$node.attr('open') ? Drupal.t('Hide') : Drupal.t('Show')).prependTo($legend).after(document.createTextNode(' ')); - - $('<a class="details-title"></a>').attr('href', '#' + this.$node.attr('id')).prepend($legend.contents()).appendTo($legend); - + $('<a class="details-title"></a>').attr('href', "#".concat(this.$node.attr('id'))).prepend($legend.contents()).appendTo($legend); $legend.append(this.$summary).on('click', $.proxy(this.onLegendClick, this)); }, onLegendClick: function onLegendClick(e) { @@ -44,13 +39,14 @@ }, onSummaryUpdated: function onSummaryUpdated() { var text = $.trim(this.$node.drupalGetSummary()); - this.$summary.html(text ? ' (' + text + ')' : ''); + this.$summary.html(text ? " (".concat(text, ")") : ''); }, 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 { @@ -62,13 +58,14 @@ }, 0); } }); - Drupal.behaviors.collapse = { attach: function attach(context) { if (Modernizr.details) { return; } + var $collapsibleDetails = $(context).find('details').once('collapse').addClass('collapse-processed'); + if ($collapsibleDetails.length) { for (var i = 0; i < $collapsibleDetails.length; i++) { CollapsibleDetails.instances.push(new CollapsibleDetails($collapsibleDetails[i])); @@ -82,6 +79,5 @@ }; $('body').on('formFragmentLinkClickOrHashChange.details', handleFragmentLinkClickOrHashChange); - Drupal.CollapsibleDetails = CollapsibleDetails; })(jQuery, Modernizr, Drupal);
\ No newline at end of file |