Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, Modernizr, Drupal) {
|
Chris@0
|
9 function CollapsibleDetails(node) {
|
Chris@0
|
10 this.$node = $(node);
|
Chris@0
|
11 this.$node.data('details', this);
|
Chris@0
|
12
|
Chris@17
|
13 var anchor = window.location.hash && window.location.hash !== '#' ? ', ' + window.location.hash : '';
|
Chris@0
|
14 if (this.$node.find('.error' + anchor).length) {
|
Chris@0
|
15 this.$node.attr('open', true);
|
Chris@0
|
16 }
|
Chris@0
|
17
|
Chris@0
|
18 this.setupSummary();
|
Chris@0
|
19
|
Chris@0
|
20 this.setupLegend();
|
Chris@0
|
21 }
|
Chris@0
|
22
|
Chris@0
|
23 $.extend(CollapsibleDetails, {
|
Chris@0
|
24 instances: []
|
Chris@0
|
25 });
|
Chris@0
|
26
|
Chris@0
|
27 $.extend(CollapsibleDetails.prototype, {
|
Chris@0
|
28 setupSummary: function setupSummary() {
|
Chris@0
|
29 this.$summary = $('<span class="summary"></span>');
|
Chris@0
|
30 this.$node.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this)).trigger('summaryUpdated');
|
Chris@0
|
31 },
|
Chris@0
|
32 setupLegend: function setupLegend() {
|
Chris@0
|
33 var $legend = this.$node.find('> summary');
|
Chris@0
|
34
|
Chris@0
|
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(' '));
|
Chris@0
|
36
|
Chris@0
|
37 $('<a class="details-title"></a>').attr('href', '#' + this.$node.attr('id')).prepend($legend.contents()).appendTo($legend);
|
Chris@0
|
38
|
Chris@0
|
39 $legend.append(this.$summary).on('click', $.proxy(this.onLegendClick, this));
|
Chris@0
|
40 },
|
Chris@0
|
41 onLegendClick: function onLegendClick(e) {
|
Chris@0
|
42 this.toggle();
|
Chris@0
|
43 e.preventDefault();
|
Chris@0
|
44 },
|
Chris@0
|
45 onSummaryUpdated: function onSummaryUpdated() {
|
Chris@0
|
46 var text = $.trim(this.$node.drupalGetSummary());
|
Chris@0
|
47 this.$summary.html(text ? ' (' + text + ')' : '');
|
Chris@0
|
48 },
|
Chris@0
|
49 toggle: function toggle() {
|
Chris@0
|
50 var _this = this;
|
Chris@0
|
51
|
Chris@0
|
52 var isOpen = !!this.$node.attr('open');
|
Chris@0
|
53 var $summaryPrefix = this.$node.find('> summary span.details-summary-prefix');
|
Chris@0
|
54 if (isOpen) {
|
Chris@0
|
55 $summaryPrefix.html(Drupal.t('Show'));
|
Chris@0
|
56 } else {
|
Chris@0
|
57 $summaryPrefix.html(Drupal.t('Hide'));
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 setTimeout(function () {
|
Chris@0
|
61 _this.$node.attr('open', !isOpen);
|
Chris@0
|
62 }, 0);
|
Chris@0
|
63 }
|
Chris@0
|
64 });
|
Chris@0
|
65
|
Chris@0
|
66 Drupal.behaviors.collapse = {
|
Chris@0
|
67 attach: function attach(context) {
|
Chris@0
|
68 if (Modernizr.details) {
|
Chris@0
|
69 return;
|
Chris@0
|
70 }
|
Chris@0
|
71 var $collapsibleDetails = $(context).find('details').once('collapse').addClass('collapse-processed');
|
Chris@0
|
72 if ($collapsibleDetails.length) {
|
Chris@0
|
73 for (var i = 0; i < $collapsibleDetails.length; i++) {
|
Chris@0
|
74 CollapsibleDetails.instances.push(new CollapsibleDetails($collapsibleDetails[i]));
|
Chris@0
|
75 }
|
Chris@0
|
76 }
|
Chris@0
|
77 }
|
Chris@0
|
78 };
|
Chris@0
|
79
|
Chris@0
|
80 var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e, $target) {
|
Chris@0
|
81 $target.parents('details').not('[open]').find('> summary').trigger('click');
|
Chris@0
|
82 };
|
Chris@0
|
83
|
Chris@0
|
84 $('body').on('formFragmentLinkClickOrHashChange.details', handleFragmentLinkClickOrHashChange);
|
Chris@0
|
85
|
Chris@0
|
86 Drupal.CollapsibleDetails = CollapsibleDetails;
|
Chris@0
|
87 })(jQuery, Modernizr, Drupal); |