-- Usage: -- :_ "install DynamicSearch( -- searchResultsElementId: #results-id -- , -- scrollToElementId: #some-id-to-scroll-to -- )" behavior DynamicSearch(searchResultsElementId, scrollToElementId) on click or focus show searchResultsElementId then go to the top of scrollToElementId smoothly on focusout or click from elsewhere wait 200ms if searchResultsElementId is not empty hide searchResultsElementId end on keydown if the event's key is 'Enter' then call event.preventDefault() then hide searchResultsElementId else show searchResultsElementId end on keyup go to the top of scrollToElementId smoothly then show
in searchResultsElementId when (its textContent).toLowerCase() contains (my value).toLowerCase() end