PageSourceSearch

https://bestforbritain.org/wp-content/themes/chd/js/stat-cards.js?ver=1790086030

js bestforbritain.org collected 2026-09-24 09:22:25 UTC 2,628 bytes, 92 lines download raw bytes

1(function () {
2  function setFlipped(card, on) {
3    card.classList.toggle('is-flipped', on);
4    var front = card.querySelector('.stat-card-front');
5    if (front) {
6      front.setAttribute('aria-expanded', on ? 'true' : 'false');
7    }
8  }
9
10  function closeAll(scope) {
11    (scope || document).querySelectorAll('.stat-card.is-flipped').forEach(function (card) {
12      setFlipped(card, false);
13    });
14  }
15
16  function initModule(mod) {
17    var grid = mod.querySelector('.stat-card-grid');
18    if (!grid) {
19      return;
20    }
21
22    function applyFilter(slug) {
23      closeAll(grid);
24
25      grid.querySelectorAll('.stat-card').forEach(function (card) {
26        var match = !slug || card.getAttribute('data-category') === slug;
27        card.classList.toggle('is-hidden', !match);
28      });
29
30      mod.querySelectorAll('.stat-filter-bar button').forEach(function (btn) {
31        var active = (btn.getAttribute('data-category') || '') === slug;
32        btn.classList.toggle('active', active);
33        btn.setAttribute('aria-pressed', active ? 'true' : 'false');
34      });
35
36      var select = mod.querySelector('.stat-filter-dropdown select');
37      if (select) {
38        select.value = slug;
39      }
40    }
41
42    mod.addEventListener('click', function (e) {
43      var filterBtn = e.target.closest('.stat-filter-bar button');
44      if (filterBtn) {
45        applyFilter(filterBtn.getAttribute('data-category') || '');
46        return;
47      }
48
49      var closeBtn = e.target.closest('.stat-card-close');
50      if (closeBtn) {
51        var closedCard = closeBtn.closest('.stat-card');
52        setFlipped(closedCard, false);
53        var front = closedCard.querySelector('.stat-card-front');
54        if (front) {
55          front.focus();
56        }
57        return;
58      }
59
60      var frontBtn = e.target.closest('.stat-card-front');
61      if (frontBtn) {
62        var card = frontBtn.closest('.stat-card');
63        var flip = !card.classList.contains('is-flipped');
64        closeAll(grid);
65        setFlipped(card, flip);
66      }
67    });
68
69    var select = mod.querySelector('.stat-filter-dropdown select');
70    if (select) {
71      select.addEventListener('change', function () {
72        applyFilter(select.value);
73      });
74    }
75  }
76
77  document.addEventListener('DOMContentLoaded', function () {
78    document.querySelectorAll('.stat-cards-layout').forEach(initModule);
79
80    document.addEventListener('keydown', function (e) {
81      if (e.key === 'Escape') {
82        closeAll();
83      }
84    });
85
86    document.addEventListener('click', function (e) {
87      if (!e.target.closest('.stat-card')) {
88        closeAll();
89      }
90    });
91  });
92})();

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.