PageSourceSearch

https://www.trisura.com/wp-content/themes/trisura/resources/scripts/EventsPosts.js?ver=1.0.0

js trisura.com collected 2026-09-29 09:47:48 UTC 4,807 bytes, 122 lines download raw bytes

1jQuery(function($){
2    // Apply the select2 library on your select elements
3    if ($(".filter-year-events").length) {
4        $(".filter-year-events").select2({
5            minimumResultsForSearch: Infinity,
6        });
7    }
8
9    function loadEventsPosts(page = 1) {
10        var year = $('#year-events').length ? $('#year-events').val() : 'all';
11        $.ajax({
12            url: wpApiSettings.root + 'events_information/v1/filter/',
13            method: 'POST',
14            dataType: 'json',
15            data: {
16                action: 'eventsfilter',
17                year: year,
18                page: page,
19            },
20            beforeSend: function (xhr) {
21                xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);
22                $('.loading').show();
23            },
24            success: function (response) {
25                //console.log(response);
26                if ($('#response-events').length) {
27                    $('#response-events').html(response.content); // Make sure to extract content from response
28                    generatePagination(response.pages, page);
29                }
30                $('.loading').hide();
31            },
32            error: function(jqXHR, textStatus, errorThrown) {
33                console.error('Error:', errorThrown);
34                console.error('Error status:', jqXHR.status);
35                console.error('Error status text:', jqXHR.statusText);
36                console.error('Error response:', jqXHR.responseText);
37                $('.loading').hide();
38            }
39        });
40    }
41
42    function generatePagination(pages, currentPage) {
43        //console.log('Generating pagination:', pages, currentPage);
44    
45        var pagination = '';
46        $('#pagination-events').addClass("d-none");
47        if ($('#pagination-events').length) {
48            if(pages > 1 && $('#response-events').html().trim() != '<p>'+wpApiSettings.no_posts_found+'</p>') {
49                
50                $('#pagination-events').removeClass("d-none");
51
52                // Determine if previous and next buttons should be disabled
53                var previousDisabled = currentPage === 1 ? 'disabled' : '';
54                var nextDisabled = currentPage === pages ? 'disabled' : '';
55
56
57                pagination += '<a class="order-2 order-md-1 ' + previousDisabled + '" href="#" data-page="' + Math.max(1, currentPage - 1) + '">'+wpApiSettings.previous+'</a>';
58                pagination += '<ul class="d-flex mb-0 order-1 order-md-2">';
59
60                var firstPage = Math.max(1, currentPage - 2);
61                var lastPage = Math.min(pages, firstPage + 4);
62
63                // Ensure we always show 5 pages
64                if (lastPage - firstPage < 4){
65                    firstPage = Math.max(1, lastPage - 4);
66                }
67
68                // If first page is not 1, show ...
69                if(firstPage > 1) {
70                    pagination += '<li><a href="#" data-page="1">1</a></li>';
71                    pagination += '<li><a href="#">...</a></li>';
72                }
73
74                for (var i = firstPage; i <= lastPage; i++) {
75                    if (i === currentPage) {
76                        pagination += '<li><a href="#" class="active" data-page="' + i + '">' + i + '</a></li>';
77                    } else {
78                        pagination += '<li><a href="#" data-page="' + i + '">' + i + '</a></li>';
79                    }
80                }
81
82                // If last page is not the actual last page, show ...
83                if(lastPage < pages) {
84                    pagination += '<li><a href="#">...</a></li>';
85                    pagination += '<li><a href="#" data-page="' + pages + '">' + pages + '</a></li>';
86                }
87
88                pagination += '</ul>';
89                pagination += '<a class="order-3 ' + nextDisabled + '" href="#" data-page="' + Math.min(pages, currentPage + 1) + '">'+wpApiSettings.next+'</a>';
90            }
91
92            $('#pagination-events').html(pagination);
93            bindPaginationLinks();
94        }
95    }
96    
97    
98    function bindPaginationLinks() {
99        if ($('#pagination-events a').length) {
100            //console.log('bindPaginationLinks');
101            $('#pagination-events a').on('click', function (e) {
102                e.preventDefault();
103                var page = $(this).data('page');
104                loadEventsPosts(page);
105            });
106        }
107    }
108
109    // When the filter changes, load the first page
110    if ($('.filter-year-events').length) {
111        $('.filter-year-events').on('change', function () {
112            loadEventsPosts(1);
113        });
114    }
115
116    // Load the first page when the page loads
117    $(document).ready(function() {
118        if ($('#response-events').length) {
119            loadEventsPosts(1);
120        }
121    });
122});

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.