1$(document).ready(function() { 2 const today = new Date(); 3 const containers = $(".news"); 4 containers.each(initContainer); 5 6 function initContainer() { 7 const container = $(this); 8 const template = container.find(".article"); 9 const loadMoreBtn = container.next(".load-more-btn"); 10 11 const pageSize = 10; 12 let currentPage = 0; 13 let filteredArticles = []; 14 15 function moreToLoad() { 16 return currentPage * pageSize < filteredArticles.length; 17 } 18 19 function populateArticles(articles) { 20 filteredArticles = articles; 21 nextPage(); 22 23 loadMoreBtn.click(nextPage); 24 25 container.prev(".news-loader").fadeOut("slow", function() { 26 container.fadeIn("slow"); 27 if (moreToLoad()) { 28 loadMoreBtn.removeClass("d-none").addClass("d-block"); 29 } 30 }); 31 } 32 33 function nextPage() { 34 appendArticles(filteredArticles.slice(currentPage * pageSize, ++currentPage * pageSize)); 35 if (!moreToLoad()) { 36 loadMoreBtn.removeClass("d-block").addClass("d-none"); 37 } 38 } 39 40 function appendArticles(articles) { 41 for (let i = 0; i < articles.length; i++) { 42 const article = articles[i]; 43 const dom = template.clone(); 44 45 dom.removeClass("d-none"); 46 dom.removeAttr("id"); 47 if (article.image) { 48 dom.find(".thumb").attr("src", article.image.src).attr("alt", article.image.alt).attr("title", article.image.alt); 49 } else { 50 dom.find(".thumb").remove(); 51 } 52 dom.find(".title").html("<a href=\"" + article.link + "\" target=\"_parent\">" + article.title + "</a>"); 53 dom.find(".date").text(new Date(article.date).toLocaleDateString()); 54 dom.find(".summary").text(article.summary); 55 dom.find(".tags").text(article.tags.map(function(t) { return t.name }).join(", ")); 56 57 container.append(dom); 58 } 59 } 60 61 const location = container.data("location"); 62 const tagsInclude = container.data("tags-include"); 63 const tagsExclude = container.data("tags-exclude"); 64 const count = container.data("count"); 65 let predicates = [articleIsCurrent]; 66 67 function articleIsCurrent(article) { 68 return new Date(article.date) < today && today < new Date(article.endDate); 69 } 70 71 if (tagsInclude) { 72 const cleanTags = tagsInclude.split(",").map(function(tag) { return tag.trim() }); 73 predicates.push(function(article) { 74 return article.tags.filter(function(t) { return cleanTags.indexOf(t.name) !== -1 }).length > 0; 75 }); 76 } 77 78 if (tagsExclude) { 79 const cleanTags = tagsExclude.split(",").map(function(tag) { return tag.trim() }); 80 predicates.push(function(article) { 81 return article.tags.filter(function(t) { return cleanTags.indexOf(t.name) !== -1 }).length === 0; 82 }); 83 } 84 85 function ifAll(article) { 86 let result = true; 87 for(let predicate of predicates) { 88 result = result && predicate(article); 89 90 if(!result) { 91 return false; 92 } 93 } 94 return true; 95 } 96 97 $.get({ 98 url: location, 99 cache: false 100 }) 101 .done(function(data) { 102 let filtered = data.filter(ifAll); 103 if (count) { 104 filtered = filtered.slice(0, count); 105 } 106 107 //This code is only necessary once published 108 109 populateArticles(filtered); 110 }); 111 } 112});
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.