PageSourceSearch

https://ojp.gov/modules/custom/ckeditor5_embedded_content/js/aftermarket/uswds_accordion.js?tkss1l

js ojp.gov collected 2026-09-24 07:32:58 UTC 3,197 bytes, 72 lines download raw bytes

1(function ($, Drupal) {
2  Drupal.behaviors.uswds_ckeditor_integration_accordion = {
3    attach: function (context, settings) {
4      // Apply modifications only once to each accordion button
5      $('div.usa-accordion__button:not(#layout-builder *)').each(function () {
6        if (!$(this).hasClass('js-accordion-modified')) {
7          let outer = this.outerHTML;
8          let regexOpen = new RegExp('<' + this.tagName, 'i');
9          let newTag = outer.replace(regexOpen, '<button');
10          let regexClose = new RegExp('</' + this.tagName, 'i');
11          newTag = newTag.replace(regexClose, '</button');
12          $(this).replaceWith(newTag).addClass('js-accordion-modified');
13        }
14      });
15
16      let $containerCounter = 0;
17      $('main .usa-accordion:not(#layout-builder *)').each(function () {
18        if (!$(this).hasClass('js-accordion-container-modified')) {
19          let $itemCounter = 0;
20          $('.usa-accordion__button', this).each(function () {
21            $(this).attr('aria-controls', $containerCounter + '-' + $itemCounter);
22            $itemCounter++;
23          });
24
25          $itemCounter = 0;
26          $('.usa-accordion__content', this).each(function () {
27            $(this).attr('id', $containerCounter + '-' + $itemCounter);
28            $itemCounter++;
29          });
30
31          $containerCounter++;
32          $(this).addClass('js-accordion-container-modified');
33        }
34      });
35
36      // Wrap each button and content pair in its own div, ignoring those within #layout-builder
37      $('main .usa-accordion:not(#layout-builder *)').each(function () {
38        $(this).find('.usa-accordion__heading').each(function () {
39          if (!$(this).hasClass('js-accordion-heading-modified')) {
40            let $button = $(this).find('.usa-accordion__button');
41            let $content = $(this).next('.usa-accordion__content');
42            $button.add($content).wrapAll('<div class="usa-accordion" />');
43            $(this).addClass('js-accordion-heading-modified');
44          }
45        });
46      });
47
48      // Adjust for URL hash, focusing outside #layout-builder
49      let hash = window.location.hash.replace('#', '');
50      if (hash) {
51        let $matchingButton = $('button[aria-controls="' + hash + '"]:not(#layout-builder *)', context);
52        if ($matchingButton.length && !$matchingButton.hasClass('js-accordion-hash-modified')) {
53          $matchingButton.attr('aria-expanded', 'true');
54          $('#' + hash).removeAttr('hidden');
55          $matchingButton.addClass('js-accordion-hash-modified');
56
57          $matchingButton.parents('.usa-accordion__content:not(#layout-builder *)').each(function() {
58            if (!$(this).hasClass('js-accordion-parent-modified')) {
59              let parentId = $(this).attr('id');
60              let $parentButton = $('button[aria-controls="' + parentId + '"]:not(#layout-builder *)', context);
61              if ($parentButton.length) {
62                $parentButton.attr('aria-expanded', 'true');
63                $('#' + parentId).removeAttr('hidden');
64                $(this).addClass('js-accordion-parent-modified');
65              }
66            }
67          });
68        }
69      }
70    }
71  };
72})(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.