PageSourceSearch

https://cdn.keylife.org/wp-content/themes/keylife/assets/js/lazy-loader.js

js keylife.org collected 2026-10-04 00:25:32 UTC 3,792 bytes, 121 lines download raw bytes

1jQuery(function ($) {
2    //console.log('lazy loader scripts loaded');
3    /**
4     * Lazy Loader Functionality.
5     * @type {*|jQuery|HTMLElement}
6     */
7    let lazy_loader_btn = $('a.lazy-loader'); // Cached the lazy loader button
8    let feed = $('.feed');
9
10    if (lazy_loader_btn.length !== 0) {
11        // console.log('Lazy Load Button Loaded');
12
13        let filter = $('form.filters'); // Cache the filter
14        let inputs = filter.find('input'); // Holds all input fields
15        let selects = filter.find('select'); // Holds all select fields
16        let ajax_url = ajax.ajax_url; // Ajax URL
17        let class_name = 'lazy-loader--loading';
18        let shared = $('.shared--articles');
19
20        // Holds the data that we'll be adding
21        let data = {
22            'action': 'ajax_lazy_load', // WordPress action
23            'paged': 2
24        };
25
26        // Additional Parameters
27        if (lazy_loader_btn.data('cat')) {
28            data.filter_category = lazy_loader_btn.data('cat');
29        }
30
31        if (lazy_loader_btn.data('tax') && lazy_loader_btn.data('term')) {
32            data.filter_taxonomy = lazy_loader_btn.data('tax');
33            data.filter_term = lazy_loader_btn.data('term');
34        }
35
36        // console.log('Shared: ', shared);
37        if (shared.length > 0) {
38            data.filter_shared = true;
39            // console.log(`Shared Found: ${shared}`);
40        }
41
42        function get_filters() {
43            // console.log('Getting Filter Information');
44
45            // console.log('Data before: ' + JSON.stringify(data));
46
47
48            inputs.each(function (index) {
49                let name = $(this).attr('name');
50                let value = $(this).val();
51                data[name] = value;
52                // console.log(name + ': ' + value);
53            });
54
55            selects.each(function (index) {
56                let name = $(this).attr('name');
57                let value = $(this).find(':selected').val();
58                data[name] = value;
59                // console.log(name + ': ' + value);
60            });
61        }
62
63        lazy_loader_btn.on('click', function (e) {
64            e.preventDefault();
65            // console.log('Lazy Load click');
66
67            get_filters(); // Update the filter data
68
69            // console.log('Data: ' + JSON.stringify(data));
70
71            let btn = $(this);
72            // add loading class to button
73            btn.addClass(class_name);
74
75            let response;
76
77
78            /**
79             * Ajax Time!
80             */
81            $.ajax({
82                'type': 'post',
83                'data': data,
84                'url': ajax_url,
85                'success': function (r) {
86                    response = r;
87                    // console.log('Success');
88                    // console.log(response);
89                    // console.log(JSON.parse(response));
90                },
91                'failure': function (r) {
92                    response = r;
93                    // console.log('Failed');
94                    // console.log(response);
95                }
96            }).done(function (r) {
97                // console.log('Done');
98                //$('.loader-container').remove();
99                //response = r;
100                //console.log(r);
101                response = JSON.parse(r);
102                // console.log(response);
103
104                btn.removeClass(class_name);
105
106                if (response.paged !== false) {
107                    lazy_loader_btn.attr('data-next', response.paged);
108                    data.paged++;
109                } else {
110                    btn.remove();
111                }
112
113                feed.append(response.content);
114
115                // console.log('Data at finish: ' + JSON.stringify(data));
116            });
117
118
119        });
120    }
121});

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.