PageSourceSearch

https://www.aragon.es/o/aragon-theme/js/aria/collapsible.js

js aragon.es collected 2026-09-24 08:28:40 UTC 2,056 bytes, 44 lines download raw bytes

1export function Collapsible(aria) {
2  aria.collapsibleInit = function (domNode) {
3    this.rootEl = domNode;
4    this.buttonEl = this.rootEl.querySelector('button[aria-expanded]');
5    this.buttonEl.addEventListener('click', handleToggle.bind(this));
6    if(this.rootEl.dataset.expanded){
7      this.buttonEl.click()
8    }
9  };
10
11  function handleToggle(element, isOpen = null) {
12    const elementTarget = element.type === 'click' ? element.target : element;
13    const elementParent = elementTarget.parentNode;
14    const button = element.type === 'click' ? this.buttonEl : element;
15    const elementCollapsibleShow = elementTarget.querySelector('.c-collapsible__show')
16    const elementCollapsibleHide = elementTarget.querySelector('.c-collapsible__hide')
17    const elementCollapsibleContent = elementTarget.nextElementSibling
18
19    if(element.type === 'click' && elementParent.getAttribute('data-expanded') === 'false' || isOpen) {
20      elementParent.setAttribute('data-expanded', 'true')
21      button.setAttribute('aria-expanded', 'true')
22      elementCollapsibleShow.setAttribute('aria-hidden', 'false')
23      elementCollapsibleHide.setAttribute('aria-hidden', 'true')
24      elementCollapsibleContent.setAttribute('aria-hidden', 'false')
25    } else if (element.type === 'click' && !elementParent.getAttribute('data-expanded') === 'true' || !isOpen) {
26      elementParent.setAttribute('data-expanded', 'false')
27      button.setAttribute('aria-expanded', 'false')
28      elementCollapsibleShow.setAttribute('aria-hidden', 'true')
29      elementCollapsibleHide.setAttribute('aria-hidden', 'false')
30      elementCollapsibleContent.setAttribute('aria-hidden', 'true')
31    }
32  }
33
34  window.activateItemCollapsible = function (element, isOpen) {
35    const collapsible = document.getElementById(element);
36    if (collapsible) {
37      handleToggle(collapsible, isOpen)
38      return [collapsible, isOpen];
39    } else {
40      console.log('There is no element with this id in the document.');
41      return null;
42    }
43  };
44}

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.