PageSourceSearch

https://www.ptotoday.com/templates/g5_helium/custom/js/pto-toggles.js

js ptotoday.com collected 2026-10-01 11:35:05 UTC 2,135 bytes, 75 lines download raw bytes

1/**
2 * PTO Today — shared expand/collapse toggles
3 * Handles both the Content with Accordion and Cards with Expansion modules.
4 * Loaded globally by the Helium theme (survives Gantry's module-output filter,
5 * which strips <script> from module markup).
6 *
7 * Binds any button carrying aria-controls that points to a panel element.
8 * Selectors: .mod-content-accordion__trigger, .mod-cards-expansion__toggle
9 */
10(function () {
11  'use strict';
12
13  var TRIGGER_SELECTOR =
14    '.mod-content-accordion__trigger, .mod-cards-expansion__toggle';
15
16  function closePanel(panel, btn) {
17    panel.style.height = panel.scrollHeight + 'px';
18    panel.offsetHeight; // reflow
19    panel.style.height = '0px';
20    btn.setAttribute('aria-expanded', 'false');
21
22    var onEnd = function () {
23      panel.hidden = true;
24      panel.style.height = '';
25      panel.removeEventListener('transitionend', onEnd);
26    };
27    panel.addEventListener('transitionend', onEnd);
28  }
29
30  function openPanel(panel, btn) {
31    panel.hidden = false;
32    var target = panel.scrollHeight;
33    panel.style.height = '0px';
34    panel.offsetHeight; // reflow
35    panel.style.height = target + 'px';
36    btn.setAttribute('aria-expanded', 'true');
37
38    var onEnd = function () {
39      panel.style.height = 'auto';
40      panel.removeEventListener('transitionend', onEnd);
41    };
42    panel.addEventListener('transitionend', onEnd);
43  }
44
45  function toggle(btn) {
46    var panel = document.getElementById(btn.getAttribute('aria-controls'));
47    if (!panel) {
48      return;
49    }
50    if (btn.getAttribute('aria-expanded') === 'true') {
51      closePanel(panel, btn);
52    } else {
53      openPanel(panel, btn);
54    }
55  }
56
57  function bind() {
58    var btns = document.querySelectorAll(TRIGGER_SELECTOR);
59    Array.prototype.forEach.call(btns, function (btn) {
60      if (btn.dataset.ptoToggleBound) {
61        return;
62      }
63      btn.dataset.ptoToggleBound = '1';
64      btn.addEventListener('click', function () {
65        toggle(btn);
66      });
67    });
68  }
69
70  if (document.readyState === 'loading') {
71    document.addEventListener('DOMContentLoaded', bind);
72  } else {
73    bind();
74  }
75})();

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.