Skip to content

Commit

Permalink
search: Extract updateStatusBox function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-w committed Aug 21, 2024
1 parent d1f2b54 commit 2ee61b0
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions _includes/search-dictionary.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
}

// Report results.
const foundMessage = 'Found ' +
entryCount +
(' entr' + (entryCount !== 1 ? 'ies' : 'y')) +
' whose plaintext contains ' +
('“' + query + '”.');
updateStatusBox({ showAll, entryCount, foundMessage });
}

function updateStatusBox({ showAll, entryCount, foundMessage }) {
const statusBox = document.querySelector('#search-dictionary-results')
statusBox.classList.remove(
'is-info',
Expand All @@ -112,12 +121,7 @@
statusBox.textContent = 'Search cleared. All entries and examples shown.'
} else {
statusBox.classList.add(entryCount > 0 ? 'is-success' : 'is-warning')
statusBox.textContent =
'Found ' +
entryCount +
(' entr' + (entryCount !== 1 ? 'ies' : 'y')) +
' whose plaintext contains ' +
('“' + query + '”.')
statusBox.textContent = foundMessage
}
}

Expand Down Expand Up @@ -156,28 +160,15 @@
}

// Report results.
const statusBox = document.querySelector('#search-dictionary-results')
statusBox.classList.remove(
'is-info',
'is-success',
'is-warning',
'is-hidden'
)
if (showAll) {
statusBox.classList.add('is-info')
statusBox.textContent = 'Search cleared. All entries and examples shown.'
} else {
statusBox.classList.add(entryCount > 0 ? 'is-success' : 'is-warning')
statusBox.textContent =
'Showing ' +
const foundMessage = 'Showing ' +
totalMatchCount +
(' example' + (totalMatchCount !== 1 ? 's' : '')) +
' across ' +
entryCount +
(' entr' + (entryCount !== 1 ? 'ies' : 'y')) +
' with Orthic notation containing ' +
('“' + query + '”.')
}
updateStatusBox({ showAll, entryCount, foundMessage });
}

function searchForNothing(event) {
Expand Down

0 comments on commit 2ee61b0

Please sign in to comment.