blob: 4138fdee4b80dbb9ea72d523dff98505f9416fed [file] [log] [blame]
Huguet57ae6d9742018-07-23 01:07:26 +02001// Get the box
2var searchBox = document.getElementById('searchBox');
3
4// Get the button that opens the box
5var searchButton = document.getElementById("searchButton");
6
7// Get the <span> element that closes the box
8var closeBox = document.getElementsByClassName("closeBox")[0];
9
10// When the user clicks the button, open the box
11searchButton.onclick = function() {
12 searchBox.style.display = "block";
Huguet57004b1552018-07-23 03:29:12 +020013 // Focus on the search input bar
14 document.getElementById("searchInput").focus();
Huguet57ae6d9742018-07-23 01:07:26 +020015}
16
17// When the user clicks on <span> (x), close the box
18closeBox.onclick = function() {
19 searchBox.style.display = "none";
Huguet57004b1552018-07-23 03:29:12 +020020 // Empty the input bar
21 var searchInput = document.getElementById('searchInput');
22 searchInput.value = "";
Huguet57ae6d9742018-07-23 01:07:26 +020023}
24
25// When the user clicks anywhere outside of the box, close it
26window.onclick = function(event) {
27 if (event.target == searchBox) {
28 searchBox.style.display = "none";
Huguet57004b1552018-07-23 03:29:12 +020029 // Empty the input bar
30 var searchInput = document.getElementById('searchInput');
31 searchInput.value = "";
Huguet57ae6d9742018-07-23 01:07:26 +020032 }
33}