1function toggleSearchFilters(event) { 2 // Handles both mouse clicks and keyboard 3 // activate with Enter or Space 4 5 // Keypresses other then Enter and Space should not trigger a command 6 // @TODO NE MARCHE PAS 7 if (event instanceof KeyboardEvent && event.key !== 'Enter' && event.key !== ' ') { 8 return; 9 } 10 11 jQuery('#search_filters').toggle("fast"); 12} 13 14function checkAll() { 15 var check = document.getElementById('checkAllVoix'); 16 var container = document.getElementsByClassName('wpas-tax_voix'); 17 var checkboxes = container[0].getElementsByTagName('input'); 18 19 // console.log(checkboxes_container); 20 if (check.checked) { 21 for (var i = 0; i < checkboxes.length; i++) { 22 if (checkboxes[i].type == 'checkbox') { 23 checkboxes[i].checked = true; 24 } 25 } 26 } else { 27 for (var i = 0; i < checkboxes.length; i++) { 28 // console.log(i) 29 if (checkboxes[i].type == 'checkbox') { 30 checkboxes[i].checked = false; 31 } 32 } 33 } 34} 35 36// list filter search bar 37(function () { 38 'use strict'; 39 40 const initFilterSearch = function () { 41 42 const searchInput = document.getElementById('term-search'); 43 const sortNameButton = document.getElementById('sort-name'); 44 const sortCountButton = document.getElementById('sort-count'); 45 const clearButton = document.getElementById('clear-search'); 46 const termLetters = document.querySelectorAll('.term-letter'); 47 48 if (searchInput) { 49 const termList = document.querySelectorAll('.taxonomy-list-shortcode li'); 50 51 // Remove existing event listeners to avoid duplicates 52 searchInput.removeEventListener('input', handleSearchInput); 53 searchInput.addEventListener('input', handleSearchInput); 54 55 function handleSearchInput() { 56 const query = searchInput.value.toLowerCase(); 57 let anyVisible = false; 58 59 termList.forEach(function(term) { 60 const termName = term.textContent.toLowerCase(); 61 if (termName.includes(query)) { 62 term.style.display = ''; 63 anyVisible = true; 64 } else { 65 term.style.display = 'none'; 66 } 67 }); 68 69 termLetters.forEach(function(letter) { 70 const letterSection = letter.nextElementSibling; 71 const visibleTerms = letterSection.querySelectorAll('li:not([style*="display: none"])'); 72 if (visibleTerms.length > 0) { 73 letter.style.display = ''; 74 letterSection.style.display = ''; 75 } else { 76 letter.style.display = 'none'; 77 letterSection.style.display = 'none'; 78 } 79 }); 80 removeSubdivisions(); 81 82 // Deactivate sorting buttons if there is a search query 83 if (query.trim() === '') { 84 sortNameButton.disabled = false; 85 sortCountButton.disabled = false; 86 clearButton.disabled = true; 87 } else { 88 sortNameButton.disabled = true; 89 sortCountButton.disabled = true; 90 clearButton.disabled = false; 91 } 92 } 93 } 94 95 if (clearButton) { 96 // Remove existing event listeners to avoid duplicates 97 clearButton.removeEventListener('click', handleClearButtonClick); 98 clearButton.addEventListener('click', handleClearButtonClick); 99 100 function handleClearButtonClick() { 101 console.log("clear"); 102 searchInput.value = ''; 103 searchInput.dispatchEvent(new Event('input')); 104 } 105 } 106 107 if (sortNameButton && sortCountButton) { 108 // Remove existing event listeners to avoid duplicates 109 sortNameButton.removeEventListener('click', handleSortNameButtonClick); 110 sortCountButton.removeEventListener('click', handleSortCountButtonClick); 111 112 sortNameButton.addEventListener('click', handleSortNameButtonClick); 113 sortCountButton.addEventListener('click', handleSortCountButtonClick); 114 115 function handleSortNameButtonClick() { 116 console.log('click sort by name'); 117 toggleSortOrder(this); 118 sortTerms('name', this); 119 removeSubdivisions(); 120 } 121 122 function handleSortCountButtonClick() { 123 console.log('click sort by count'); 124 toggleSortOrder(this); 125 sortTerms('count', this); 126 removeSubdivisions(); 127 } 128 } 129 130 function toggleSortOrder(button) { 131 const order = button.getAttribute('data-order'); 132 const newOrder = order === 'asc' ? 'desc' : 'asc'; 133 var iconArrowDownward = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon" viewB
133ox="0 0 24 24" fill="currentColor"><path fill="#010101" d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"></path></svg>'; 134 var iconArrowUpward = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon" viewBox="0 0 24 24" fill="currentColor"><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"></path></svg>'; 135 button.setAttribute('data-order', newOrder); 136 button.querySelector('.sort-arrow').innerHTML = newOrder === 'asc' ? iconArrowUpward : iconArrowDownward; 137 } 138 function sortTerms(criteria, button) { 139 // Select all list items within the taxonomy list 140 const allTerms = Array.from(document.querySelectorAll('.taxonomy-list-shortcode li')); 141 // Fetch the sorting order from the button's data attribute 142 const order = button.getAttribute('data-order'); 143 // Sort the terms based on the specified criteria and order 144 allTerms.sort(function(a, b) { 145 console.log("let's sort"); 146 if (criteria === 'name') { 147 // If sorting by name, compare the text content of the list items 148 const nameA = a.textContent.trim().toLowerCase(); 149 const nameB = b.textContent.trim().toLowerCase(); 150 return order === 'asc' ? nameA.localeCompare(nameB) : nameB.localeCompare(nameA); 151 } else if (criteria === 'count') { 152 // If sorting by count, compare the numeric values of the post counts 153 const countA = parseInt(a.querySelector('.post-count').textContent.trim(), 10); 154 const countB = parseInt(b.querySelector('.post-count').textContent.trim(), 10); 155 return order === 'asc' ? countA - countB : countB - countA; 156 } 157 }); 158 159 // Select the main container of the taxonomy list 160 const mainContainer = document.querySelector('.taxonomy-list-shortcode'); 161 mainContainer.innerHTML = ''; 162 // Append the sorted terms back to the main container 163 allTerms.forEach(function(term) { 164 mainContainer.appendChild(term); 165 }); 166 } 167 168 function removeSubdivisions() { 169 termLetters.forEach(function(letter) { 170 letter.style.display = 'none'; 171 }); 172 } 173 }; 174 175 document.addEventListener('DOMContentLoaded', function() { 176 initFilterSearch(); 177 }); 178 179 document.addEventListener('pjax:complete', function() { 180 initFilterSearch(); 181 }); 182 183})();
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.