PageSourceSearch

https://verilymag.com/wp-content/plugins/mai-load-more/build/mai-load-more.js?ver=be9edc6451f4338b7ab8

js verilymag.com collected 2026-10-02 04:34:42 UTC 3,806 bytes, 99 lines download raw bytes

1/******/ (() => { // webpackBootstrap
2/*!******************************!*\
3  !*** ./src/mai-load-more.js ***!
4  \******************************/
5/**
6 * Mai Load More JavaScript.
7 * Handles load more functionality for archives and grids.
8 */
9(function () {
10  'use strict';
11
12  // Get the load more entries.
13  const entries = document.querySelectorAll('.entries[data-load-more]');
14
15  // Loop through the entries.
16  entries.forEach(container => {
17    // Get the button.
18    const button = container.querySelector('.mai-load-more');
19
20    // Add click event listener.
21    button?.addEventListener('click', function (e) {
22      // Get the button text.
23      const buttonText = this.textContent;
24      const styleTag = `<style id="mai-load-more-style">@keyframes mailoadmorespin { to { transform: rotate(360deg); } }</style>`;
25
26      // Modify the button.
27      this.insertAdjacentHTML('beforeBegin', styleTag);
28      this.innerHTML = `<span class="mai-load-more__text" style="opacity:0;">${buttonText}</span><span class="mai-load-more__loading" style="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);line-height:0;">${maiLoadMore.args.button_text_loading}</span>`;
29      this.disabled = true;
30
31      // Get the data.
32      const template = JSON.parse(atob(decodeURIComponent(container.dataset.template)));
33      const query = JSON.parse(atob(decodeURIComponent(container.dataset.query)));
34      const nextPage = parseInt(container.dataset.page) + 1;
35
36      // Set up query parameters.
37      query.paged = nextPage;
38
39      // Determine if this is a term query or post query.
40      const action = 'term' === container.dataset.type ? 'mai_load_more_terms' : 'mai_load_more_posts';
41
42      // Build data for AJAX request.
43      const data = new FormData();
44      data.append('action', action);
45      data.append('query_args', JSON.stringify(query));
46      data.append('template_args', JSON.stringify(template));
47      data.append('total_entries', container.dataset.totalEntries);
48      data.append('nonce', maiLoadMore.nonce);
49
50      // Make AJAX request.
51      fetch(maiLoadMore.ajaxUrl, {
52        method: 'POST',
53        body: data
54      }).then(res => {
55        if (!res.ok) {
56          throw new Error('Network response was not ok');
57        }
58        return res.json();
59      }).then(data => {
60        // Check if we have successful response with HTML content.
61        if (data.success && data.data?.html?.trim()) {
62          // Insert new HTML after the current entries.
63          container.querySelector('.entries-wrap')?.insertAdjacentHTML('beforeEnd', data.data.html);
64
65          // Update page number.
66          container.dataset.page = nextPage;
67
68          // Check if there are more posts to load.
69          if (!data.data.has_more) {
70            // Show "no more entries" message if configured.
71            if (container.dataset.noentries && entries) {
72              container.querySelector('.entries-wrap')?.insertAdjacentHTML('afterEnd', `<p class="${container.dataset.noentriesClass}">${container.dataset.noentries}</p>`);
73            }
74            // Remove the button since there are no more posts.
75            this.remove();
76          } else {
77            // Re-enable button and restore original text.
78            this.disabled = false;
79            this.textContent = buttonText;
80          }
81        } else {
82          // Remove button if no valid response.
83          this.remove();
84        }
85
86        // Remove the style tag.
87        document.getElementById('mai-load-more-style')?.remove();
88      }).catch(error => {
89        console.error('Error:', error);
90        // Re-enable button and restore original text on error.
91        this.disabled = false;
92        this.textContent = buttonText;
93      });
94    });
95  });
96})();
97/******/ })()
98;
99//# sourceMappingURL=mai-load-more.js.map

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.