|
1 | | -window.addEventListener('DOMContentLoaded', () => { |
2 | | - const searchBarBtn = document.querySelector('.searchbar-btn'); |
3 | | - const searchBarForm = document.querySelector('.searchbar-form'); |
4 | | - const searchBarInput = document.querySelector('.searchbar-form input[type="text"]'); |
| 1 | +const searchBarBtn = document.querySelector('.searchbar-btn'); |
| 2 | +const searchBarForm = document.querySelector('.searchbar-form'); |
| 3 | +const searchBarInput = document.querySelector('.searchbar-form input[type="text"]'); |
5 | 4 |
|
6 | | - searchBarBtn.addEventListener('click', () => { |
7 | | - searchBarForm.classList.remove('visible-md'); |
8 | | - searchBarForm.classList.remove('visible-lg'); |
9 | | - searchBarForm.classList.add('searchbar-open'); |
10 | | - searchBarInput.focus(); |
| 5 | +searchBarBtn.addEventListener('click', () => { |
| 6 | + searchBarForm.classList.remove('visible-md'); |
| 7 | + searchBarForm.classList.remove('visible-lg'); |
| 8 | + searchBarForm.classList.add('searchbar-open'); |
| 9 | + searchBarInput.focus(); |
11 | 10 |
|
12 | | - // Set the width of the autocomplete suggestions when searchbar button gets clicked |
13 | | - const autocompleteSuggestions = document.querySelector('.autocomplete-suggestions'); |
14 | | - const searchBarFormWidth = `${searchBarForm.offsetWidth}px`; |
15 | | - autocompleteSuggestions.style.width = searchBarFormWidth; |
16 | | - }); |
| 11 | + // Set the width of the autocomplete suggestions when searchbar button gets clicked |
| 12 | + const autocompleteSuggestions = document.querySelector('.autocomplete-suggestions'); |
| 13 | + const searchBarFormWidth = `${searchBarForm.offsetWidth}px`; |
| 14 | + autocompleteSuggestions.style.width = searchBarFormWidth; |
| 15 | +}); |
17 | 16 |
|
18 | | - const showSearchBar = () => { |
19 | | - const searchBarOpenInput = document.querySelector('.searchbar-form.searchbar-open input[type="text"]'); |
20 | | - if (searchBarOpenInput) { |
21 | | - if (searchBarInput === document.activeElement) { |
22 | | - searchBarForm.classList.add('searchbar-open'); |
23 | | - searchBarForm.classList.remove('visible-md'); |
24 | | - searchBarForm.classList.remove('visible-lg'); |
25 | | - } else { |
26 | | - searchBarForm.classList.remove('searchbar-open'); |
27 | | - searchBarForm.classList.add('visible-md'); |
28 | | - searchBarForm.classList.add('visible-lg'); |
29 | | - } |
| 17 | +const showSearchBar = () => { |
| 18 | + const searchBarOpenInput = document.querySelector('.searchbar-form.searchbar-open input[type="text"]'); |
| 19 | + if (searchBarOpenInput) { |
| 20 | + if (searchBarInput === document.activeElement) { |
| 21 | + searchBarForm.classList.add('searchbar-open'); |
| 22 | + searchBarForm.classList.remove('visible-md'); |
| 23 | + searchBarForm.classList.remove('visible-lg'); |
| 24 | + } else { |
| 25 | + searchBarForm.classList.remove('searchbar-open'); |
| 26 | + searchBarForm.classList.add('visible-md'); |
| 27 | + searchBarForm.classList.add('visible-lg'); |
30 | 28 | } |
31 | 29 | } |
| 30 | +} |
32 | 31 |
|
33 | | - document.body.addEventListener('click', showSearchBar); |
| 32 | +document.body.addEventListener('click', showSearchBar); |
34 | 33 |
|
35 | | - window.addEventListener('resize', () => { |
36 | | - const searchBarOpenInput = document.querySelector('.searchbar-form.searchbar-open input[type="text"]'); |
37 | | - if (searchBarOpenInput) { |
38 | | - if (searchBarInput === document.activeElement) { |
39 | | - if (document.body.clientWidth >= 992) { |
40 | | - searchBarForm.classList.remove('searchbar-open'); |
41 | | - searchBarForm.classList.add('visible-md'); |
42 | | - searchBarForm.classList.add('visible-lg'); |
43 | | - } else { |
44 | | - searchBarForm.classList.add('searchbar-open'); |
45 | | - searchBarForm.classList.remove('visible-md'); |
46 | | - searchBarForm.classList.remove('visible-lg'); |
47 | | - } |
| 34 | +window.addEventListener('resize', () => { |
| 35 | + const searchBarOpenInput = document.querySelector('.searchbar-form.searchbar-open input[type="text"]'); |
| 36 | + if (searchBarOpenInput) { |
| 37 | + if (searchBarInput === document.activeElement) { |
| 38 | + if (document.body.clientWidth >= 992) { |
| 39 | + searchBarForm.classList.remove('searchbar-open'); |
| 40 | + searchBarForm.classList.add('visible-md'); |
| 41 | + searchBarForm.classList.add('visible-lg'); |
| 42 | + } else { |
| 43 | + searchBarForm.classList.add('searchbar-open'); |
| 44 | + searchBarForm.classList.remove('visible-md'); |
| 45 | + searchBarForm.classList.remove('visible-lg'); |
48 | 46 | } |
49 | 47 | } |
50 | | - }); |
| 48 | + } |
51 | 49 | }); |
0 commit comments