Skip to content

Commit

Permalink
When the user presses Ctrl + K will target Search Event
Browse files Browse the repository at this point in the history
  • Loading branch information
penxian committed May 22, 2024
1 parent ddecbe3 commit 590b2c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/js/third-party/search/algolia-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ document.addEventListener('DOMContentLoaded', () => {
});
document.querySelector('.popup-btn-close').addEventListener('click', onPopupClose);
document.addEventListener('pjax:success', onPopupClose);
window.addEventListener('keydown', event => {
if (event.ctrlKey && event.key === 'k') {
event.preventDefault();
document.body.classList.add('search-active');
setTimeout(() => input.focus(), 500);
}
});
window.addEventListener('keyup', event => {
if (event.key === 'Escape') {
onPopupClose();
Expand Down
8 changes: 8 additions & 0 deletions source/js/third-party/search/local-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ document.addEventListener('DOMContentLoaded', () => {
localSearch.highlightSearchWords(document.querySelector('.post-body'));
onPopupClose();
});
window.addEventListener('keydown', event => {
if (event.ctrlKey && event.key === 'k') {
event.preventDefault();
document.body.classList.add('search-active');
setTimeout(() => input.focus(), 500);
if (!localSearch.isfetched) localSearch.fetchData();
}
});
window.addEventListener('keyup', event => {
if (event.key === 'Escape') {
onPopupClose();
Expand Down

0 comments on commit 590b2c3

Please sign in to comment.