PageSourceSearch

https://www.csbs.org/core/misc/details-summarized-content.js?v=11.4.6

js csbs.org collected 2026-09-24 17:40:04 UTC 2,949 bytes, 105 lines download raw bytes

1/**
2 * @file
3 * Adds a summary of a details element's contents to its summary element.
4 */
5(($, Drupal) => {
6  /**
7   * The DetailsSummarizedContent object represents a single details element.
8   *
9   * @constructor Drupal.DetailsSummarizedContent
10   *
11   * @param {HTMLElement} node
12   *   A details element, the summary of which may have supplemental text.
13   *   The supplemental text summarizes the details element's contents.
14   */
15  function DetailsSummarizedContent(node) {
16    this.$node = $(node);
17    this.setupSummary();
18  }
19
20  $.extend(
21    DetailsSummarizedContent,
22    /** @lends Drupal.DetailsSummarizedContent */ {
23      /**
24       * Holds references to instantiated DetailsSummarizedContent objects.
25       *
26       * @type {Array.<Drupal.DetailsSummarizedContent>}
27       */
28      instances: [],
29    },
30  );
31
32  $.extend(
33    DetailsSummarizedContent.prototype,
34    /** @lends Drupal.DetailsSummarizedContent# */ {
35      /**
36       * Initialize and setup summary events and markup.
37       *
38       * @fires event:summaryUpdated
39       *
40       * @listens event:summaryUpdated
41       */
42      setupSummary() {
43        this.$detailsSummarizedContentWrapper = $(
44          Drupal.theme('detailsSummarizedContentWrapper'),
45        );
46        this.$node
47          .on('summaryUpdated', this.onSummaryUpdated.bind(this))
48          .trigger('summaryUpdated')
49          .find('> summary')
50          .append(this.$detailsSummarizedContentWrapper);
51      },
52
53      /**
54       * Update summary.
55       */
56      onSummaryUpdated() {
57        const text = this.$node.drupalGetSummary();
58        this.$detailsSummarizedContentWrapper.html(
59          Drupal.theme('detailsSummarizedContentText', text),
60        );
61      },
62    },
63  );
64
65  /**
66   * Adds a summary of a details element's contents to its summary element.
67   *
68   * @type {Drupal~behavior}
69   *
70   * @prop {Drupal~behaviorAttach} attach
71   *   Attaches behavior for the details element.
72   */
73  Drupal.behaviors.detailsSummary = {
74    attach(context) {
75      DetailsSummarizedContent.instances =
76        DetailsSummarizedContent.instances.concat(
77          once('details', 'details', context).map(
78            (details) => new DetailsSummarizedContent(details),
79          ),
80        );
81    },
82  };
83
84  Drupal.DetailsSummarizedContent = DetailsSummarizedContent;
85
86  /**
87   * The element containing a wrapper for summarized details content.
88   *
89   * @return {string}
90   *   The markup for the element that will contain the summarized content.
91   */
92  Drupal.theme.detailsSummarizedContentWrapper = () =>
93    `<span class="summary"></span>`;
94
95  /**
96   * Formats the summarized details content text.
97   *
98   * @param {string|null} [text]
99   *   (optional) The summarized content text displayed in the summary.
100   * @return {string}
101   *   The formatted summarized content text.
102   */
103  Drupal.theme.detailsSummarizedContentText = (text) =>
104    text ? ` (${text})` : '';
105})(jQuery, Drupal);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.