@@ -58,42 +58,11 @@ if (toggleContentNav !== null) {
61−function initToggleSearchWindow() {
62− var toggleSearchWindow = document.getElementById('js-search-window-toggle');
63− var bodyEl = document.body;
64− var searchOverlay = document.getElementById('search-overlay');
65− var searchWindow = document.getElementById('search-window');
66− var searchActive = bodyEl.classList.contains('has-active-search-window');
67− var searchInput = document.getElementById('search');
68− if (toggleSearchWindow !== null) {
69− toggleSearchWindow.onclick = function() {
71− bodyEl.classList.toggle('has-active-search-window');
72− //put input in focus when activating search
75− searchOverlay.addEventListener('click', function(e){
76− if (!searchWindow.contains(e.target)){
77− bodyEl.classList.toggle('has-active-search-window');
84 // hotkeys
62 // hotkeys
86−function initHotKeys() {
87− /*document.onkeydown = function(evt) {
88− evt = evt || window.event;
89− if (evt.keyCode == 27) {
92− //when search is active TAB puts search input into focus
65+function initHotKeys() {
93− if (evt.keyCode == 27) {
94− document.body.classList.remove('has-active-search-window');
98 var bodyEl = document.body;
67 var bodyEl = document.body;
99 var searchInput = document.getElementById('search');
68 var searchInput = document.getElementById('search');
@@ -114,9 +83,7 @@ function initHotKeys() {
114 if (bodyEl.classList.contains('has-active-search-window')) {
83 if (bodyEl.classList.contains('has-active-search-window')) {
115 if (key === 'Tab' || key === 'Tab' || key === 9) {
84 if (key === 'Tab' || key === 'Tab' || key === 9) {
116 searchInput.focus();
85 searchInput.focus();
117− console.log('focus');
119− console.log('got here');
@@ -288,6 +255,7 @@ function formatSearchResultItem(item, terms) {
289function initSearch() {
256function initSearch() {
290 var searchInput = document.getElementById("search");
257 var searchInput = document.getElementById("search");
291 if (!searchInput) {
259 if (!searchInput) {
@@ -297,8 +265,6 @@ function initSearch() {
297 var searchResultsItems = document.querySelector(".search-results__items");
265 var searchResultsItems = document.querySelector(".search-results__items");
298 var MAX_ITEMS = 200;
266 var MAX_ITEMS = 200;
300− searchResultsHeader.value='';
302 var options = {
268 var options = {
303 bool: "AND",
269 bool: "AND",
304 fields: {
270 fields: {
@@ -309,7 +275,34 @@ function initSearch() {
309 var currentTerm = "";
275 var currentTerm = "";
310 var index = elasticlunr.Index.load(window.searchIndex);
276 var index = elasticlunr.Index.load(window.searchIndex);
278+ // toggle search window
279+ var toggleSearchWindow = document.getElementById('js-search-window-toggle');
280+ var bodyEl = document.body;
281+ var searchOverlay = document.getElementById('search-overlay');
282+ var searchWindow = document.getElementById('search-window');
283+ var searchActive = bodyEl.classList.contains('has-active-search-window');
284+ if (toggleSearchWindow !== null) {
285+ toggleSearchWindow.onclick = function() {
287+ bodyEl.classList.toggle('has-active-search-window');
288+ //put input in focus when activating search
289+ searchInput.focus();
290+ searchInput.value = "";
291+ searchResultsHeader.value = "";
292+ searchResults.style.display = searchInput.value.trim() === "" ? "none" : "block";
294+ searchOverlay.addEventListener('click', function(e){
295+ if (!searchWindow.contains(e.target)){
296+ bodyEl.classList.toggle('has-active-search-window');
312 searchInput.addEventListener("keyup", debounce(function() {
302 searchInput.addEventListener("keyup", debounce(function() {
304+ searchResultsHeader.value = "";
313 var term = searchInput.value.trim();
306 var term = searchInput.value.trim();
315 if (term === currentTerm || !index) {
308 if (term === currentTerm || !index) {
@@ -347,7 +340,6 @@ if (document.readyState === "complete" ||
347 initToggleSearchWindow();
340 initToggleSearchWindow();
349 document.addEventListener("DOMContentLoaded", function () {
342 document.addEventListener("DOMContentLoaded", function () {
350− initToggleSearchWindow();
351 initSearch();
343 initSearch();
352 initHotKeys();
344 initHotKeys();