PageSourceSearch

https://pathforwardcoalition.org/wp-content/themes/pathforward/blocks/news-mentions/frontend.js?ver=7.0.5

js pathforwardcoalition.org collected 2026-10-04 05:17:21 UTC 2,698 bytes, 76 lines download raw bytes

1// /blocks/news-mentions/frontend.js
2(function () {
3  function ready(fn) {
4    if (document.readyState !== 'loading') fn();
5    else document.addEventListener('DOMContentLoaded', fn);
6  }
7
8  ready(function () {
9    document.querySelectorAll('.news-mentions-block[data-query]').forEach(function (wrap) {
10      var grid    = wrap.querySelector('.wp-block-post-template');
11      var button  = wrap.querySelector('.news-mentions-loadmore');
12      if (!grid || !button) return;
13
14      var ppp      = parseInt(wrap.getAttribute('data-ppp') || '6', 10);
15      var total    = parseInt(wrap.getAttribute('data-total') || '0', 10);
16      var offset   = grid.children.length;
17      var queryStr = wrap.getAttribute('data-query');
18      var ajaxUrl  = wrap.getAttribute('data-ajax-url');
19      var nonce    = wrap.getAttribute('data-nonce');
20
21      function setBusy(on) {
22        button.disabled = !!on;
23        button.setAttribute('aria-busy', on ? 'true' : 'false');
24        button.textContent = on ? 'Loading…' : 'Load more';
25      }
26
27      button.addEventListener('click', function () {
28        if (offset >= total) return;
29        setBusy(true);
30
31        var body = new URLSearchParams();
32        body.set('action', 'news_mentions_load_more');
33        body.set('nonce', nonce);
34        body.set('ppp', String(ppp));
35        body.set('offset', String(offset));
36        body.set('query', queryStr);
37
38        fetch(ajaxUrl, {
39          method: 'POST',
40          headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
41          body: body.toString()
42        })
43        .then(function (r) { return r.json(); })
44        .then(function (resp) {
45          if (resp && resp.success && resp.data && resp.data.html) {
46            var parser = new DOMParser();
47            var doc = parser.parseFromString(resp.data.html, 'text/html');
48
49            // SNAPSHOT the children to avoid skipping due to live HTMLCollection
50            var els = Array.from(doc.body.children);
51
52            var frag = document.createDocumentFragment();
53            els.forEach(function (el) { frag.appendChild(el); });
54            grid.appendChild(frag);
55
56            // Use the number actually appended
57            offset += els.length;
58
59            if (offset >= total || els.length < ppp) {
60              button.style.display = 'none';
61            } else {
62              setBusy(false);
63            }
64          } else {
65            alert('Sorry—something went wrong loading more items.');
66            setBusy(false);
67          }
68        })
69        .catch(function () {
70          alert('Sorry—something went wrong loading more items.');
71          setBusy(false);
72        });
73      });
74    });
75  });
76})();

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.