on master help sign in
period or / hotkey now invokes and puts to sleep search window
ed977bffriederjanmoerman
static/scripts.js+12−4
@@ -67,7 +67,7 @@ function initHotKeys() {
67 var bodyEl = document.body;
67 var bodyEl = document.body;
68 var searchInput = document.getElementById('search');
68 var searchInput = document.getElementById('search');
69
69
70− document.addEventListener('keyup', function (event) {
70+ document.addEventListener('keydown', function (event) {
71 if (event.defaultPrevented) {
71 if (event.defaultPrevented) {
72 return;
72 return;
73 }
73 }
@@ -77,6 +77,16 @@ function initHotKeys() {
77 // ESC to close search window
77 // ESC to close search window
78 if (key === 'Escape' || key === 'Esc' || key === 27) {
78 if (key === 'Escape' || key === 'Esc' || key === 27) {
79 document.body.classList.remove('has-active-search-window');
79 document.body.classList.remove('has-active-search-window');
80+ console.log('esc');
81+ }
82+
83+ // / to close toggle window
84+ if (key === '/' || key === 'Period' || key === 58) {
85+ event.preventDefault();
86+ document.body.classList.toggle('has-active-search-window');
87+ if (bodyEl.classList.contains('has-active-search-window')) {
88+ searchInput.focus();
89+ }
80 }
90 }
81
91
82 //when search is active TAB puts search input into focus
92 //when search is active TAB puts search input into focus
@@ -88,8 +98,6 @@ function initHotKeys() {
88 });
98 });
89};
99};
90
100
91−
92−
93//
101//
94 // search functionality
102 // search functionality
95//
103//
@@ -303,7 +311,7 @@ function initSearch() {
303 searchResultsHeader.value = "";
311 searchResultsHeader.value = "";
304
312
305 var term = searchInput.value.trim();
313 var term = searchInput.value.trim();
306−
314+
307 /*
315 /*
308 //removed to fix: a state where there’s a valid search term, but no results
316 //removed to fix: a state where there’s a valid search term, but no results
309
317