1(() => { 2 /** 3 * initializeBlock 4 * 5 * Adds custom JavaScript to the block HTML. 6 * 7 * @date 15/4/19 8 * @since 1.0.0 9 * 10 * @return void 11 */ 12 13 const scriptName = "m_teaser_content_list"; 14 15 var initializeBlock = (block) => { 16 const module = window.acf ? block[0] : block; 17 18 const filters = module.querySelectorAll(".m_teaser_content_list__filter_item"); 19 const allPosts = module.querySelectorAll(".m_teaser_content_list__item"); 20 21 let selectedTerms = []; 22 23 filters.forEach((filter) => { 24 filter.addEventListener('click', () => { 25 filterTeasers(filter); 26 }) 27 28 if(filter.dataset.select){ 29 filterTeasers(filter); 30 } 31 }) 32 33 // Mobile 34 const filtermobile = module.querySelector(".m_teaser_content_list__filtermobile"); 35 const filtergroup = module.querySelector(".m_teaser_content_list__filter"); 36 filtermobile.addEventListener('click', () => { 37 filtermobile.classList.toggle("show"); 38 filtergroup.classList.toggle("show"); 39 }) 40 41 function filterTeasers(filter){ 42 if (filter.classList.contains("selected")) { 43 filter.classList.remove("selected"); 44 } else { 45 filter.classList.add("selected"); 46 } 47 48 const selectedTerm = filter.getAttribute('data-term'); 49 50 // toggle the selection 51 if (selectedTerms.includes(selectedTerm)) { 52 53 // If term is alrady selected, remove it from the array 54 const index = selectedTerms.indexOf(selectedTerm); 55 if (index > -1) selectedTerms.splice(index, 1); 56 } else { 57 58 // If the term is not selected, add it to the array 59 selectedTerms.push(selectedTerm); 60 } 61 62 // Show posts that have at least one of the selected taxonomy terms and hide others 63 if (selectedTerms.length === 0) { 64 allPosts.forEach(function (post) { 65 post.classList.add("show"); 66 }); 67 } else { 68 allPosts.forEach(function (post) { 69 var postTerms = post.getAttribute('data-term').split(' '); 70 71 if (selectedTerms.some(term => postTerms.includes(term))) { 72 post.classList.add("show"); 73 } else { 74 post.classList.remove("show"); 75 } 76 }); 77 } 78 } 79 80 } 81 82 document.addEventListener("DOMContentLoaded", () => { 83 const elements = Array.from(document.getElementsByClassName(`${scriptName}`)); 84 elements.forEach(element => { 85 initializeBlock( element ); 86 }); 87 }); 88 89 if( window.acf ) { 90 window.acf.addAction( `render_block_preview/type=${scriptName}`, initializeBlock ); 91 } 92})();
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.