PageSourceSearch

https://www.ontheforecheck.com/wp-content/themes/forfanstwocolumn/js/infinite-scroll.js?ver=1.1.3

js ontheforecheck.com collected 2026-10-02 10:02:54 UTC 3,949 bytes, 148 lines download raw bytes

1/**
2 * Infinite Scroll and Pagination Handler
3 * Handles dynamic post loading for homepage feed
4 * Supports both infinite scroll and "Load More" button modes
5 */
6
7(function() {
8	'use strict';
9
10	// Configuration object passed from PHP
11	var config = window.ffntScrollConfig || {};
12	
13	var isLoading = false;
14	var currentPostCount = config.currentPostCount || 0;
15	var currentAdCount = config.currentAdCount || 0;
16	var postsPerPage = config.postsPerPage || 10;
17	var infiniteScrollEnabled = config.infiniteScrollEnabled || false;
18	var ajaxUrl = config.ajaxUrl || '/wp-admin/admin-ajax.php';
19
20	/**
21	 * Fetch posts via AJAX
22	 */
23	function fetchPosts() {
24		var url = ajaxUrl + '?action=ffnt_remoteFeedPull&currentPostCount=' + 
25			currentPostCount + '&currentAdCount=' + currentAdCount + '&postsPerPage=' + postsPerPage;
26
27		fetch(url, {
28			method: 'GET'
29		}).then(function(res) {
30			return res.text();
31		}).then(function(theData) {
32			// If in pagination mode, insert before the button
33			if (!infiniteScrollEnabled) {
34				var loadMoreContainer = document.querySelector('.load-more-container');
35				if (loadMoreContainer) {
36					loadMoreContainer.insertAdjacentHTML('beforebegin', theData);
37				} else {
38					appendToMainColumn(theData);
39				}
40			} else {
41				appendToMainColumn(theData);
42			}
43			
44			setTimeout(function() {
45				currentPostCount = currentPostCount + postsPerPage;
46				currentAdCount = document.querySelectorAll('.postCardAd').length;
47				isLoading = false;
48				
49				// Re-enable the load more button in pagination mode
50				if (!infiniteScrollEnabled) {
51					var button = document.querySelector('.load-more-button');
52					if (button) {
53						button.textContent = 'Load More Posts';
54						button.disabled = false;
55					}
56				}
57			}, 400);
58		}).catch(function(error) {
59			console.error('Error loading posts:', error);
60			isLoading = false;
61			
62			// Re-enable button on error
63			if (!infiniteScrollEnabled) {
64				var button = document.querySelector('.load-more-button');
65				if (button) {
66					button.textContent = 'Load More Posts';
67					button.disabled = false;
68				}
69			}
70		});
71	}
72
73	/**
74	 * Append content to main column
75	 * Uses u() if available (Umbrellajs), otherwise vanilla JS
76	 */
77	function appendToMainColumn(content) {
78		if (typeof u !== 'undefined') {
79			u('.mainColumn').append(content);
80		} else {
81			var mainColumn = document.querySelector('.mainColumn');
82			if (mainColumn) {
83				mainColumn.insertAdjacentHTML('beforeend', content);
84			}
85		}
86	}
87
88	/**
89	 * Initialize infinite scroll mode
90	 */
91	function initInfiniteScroll() {
92		window.addEventListener('scroll', function() {
93			var scrollHeight = document.documentElement.scrollHeight;
94			var scrollTop = document.documentElement.scrollTop;
95			var clientHeight = document.documentElement.clientHeight;
96			
97			if (scrollTop + clientHeight > scrollHeight - 800) {
98				if (!isLoading) {
99					isLoading = true;
100					setTimeout(fetchPosts, 400);
101				}
102			}
103		});
104	}
105
106	/**
107	 * Initialize pagination mode with Load More button
108	 */
109	function initPaginationMode() {
110		var mainColumn = document.querySelector('.mainColumn');
111		if (mainColumn) {
112			var loadMoreButton = document.createElement('div');
113			loadMoreButton.className = 'load-more-container';
114			loadMoreButton.innerHTML = '<button class="load-more-button">Load More Posts</button>';
115			
116			mainColumn.appendChild(loadMoreButton);
117			
118			var button = loadMoreButton.querySelector('.load-more-button');
119			button.addEventListener('click', function() {
120				if (!isLoading) {
121					isLoading = true;
122					this.textContent = 'Loading...';
123					this.disabled = true;
124					fetchPosts();
125				}
126			});
127		}
128	}
129
130	/**
131	 * Initialize based on configuration
132	 */
133	function init() {
134		if (infiniteScrollEnabled) {
135			initInfiniteScroll();
136		} else {
137			initPaginationMode();
138		}
139	}
140
141	// Initialize when DOM is ready
142	if (document.readyState === 'loading') {
143		document.addEventListener('DOMContentLoaded', init);
144	} else {
145		init();
146	}
147
148})();

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.