(function() { let offset = 0; const limit = 6; let isLoading = false; let hasMore = true; let searchDebounceTimer = null; function fetchContestants(reset) { if (isLoading && !reset) return; if (!hasMore && !reset) return; isLoading = true; const searchEl = document.getElementById("search_cont"); const getIdEl = document.getElementById("get_id"); const searchValue = searchEl ? searchEl.value.trim() : ''; const getIds = getIdEl ? getIdEl.value.trim() : ''; if (reset) { offset = 0; hasMore = true; $('#loader1').show(); } else { $('#loader').show(); } $.ajax({ url: 'video_data_load.php', type: 'POST', data: { offset: offset, search_cont: searchValue, get_id: getIds }, dataType: 'json', success: function(data) { isLoading = false; $('#loader, #loader1').hide(); if (reset) { $('#items-container').empty(); } if (Array.isArray(data) && data.length > 0) { $('#items-container').append(data.join('')); offset += data.length; if (data.length < limit || getIds !== '') { hasMore = false; $('#load-more').prop('disabled', true).text('No more Videos to load'); } else { hasMore = true; $('#load-more').prop('disabled', false).text('Load More'); } } else { hasMore = false; $('#load-more').prop('disabled', true).text('No more Videos to load'); } if (typeof checkAndHideVoteButton === 'function') { checkAndHideVoteButton(); } }, error: function(xhr, status, error) { isLoading = false; $('#loader, #loader1').hide(); console.error('Error loading videos: ' + error); } }); } $(document).ready(function() { const loadMoreBtn = document.getElementById('load-more'); $('#load-more').off('click').on('click', function() { fetchContestants(false); }); fetchContestants(false); // Pre-fetch next batch automatically as user scrolls near the Load More button if (loadMoreBtn && 'IntersectionObserver' in window) { const observer = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting && !isLoading && hasMore) { fetchContestants(false); } }); }, { rootMargin: '450px 0px' }); observer.observe(loadMoreBtn); } }); window.search_function = function() { clearTimeout(searchDebounceTimer); searchDebounceTimer = setTimeout(function() { fetchContestants(true); }, 250); }; })(); function shareViaFacebook(videoUrl) { var facebookLink = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(videoUrl); window.open(facebookLink, '_blank'); } function shareViaWhatsApp(videoUrl) { var message = " Please vote for me as a singer in Aikat Mozo Tavo and ask others to vote as well!!!"; var whatsappLink = 'whatsapp://send?text=' + encodeURIComponent(videoUrl + '\n\n' + message); window.open(whatsappLink, '_blank'); } function copyLink(videoUrl) { var message = " Please vote for me as a singer in Aikat Mozo Tavo and ask others to vote as well!!!"; var textField = document.createElement('textarea'); textField.innerText = videoUrl + '\n\n' + message; document.body.appendChild(textField); textField.select(); document.execCommand('copy'); textField.remove(); Swal.fire({ title: 'Link Copied', text: 'The link with message has been copied to your clipboard.', icon: 'success', showConfirmButton: false, timer: 1500 }); } function shareViaInstagramDM(videoUrl) { var message = "Please vote for me as a singer in Aikat Mozo Tavo and encourage others to vote as well!"; var textField = document.createElement('textarea'); textField.innerText = videoUrl + '\n\n' + message; document.body.appendChild(textField); textField.select(); document.execCommand('copy'); textField.remove(); Swal.fire({ title: 'Link Copied', text: 'The link with your message has been copied to your clipboard. Paste and share it in your Instagram DM.', icon: 'success', confirmButtonText: 'OK' }).then((result) => { if (result.isConfirmed) { var instagramLink = 'https://www.instagram.com/direct/new/?text=' + encodeURIComponent(message); window.open(instagramLink, '_blank'); } }); }