diff --git a/djangoproject/static/js/mod/search-key.js b/djangoproject/static/js/mod/search-key.js index 578092e890..a131d22f59 100644 --- a/djangoproject/static/js/mod/search-key.js +++ b/djangoproject/static/js/mod/search-key.js @@ -1,20 +1,24 @@ define([ 'jquery' //requires jquery ], function( $ ) { - - var SearchForm = function(search_form) { + const SearchForm = function(search_form) { this.search_form = $(search_form); // the search form this.init(); }; SearchForm.prototype = { init: function(){ - var self = this; + const self = this; $(document).ready(function () { - $(window).keypress(function(e) { - if ($('input:focus, textarea:focus').length === 0 && - e.which === 47) { // The slash is 47. - self.search_form.find('input').focus().select(); + const search_form_input = self.search_form.find('input'); + const raw_placeholder = search_form_input.attr('placeholder'); + const shortcut = navigator.userAgent.indexOf("Mac") === -1 ? "⌘ + K" : "Ctrl + K"; + search_form_input.attr('placeholder', `${raw_placeholder} (${shortcut})`); + + $(window).keydown(function(e) { + if ((e.metaKey || e.ctrlKey) && e.key === 'k' && $('input:focus, textarea:focus').length === 0) { + search_form_input.focus().select(); + search_form_input[0].scrollIntoView({ behavior: "smooth", block: "start" }); return false; } });