Skip to content

Commit 3bfa107

Browse files
Merge pull request #281 from MITLibraries/use-201-spinner
Add / remove spinner on pagination changes
2 parents b1c36d2 + ee418c5 commit 3bfa107

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/javascript/loading_spinner.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ document.addEventListener('turbo:frame-render', function(event) {
2222
if (firstResult) {
2323
firstResult.focus();
2424
}
25+
26+
// Remove the spinner now that things are ready
27+
document.getElementById('search-results').classList.remove('spinner');
28+
2529
// Clear the pending action
2630
window.pendingFocusAction = null;
2731
};
@@ -53,7 +57,12 @@ document.addEventListener('click', function(event) {
5357
// Handle pagination clicks
5458
if (clickedElement.closest('.pagination-container') ||
5559
clickedElement.matches('.first a, .previous a, .next a')) {
60+
// Throw the spinner on the search results immediately
61+
document.getElementById('search-results').classList.add('spinner');
62+
63+
// Position the window at the top of the results
5664
window.scrollTo({ top: 0, behavior: 'smooth' });
65+
5766
window.pendingFocusAction = 'pagination';
5867
}
5968

0 commit comments

Comments
 (0)