🐛 fix(search): close modal when clicking current page result (#350)
This commit is contained in:
parent
0f18ac264d
commit
f72f454ea7
@ -3013,6 +3013,24 @@ window.onload = function () {
|
||||
}
|
||||
});
|
||||
|
||||
results.addEventListener('click', function(event) {
|
||||
const clickedElement = event.target.closest('a');
|
||||
if (clickedElement) {
|
||||
const clickedHref = clickedElement.getAttribute('href');
|
||||
const currentPageUrl = window.location.href;
|
||||
|
||||
// Normalise URLs by removing the text fragment and trailing slash.
|
||||
const normalizeUrl = (url) => url.split('#')[0].replace(/\/$/, '');
|
||||
|
||||
// Check if the clicked link matches the current page.
|
||||
// If using Ctrl+click or Cmd+click, don't close the modal.
|
||||
if (normalizeUrl(clickedHref) === normalizeUrl(currentPageUrl) &&
|
||||
!event.ctrlKey && !event.metaKey) {
|
||||
closeModal();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add touch events to the results.
|
||||
setupTouchEvents();
|
||||
},
|
||||
|
2
static/js/searchElasticlunr.min.js
vendored
2
static/js/searchElasticlunr.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user