1(function($) { 2 3 function strInTheNewsRequestAPI() { 4 // var total = 4; 5 var newsWrap = $("div[data-append='news-releases'] .news-wrap"); 6 7 wp.apiRequest({ 8 url: '/wp-json/emulate-in-the-news/v2/news' 9 }).then(newsreleases => { 10 let press = newsreleases[0].posts; 11 12 newsWrap.each(function() { 13 let app = $(this); 14 let batch = app.data('batch'); 15 let loadMore = app.find('.button-cont .load-more'); 16 17 loadMore.on('click', function(){ 18 let bttn = $(this); 19 let it = bttn.data('it'); 20 let term = bttn.data('term'); 21 22 let postNum = appendNewsMatch( press, it, app, batch, term); 23 if (postNum != null) { 24 bttn.data('it', it+= batch); 25 } else { 26 bttn.attr('disabled', true); 27 bttn.text('no more news'); 28 } 29 return false; 30 }); 31 }); 32 33 34 35 }).catch( error => console.log('error: ', error)); 36 37 function findFilteredNews(posts, term) { 38 let matches = []; 39 posts.forEach((post) => { 40 let news = post.taxonomies['news_category']; 41 if (news != undefined) { 42 for($x = 0; $x < news.length; $x++) { 43 let pId = news[$x]['term_id']; 44 if (pId == term) { 45 matches.push(post); 46 } 47 } 48 } 49 }); 50 return matches; 51 } 52 53 function appendNewsMatch( posts, num, app, batch, term) { 54 let append = $(app).find('.news-group'); 55 let filteredPosts = findFilteredNews(posts, term); 56 let selectedPosts = filteredPosts.slice(num, num+batch); 57 let appendPosts = getNewsCards(selectedPosts); 58 let totalPosts = appendPosts != undefined ? appendPosts.length : null; 59 60 if (totalPosts != null) { 61 $(append).append(appendPosts); 62 } 63 64 return totalPosts; 65 } 66 67 function getNewsCards(posts) { 68 if (posts.length > 0) { 69 let appendPosts = []; 70 71 posts.map((post) => { 72 let title = post.post_title; 73 let url = post.post_link; 74 let tags = post.tags; 75 let card = $('<div>', {'class' : 'card'}); 76 let link = $('<a>', {'href' : url, 'target' : '_blank'}); 77 let head = $('<h3>', {'text' : title, 'class' : 'card-title'}); 78 let list = $('<ul>', {'class' : 'tags'}); 79
80 tags.forEach((tag) => { 81 let del = tags.length > 1 ? ', ' : ''; 82 let lItem = $('<li>', {'class' : 'tag', 'text' : tag + del}); 83 list.append(lItem); 84 }); 85 86 card.append(link); 87 link.append(head); 88 link.append(list); 89 card.append(link); 90 appendPosts.push(card); 91 }); 92 93 return appendPosts; 94 } 95 96 } 97 98 } 99 100 strInTheNewsRequestAPI(); 101 102})(jQuery);
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.