Add a new javascript block to populate the dropdown from the items in the gutter, and handles the interactivity when an item is chosen.
expression_detail.html
<script>constselect=document.getElementById('select-enrichments');// add a mutation observer to take action when items are added to the gutterfunctionupdateHighlightOptions () {// empty the optionswhile (select.firstChild) select.removeChild(select.firstChild);// add the empty optionconstoption=document.createElement('option');option.innerText ="(off)";option.value ="";select.appendChild(option);// unique text of gutter itemsconstitems= [...newSet([...document.querySelectorAll('la-gutter-item')].map((item) =>item.innerText))];items.sort();// add the items as options to the dropdownfor (constitemof items) {constoption=document.createElement('option');option.innerText = item;option.value = item;select.appendChild(option); } }constobserver=newMutationObserver(() => {window.setTimeout(updateHighlightOptions,500); });observer.observe(document.getElementById('gutter'), { childList:true });updateHighlightOptions();// when the select changes, highlight the provisions that match by adding a class to those provisionsselect.addEventListener('change', (e) => {constdoc=document.getElementsByTagName('la-akoma-ntoso')[0];// remove any existing highlightsfor (constprovisionofdocument.querySelectorAll('.highlight')) {provision.classList.remove('highlight'); }constselected=e.target.value;if (selected) {// turn on highlightingdoc.classList.add('highlighting');// mark each highlighted elementfor (constitemofdocument.querySelectorAll('la-gutter-item')) {if (item.innerText === selected) {constanchor=item.getAttribute('anchor');constprovision=doc.querySelector(`[id="${anchor.slice(1)}"]`);if (provision) {provision.classList.add('highlight'); } } } } else {// turn off highlightingdoc.classList.remove('highlighting'); } });</script>
Finally, let's add the necessary styling to handle the new .highlight and .highlighting classes.
Add this block in the <head> tag of expression_detail.html.