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 21, 2024
1 parent ddecbe3 commit 1c708a6
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) => {

Check failure on line 117 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote

Check failure on line 117 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected parentheses around single function argument
if (event.ctrlKey && event.key === "k") {

Check failure on line 118 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
event.preventDefault()

Check failure on line 119 in source/js/third-party/search/algolia-search.js

View workflow job for this annotation

GitHub Actions / linter

Missing semicolon
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) => {

Check failure on line 82 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote

Check failure on line 82 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected parentheses around single function argument
if (event.ctrlKey && event.key === "k") {

Check failure on line 83 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
event.preventDefault()

Check failure on line 84 in source/js/third-party/search/local-search.js

View workflow job for this annotation

GitHub Actions / linter

Missing semicolon
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 1c708a6

Please sign in to comment.