Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions djangoproject/static/js/mod/search-key.js
Original file line number Diff line number Diff line change
@@ -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;
}
});
Expand Down