1/** 2 * Shopify Pagination JavaScript 3 * 4 * Handles pagination functionality for Shopify collections 5 */ 6 7document.addEventListener('DOMContentLoaded', function() { 8 // Initialize pagination handlers 9 initializePaginationHandlers(); 10}); 11 12function initializePaginationHandlers() { 13 // Add event listener for the shopify-list-context-update event to toggle pagination states 14 document.addEventListener( 15 "shopify-list-context-update", 16 (event) => { 17 // Find all pagination containers 18 const paginationContainers = document.querySelectorAll(".collection-pagination"); 19 20 paginationContainers.forEach((paginationContainer) => { 21 // Find associated list ID from the container's buttons 22 const previousButton = paginationContainer.querySelector(".pagination-button--previous"); 23 const nextButton = paginationContainer.querySelector(".pagination-button--next"); 24 25 if (!previousButton || !nextButton) return; 26 27 const { hasNextPage, hasPreviousPage } = event.detail; 28 29 // Hide the entire pagination container if there are no next or previous pages 30 if (!hasNextPage && !hasPreviousPage) { 31 paginationContainer.style.display = "none"; 32 } else { 33 // Show the pagination container and manage button states 34 paginationContainer.style.display = "flex"; 35 36 if (!hasNextPage) { 37 nextButton.setAttribute("disabled", "true"); 38 } else { 39 nextButton.removeAttribute("disabled"); 40 } 41 if (!hasPreviousPage) { 42 previousButton.setAttribute("disabled", "true"); 43 } else { 44 previousButton.removeAttribute("disabled"); 45 } 46 } 47 48 console.log('Pagination event listener processed for container:', paginationContainer); 49 }); 50 }, 51 ); 52 53 console.log('Pagination handlers initialized successfully'); 54} 55 56// Global pagination functions that can be called from PHP-generated onclick handlers 57window.handlePaginationClick = function(listId, direction) { 58 const listElement = document.getElementById(listId); 59 if (!listElement) { 60 console.error('List element not found:', listId); 61 return; 62 } 63 64 if (direction === 'next') { 65 listElement.nextPage(); 66 } else if (direction === 'previous') { 67 listElement.previousPage(); 68 } 69 70 // Scroll to top after pagination 71 window.scrollTo(0, 0); 72};
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.