+
+function showSearchDialog() {
+ if (searchDialog.open) {
+ return;
+ }
+ searchDialog.show();
+ searchInput.focus();
+
+ const clickListener = e => {
+ if(!e.target.closest('dialog')) {
+ closeListener();
+ }
+ };
+
+ const escListener = e => {
+ if (e.key === 'Escape') {
+ closeListener();
+ }
+ };
+
+ const mouseLeaveListener = e => {
+ closeListener();
+ }
+
+ const closeListener = () => {
+ searchDialog.close();
+ document.removeEventListener('click', clickListener);
+ document.removeEventListener('keydown', escListener);
+ searchForm.removeEventListener('mouseleave', mouseLeaveListener);
+ };
+
+ document.addEventListener('click', clickListener);
+ document.addEventListener('keydown', escListener);
+ searchForm.addEventListener('mouseleave', mouseLeaveListener);
+}
+
+function showSearchLoading() {
+ searchDialog.innerHTML = `<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>`;
+ showSearchDialog();
+}
+
+searchForm.addEventListener('submit', event => {
+ event.preventDefault();
+ showSearchLoading();
+ runSearch();
+});
+
+searchInput.addEventListener('input', event => {
+ const termLength = searchInput.value.length;
+ if (termLength === 0) {
+ searchDialog.close();
+ } else if (termLength > 2) {
+ showSearchLoading();
+ runSearch();
+ }
+});
+
+
+// Email display
+const emailDisplayLinks = document.querySelectorAll('a.email-display');
+const eb64 = 'ZW1haWxAYm9v' + 'a3N0YWNrYXBwLmNvbQ==';
+for (const link of emailDisplayLinks) {
+ const email = atob(eb64);
+ link.addEventListener('click', e => {
+ e.preventDefault();
+ e.target.textContent = email;
+ e.target.href = 'mailto:' + email;
+ });
+}
\ No newline at end of file