1let urlTerm = categoryTerms.queryTaxonomy === 'category' ? 'cat' : 'tags'; 2if (categoryTerms.queryTaxonomy === 'choice' || categoryTerms.is_choice_archive == true) urlTerm = 'choice'; 3const urlTermID = categoryTerms.queryTermID; 4const chunkSize = categoryTerms.query_limits ?? 10; 5let pagingState = '1'; 6const url = new URL(location); 7const params = url.searchParams; 8const sortingTerm = params.has('sorting') ? params.get('sorting') : ''; 9 10const siteUrl = generalTerms.status === 'dev' ? 'https://dev.cloudevo.ai/dev/newsAuto' : (urlTermID === 23113 ? 'https://www.newsauto.gr' : location.origin); 11const restRoute = generalTerms.status === 'dev' ? '?rest_route=/loadmore/category/articles&' : 'wp-json/loadmore/category/articles?'; 12const catQuery = (urlTerm, urlTermID, pagenum, chunkSize) => `${siteUrl}/${restRoute}tax=${urlTerm}&taxID=${urlTermID}&pagingState=${pagenum}&per_page=${chunkSize}&sortingTerm=${sortingTerm}&excluded=${categoryTerms.excluded.join(',')}`; 13 14const articleContainerSelector = urlTermID !== 23113 ? '.search-results-wrapper .nr-more-articles-wrapper' : '.nr-more-articles-wrapper .nr-more-articles' 15const articleThreshold = urlTermID !== 23113 ? 9 : 5; 16 17const getArticleBatch = (urlTerm, urlTermID, pagenum, chunkSize) => { 18 const fetchHeaders = generalTerms.status === 'dev' ? { 19 'Accept': 'application/json', 20 'Content-Type': 'application/json', 21 'Authorization': `Basic ${btoa('demo:demo')}`, 22 } : { 23 'Accept': 'application/json', 24 'Content-Type': 'application/json', 25 }; 26 const fetchOptions = { 27 method: 'GET', 28 headers: { 29 'Accept': 'application/json', 30 'Content-Type': 'application/json', 31 }, 32 credentials: 'same-origin', 33 mode: 'cors', 34 }; 35 const fetchURL = catQuery(urlTerm, urlTermID, pagenum, chunkSize); 36 console.log(fetchURL); 37 return fetch(fetchURL, fetchOptions) 38 .then(response => response.json()) 39 .then(articles => { 40 document.querySelector(`${articleContainerSelector}`).lastElementChild.insertAdjacentHTML('afterend', `${JSON.parse(articles).join(' ')}`); 41 document.querySelector(`${articleContainerSelector} .observable`).classList.remove('observable') 42 document.querySelector(`${articleContainerSelector} .article-box:last-of-type`).classList.add('observable'); 43 loadMoreObserver.observe(document.querySelector(`${articleContainerSelector} .observable`)) 44 }) 45} 46 47const loadMoreArticles = (entries, observer) => { 48 entries.forEach(entry => { 49 if (entry.isIntersecting) { 50 if (document.querySelector(`${articleContainerSelector}`).childElementCount > articleThreshold) { 51 console.log('incoming...'); 52 const incrCounter = parseInt(pagingState) + 1; 53 console.log('pagingState is ', pagingState) 54 pagingState = incrCounter 55 if (incrCounter < 15) { 56 getArticleBatch(urlTerm, urlTermID, incrCounter, chunkSize) 57 const nextObservable = document.querySelector(`${articleContainerSelector} .observable`); 58 observer.observe(nextObservable) 59 }; 60 observer.unobserve(entry.target); 61 } 62 } 63 }); 64} 65 66const loadMoreObserver = new IntersectionObserver(loadMoreArticles, { 67 rootMargin: "0px 0px -100px 0px" 68}); 69 70if (document.querySelector('.afieromaSwiper')) { 71 const nmFeaturedSwiper = new Swiper(".afieromaSwiper", { 72 slidesPerView: 1.5, 73 spaceBetween: 8, 74 freeMode: true, 75 breakpoints:{ 76 500: { 77 spaceBetween: 19, 78 }, 79 1100: { 80 slidesPerView: 3.07, 81 }, 82 }, 83 }); 84} 85 86document.addEventListener('DOMContentLoaded', () => { 87 document.querySelector(`${articleContainerSelector} .article-box:last-of-type`).classList.add('observable'); 88 loadMoreObserver.observe(document.querySelector(`${articleContainerSelector} .observable`)); 89 const sortingForm = document.querySelector('form.filters-form'); 90 if (sortingForm) { 91 const formElems = [...sortingForm.elements]; 92 const param = location.search !== '' ? new URLSearchParams(location.search) : ''; 93 if (param !== '' && param.has('sorting')) {
94 formElems.forEach(a => { 95 if (a.value == param.get('sorting')) { 96 a.checked = true 97 } else { 98 a.checked = false 99 } 100 }) 101 } 102 sortingForm.addEventListener('click', (event) => { 103 const target = event.target; 104 const value = target.value; 105 formElems.forEach(a => { 106 if (a.value == value) { 107 a.checked = true 108 } else { 109 a.checked = false 110 } 111 }) 112 // in production with pretty permalinks 113 // sortingForm.submit(); 114 // temp solution for normal permalinks 115 const url = new URL(location); 116 const params = url.searchParams; 117 params.set('sorting', target.value); 118 location.href = url.href 119 }) 120 } 121 122});
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.