mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-14 14:17:07 +00: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:
1 parent
e95405f79a
commit
07c9f4f387
1 file changed
+26
-6
+26
-6
@@ -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);
|
||||
Reference in new issue
Block a user