Skip to content

Commit

Permalink
Improve search responsiveness when hitting Enter (jdm-contrib#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightfirecat authored Apr 23, 2022
1 parent 44133b7 commit 4f2fe32
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $(function(){
var siteUrl = siteHeader.href.toLowerCase();
var lowerTerm = term.toLowerCase();

// returns true if lowerTerm isn"t found in site title or URL
// returns true if lowerTerm isn't found in site title or URL
return Math.max(siteTitle.indexOf(lowerTerm), siteUrl.indexOf(lowerTerm)) === -1;
});

Expand Down Expand Up @@ -105,6 +105,16 @@ $(function(){
hashUpdateTimer = setTimeout(setWindowHash, 250, $(this).val());
});

// When the user hits enter while in the search bar, update the hash immediately and clear the
// debounce timeout
$("input").on("keypress", function(e) {
var code = e.keyCode || e.which;
if (code === 13) { // Enter key
window.clearTimeout(hashUpdateTimer);
setWindowHash($(this).val());
}
});

// Call updateSearch when hash changes
$(window).on("hashchange", function() {
updateSearch();
Expand Down

0 comments on commit 4f2fe32

Please sign in to comment.