mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
feat(search): Add search shortcuts (/ and ESC)
* Press / to toggle search dialog * Press ESC to close search dialog See #784
This commit is contained in:
parent
e95405f79a
commit
07c9f4f387
1 changed files with 26 additions and 6 deletions
|
@ -251,6 +251,21 @@
|
|||
});
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* Toggle search dialog.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
||||
function toggleSearchDialog() {
|
||||
if ($('body').hasClass('searching')) {
|
||||
$('[id=search-query]').blur();
|
||||
$('body').removeClass('searching');
|
||||
} else {
|
||||
$('body').addClass('searching');
|
||||
$('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200);
|
||||
$('#search-query').focus();
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* On window load.
|
||||
* --------------------------------------------------------------------------- */
|
||||
|
@ -370,14 +385,19 @@
|
|||
// On search icon click toggle search dialog.
|
||||
$('.js-search').click(function(e) {
|
||||
e.preventDefault();
|
||||
if ($('body').hasClass('searching')) {
|
||||
$('body').removeClass('searching');
|
||||
} else {
|
||||
$('body').addClass('searching');
|
||||
$('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200);
|
||||
$('#search-query').focus();
|
||||
toggleSearchDialog();
|
||||
});
|
||||
$(document).on('keydown', function(e){
|
||||
if (e.which == 27) {
|
||||
if ($('body').hasClass('searching')) {
|
||||
toggleSearchDialog();
|
||||
}
|
||||
} else if (e.which == 191) {
|
||||
e.preventDefault();
|
||||
toggleSearchDialog();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue