1(function($) { 2 function strPostsRequestAPI() { 3 // var total = 4; 4 var postsWrap = $("div[data-append='post'] .posts-wrap"); 5 6 wp.apiRequest({ 7 url: '/wp-json/emulate-posts/v2/posts' 8 }).then(blogposts => { 9 let posts = blogposts; 10 11 postsWrap.each(function() { 12 13 let app = $(this); 14 let loadMore = app.find('.button-cont .load-more'); 15 16 loadMore.on('click', function(){ 17 let bttn = $(this); 18 let it = bttn.data('it'); 19 20 let postNum = appendPostsMatch( posts, it, app); 21 if (postNum != null) { 22 bttn.data('it', it+= 6); 23 } else { 24 bttn.attr('disabled', true); 25 bttn.text('no more posts'); 26 } 27 return false; 28 }); 29 }); 30 31 32 33 }).catch( error => console.log('error: ', error)); 34 35 function appendPostsMatch( posts, num, app ) { 36 let append = $(app).find('.posts-group'); 37 let selectedPosts = posts.slice(num, num+6); 38 let appendPosts = getPostsCards(selectedPosts); 39 let totalPosts = appendPosts != undefined ? appendPosts.length : null; 40 41 if (totalPosts != null) { 42 $(append).append(appendPosts); 43 } 44 45 return totalPosts; 46 } 47 48 function getPostsCards(posts) { 49 if (posts.length > 0) { 50 let appendPosts = []; 51 52 posts.map((post) => { 53 let title = post.post_title; 54 let url = post.link; 55 let media = post.media_url; 56 let card = $('<div>', {'class' : 'card'}); 57 let link = $('<a>', {'href' : url, 'target' : '_blank'}); 58 let head = $('<h3>', {'text' : title, 'class' : 'card-title'}); 59 let readmore = $('<span>', {'text' : 'Read More', 'class' : 'read-more'}); 60 61 if (media != '') { 62 let iCont = $('<div>', {'class' : 'img-wrap'}); 63 let img = $('<img>', {'src' : media, 'alt' : 'Image for ' + title, 'loading' : 'lazy'}); 64 iCont.append(img); 65 link.append(iCont); 66 } 67 68 card.append(link); 69 link.append(head); 70 link.append(readmore); 71 card.append(link); 72 appendPosts.push(card); 73 }); 74 75 return appendPosts; 76 } 77 78 } 79 80 } 81 82 strPostsRequestAPI(); 83 84})(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.