PageSourceSearch

https://bright-way.ac/wp-content/plugins/edcare-core/assets/js/learnpress-ajax-filter-open.js?ver=7.1.2

js bright-way.ac collected 2026-10-02 01:10:57 UTC 8,561 bytes, 225 lines download raw bytes

1;(function($){
2    "use strict";
3    
4    var formDataFilter = {};
5    var paged = 1;
6    var tax_val = wp_vars.course_tax_page;
7    var term_id = wp_vars.current_term_id;
8    
9    $(document).on('change', '.archive_filter_3 select', function(){
10        
11        var formData = {};
12        paged = 1;
13        formData['paged'] = paged;
14        if(1 == paged){
15            $('.ac-lp-archive-load-more-3').css('display', 'inline-block');
16        }
17
18        // sort by
19        var sort_by = $('select[name="sort_by"]').val() || '';
20        if (sort_by !== '') {
21            formData['sort_by'] = sort_by;
22        }
23
24        // categories
25        var categories = $('select[name="categories"]').val() || '';
26        if (categories !== '') {
27            formData['categories'] = categories;
28        }
29
30        // instructors
31        var instructors = $('select[name="instructors"]').val() || '';
32        if (instructors !== '') {
33            formData['instructors'] = instructors;
34        }
35
36        // sort_by_price
37        var sort_by_price = $('select[name="sort_by_price"]').val() || '';
38        if (sort_by_price !== '') {
39            formData['sort_by_price'] = sort_by_price;
40        }
41
42        // Generate a nonce and add it to formData
43        let nonce = wp_vars_filter_open.nonce;
44        formData['nonce'] = nonce;
45
46        let urlParams = buildUrlParams(formData);
47        let newUrl = window.location.origin + window.location.pathname + '?' + urlParams;
48        window.history.pushState(null, null, newUrl);
49
50        // formData['action'] = 'ac_learnpress_filter_open_ajax_course';
51
52        ajax_filter_open_post_fetch(formData, '[data-ac-course-filter-open-content]', '[data-ac-course-filter-open-content-list]');
53
54    })
55
56    function buildUrlParams(data) {
57        let params = [];
58    
59        for (let key in data) {
60            if (Array.isArray(data[key]) && data[key].length > 0) {
61                // Join array values by commas if it's non-empty
62                params.push(`${key}=${data[key].join(',')}`);
63            } else if (data[key] !== null && data[key] !== '') {
64                // Add single values (like rating) only if they are not null or empty
65                params.push(`${key}=${data[key]}`);
66            }
67        }
68    
69        return params.join('&');
70    }
71
72    // filter bar
73    window.ajax_filter_open_post_fetch = (params, result, result_list) => {
74        $.ajax({
75            url: wp_vars_filter_open.ajaxurl,
76            type: 'POST',
77            data: {
78                ...params,
79                action: 'ac_learnpress_filter_open_ajax_course'
80            },
81            beforeSend:function(){
82                block($(result));
83                block($(result_list));
84            },
85            success:function(res){
86                $(result).html(res?.data?.results);
87                res?.data?.total_posts > 0 && $('[data-total-courses]').html(res?.data?.totals);
88                $(result_list).html(res?.data?.results_list);
89            },
90            complete: function(){
91                unblock($(result));
92                unblock($(result_list));
93            },
94            error:function(err){
95                console.log(err);
96            }
97        })
98    }
99
100    // ajax search
101    $(document).on('keyup', '.ac-archive-filter-open-search-form .course_search', function(e) {
102        $('.ac-lp-archive-load-more-3').css('display', 'inline-block');
103        // Get the value from the input field
104        let searchValue = $(this).val().trim();
105        // Get the current base URL (without query parameters)
106        let baseUrl = window.location.origin + window.location.pathname;
107
108        if (searchValue != '' && searchValue.length > 0) {
109            // Update the URL with the new query parameter
110            let newUrl = baseUrl + '?search_for=' + encodeURIComponent(searchValue);
111            
112            // Update the browser URL without reloading the page
113            window.history.pushState(null, null, newUrl);
114
115            if (e.keyCode == 13) { // Trigger form submission on Enter key
116                $('.ac-archive-filter-open-search-form').submit();
117            }
118
119            search_filter_open_ajax_fetch_post(searchValue, '[data-ac-course-filter-open-content]', '[data-ac-course-filter-open-content-list]')
120
121            // Perform the AJAX search
122            // search_ajax_fetch_post(searchValue, '[data-ac-course-content]', '[data-ac-course-content-list]');
123        } else {
124            // If the input is cleared (e.g., Ctrl + A + Backspace), reset the URL to the base URL
125            window.history.pushState(null, null, baseUrl);
126
127            search_filter_open_ajax_fetch_post('', '[data-ac-course-filter-open-content]', '[data-ac-course-filter-open-content-list]')
128            
129            // Optionally, trigger the default search or reset action
130            // search_ajax_fetch_post('', '[data-ac-course-content]', '[data-ac-course-content-list]');
131        }
132        formData['search_for'] = searchValue;
133        paged = 1;
134        formData['paged'] = paged;
135    });
136
137    window.search_filter_open_ajax_fetch_post = (sarch_val, result, results_list) => {
138        $.ajax({
139            url: wp_vars.ajaxurl,
140            type: 'POST',
141            data: {
142                action: 'ac_learnpress_filter_open_ajax_course',
143                search_for: sarch_val
144            },
145            beforeSend: function(){
146                block($(result));
147                block($(results_list));
148            },
149            success: function(res){
150                $(result).html(res?.data?.results);
151                $(results_list).html(res?.data?.results_list);
152                res?.data?.total_posts > 0 && $('[data-total-courses]').html(res?.data?.totals);
153            },
154            complete: function(){
155                unblock($(result));
156                unblock($(results_list));
157            },
158            error:function(err){
159                console.log(err);
160            }
161        });
162    }
163
164    $(document).on('click', '.ac-lp-archive-load-more-3', function(e){
165        e.preventDefault();
166        paged++;
167        var url = new URL(window.location.href);
168        var params = new URLSearchParams(url.search);
169        // formData['action'] = 'ac_learnpress_filter_open_ajax_course';
170        if( params.get('sort_by') != null ){
171            formDataFilter['sort_by'] = params.get('sort_by');
172        }
173        if( params.get('search_for') != null ){
174            formDataFilter['search_for'] = params.get('search_for');
175        }
176        if( params.get('categories') != null ){
177            formDataFilter['categories'] = params.get('categories');
178        }
179        if( params.get('instructors') != null){
180            formDataFilter['instructors'] = params.get('instructors');
181        }
182        if( params.get('paged') != null ){
183            formDataFilter['paged'] = params.get('paged') || paged;
184        }
185        if( params.get('sort_by_price') != null ){
186            formDataFilter['sort_by_price'] = params.get('sort_by_price');
187        }
188        formDataFilter['paged'] = paged;
189        ajax_filter_open_post_fetch_load(formDataFilter, '[data-ac-course-filter-open-content]', '[data-ac-course-filter-open-content-list]');
190    });
191
192    window.ajax_filter_open_post_fetch_load = (params, result, result_list) => {
193        $.ajax({
194            url: wp_vars_filter_open.ajaxurl,
195            type: 'POST',
196            data: {
197                ...params,
198                action : 'ac_learnpress_filter_open_ajax_course',
199                tax_val: tax_val,
200                term_id: term_id
201            },
202            beforeSend:function(){
203                block($(result));
204                block($(result_list));
205            },
206            success:function(res){
207                $(result).append(res?.data?.results);
208                $(result_list).append(res?.data?.results_list);
209                res?.data?.total_posts > 0 && $('[data-total-courses]').html(res?.data?.totals);
210                if(0 == res.data.total_pagi){
211                    $('.ac-lp-archive-load-more-3').css('display', 'none');
212                }
213            },
214            complete: function(){
215                unblock($(result));
216                unblock($(result_list));
217            },
218            error:function(err){
219                console.log(err);
220            }
221        })
222    }
223
224
225})(jQuery);

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.