1// document.addEventListener('DOMContentLoaded', function () { 2// const loadMoreButton = document.getElementById('load-more-btn'); 3// let pageIndex = 0; // Start with the first page 4// const pageSize = 8; // Posts per page 5// const postContainer = document.getElementById('postContainer'); 6 7// // Function to load posts 8// function loadPosts() { 9// // Disable button temporarily to prevent multiple clicks 10// loadMoreButton.disabled = true; 11 12// var currentUrl = window.location.href; 13// var langParam = ""; 14 15// // Check if the current URL contains '/zh' 16// if (currentUrl.includes('/zh')) { 17// langParam = "lang=zh"; 18// } 19 20// fetch(`/MorePost?pageIndex=${pageIndex}&pageSize=${pageSize}&${langParam}`) 21// .then(response => response.text()) // Assuming the response is HTML 22// .then(html => { 23// postContainer.insertAdjacentHTML('beforeend', html); 24// pageIndex++; // Increment the page index for next load 25 26// // Enable the Load More button again 27// loadMoreButton.disabled = false; 28 29// // Check the number of posts returned 30// const posts = html.match(/class="col-sm-6"/g) || []; 31// if (posts.length < pageSize) { 32// // If fewer posts than the pageSize are returned, hide the Load More button 33// loadMoreButton.style.display = 'none'; 34// } 35// }) 36// .catch(error => { 37// console.error('Error loading posts:', error); 38// // Re-enable the button if there's an error but consider providing feedback to the user 39// loadMoreButton.disabled = false; 40// }); 41// } 42 43// // Initial load 44// loadPosts(); 45 46// // Load more posts on button click 47// loadMoreButton.addEventListener('click', loadPosts); 48// }); 49 50 51document.addEventListener('DOMContentLoaded', function () {
52 const loadMoreButton = document.getElementById('load-more-btn'); 53 const postContainer = document.getElementById('postContainer'); 54 if (!loadMoreButton || !postContainer) return; 55 56 // Desktop 3 åï¼12 æ¡/页ï¼Mobile 2 åï¼10 æ¡/页ï¼ä¸ md æç¹ä¸è´ï¼ 57 function getPageSize() { 58 return window.matchMedia('(min-width: 768px)').matches ? 12 : 10; 59 } 60 61 // SSR 已渲æç¬¬ 1 页(pageIndex=0)ï¼Load More ä»ç¬¬ 2 页(pageIndex=1) å¼å§ 62 let pageIndex = postContainer.dataset.ssrLoaded === 'true' ? 1 : 0; 63 64 function loadPosts() { 65 loadMoreButton.disabled = true; 66 67 var langParam = ''; 68 if (window.location.href.includes('/zh')) { 69 langParam = 'lang=zh'; 70 } 71 72 var pageSize = getPageSize(); 73 fetch('/MorePost?pageIndex=' + pageIndex + '&pageSize=' + pageSize + (langParam ? '&' + langParam : '')) 74 .then(function (response) { return response.text(); }) 75 .then(function (html) { 76 postContainer.insertAdjacentHTML('beforeend', html); 77 pageIndex++; 78 79 loadMoreButton.disabled = false; 80 81 // å端å¨è¿åä¸è¶³ä¸é¡µ(å°äº pageSize)æ¶ä¼è¾åº <input id="morePostEnd" ...> ä½ä¸ºâæ²¡ææ´å¤âçæ è®°ï¼ 82 // æè¿åå 容为空ãå½ä¸ä»»ä¸æ¡ä»¶æéèæé®ï¼å¦åä¿æå¯ç»§ç»ç¹å»ã 83 if (html.indexOf('id="morePostEnd"') !== -1 || html.trim() === '') { 84 loadMoreButton.style.display = 'none'; 85 } 86 }) 87 .catch(function (error) { 88 console.error('Error loading posts:', error); 89 loadMoreButton.disabled = false; 90 }); 91 } 92 93 // ä» å¨æ²¡æ SSR é¦å±æ¶æèªå¨å 载第 1 页 94 if (postContainer.dataset.ssrLoaded !== 'true') { 95 loadPosts(); 96 } 97
98 loadMoreButton.addEventListener('click', loadPosts); 99});
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.