@@ -64,9 +64,13 @@ function initToggleSearchWindow() {
6464 var searchOverlay = document.getElementById('search-overlay');
6565 var searchWindow = document.getElementById('search-window');
6666 var searchActive = bodyEl.classList.contains('has-active-search-window');
67+ var searchInput = document.getElementById('search');
6768 if (toggleSearchWindow !== null) {
6869 toggleSearchWindow.onclick = function() {
70+ //activate search
6971 bodyEl.classList.toggle('has-active-search-window');
72+ //put input in focus when activating search
73+ searchInput.focus();
7074 }
7175 searchOverlay.addEventListener('click', function(e){
7276 if (!searchWindow.contains(e.target)){
@@ -80,15 +84,45 @@ function initToggleSearchWindow() {
8084 // hotkeys
8185//
8286function initHotKeys() {
83− document.onkeydown = function(evt) {
87+ /*document.onkeydown = function(evt) {
8488 evt = evt || window.event;
85− // ESC to close search window
89+ if (evt.keyCode == 27) {
90+ }
91+
92+ //when search is active TAB puts search input into focus
8693 if (evt.keyCode == 27) {
8794 document.body.classList.remove('has-active-search-window');
8895 }
89− };
96+ };*/
97+
98+ var bodyEl = document.body;
99+ var searchInput = document.getElementById('search');
100+
101+ document.addEventListener('keyup', function (event) {
102+ if (event.defaultPrevented) {
103+ return;
104+ }
105+
106+ var key = event.key || event.keyCode;
107+
108+ // ESC to close search window
109+ if (key === 'Escape' || key === 'Esc' || key === 27) {
110+ document.body.classList.remove('has-active-search-window');
111+ }
112+
113+ //when search is active TAB puts search input into focus
114+ if (bodyEl.classList.contains('has-active-search-window')) {
115+ if (key === 'Tab' || key === 'Tab' || key === 9) {
116+ searchInput.focus();
117+ console.log('focus');
118+ }
119+ console.log('got here');
120+ }
121+ });
90122};
91123
124+
125+
92126//
93127 // search functionality
94128//