-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
84 lines (68 loc) · 3.04 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function populateDropdown(category, placeholder) {
const dropdown = document.getElementById('placesDropdown');
dropdown.innerHTML = '';
const defaultOption = document.createElement('option');
defaultOption.value = '';
defaultOption.disabled = true;
defaultOption.selected = true;
defaultOption.hidden = true;
defaultOption.textContent = placeholder;
dropdown.appendChild(defaultOption);
const selectedCategory = document.getElementById(`${category}Result`);
if (selectedCategory) {
const locations = selectedCategory.querySelectorAll('ul');
locations.forEach(location => {
const locationName = location.id.replace(`${category}`, '');
const capitalizedLocation = locationName.charAt(0).toUpperCase() + locationName.slice(1).toLowerCase();
const option = document.createElement('option');
option.value = locationName.toLowerCase();
option.textContent = capitalizedLocation;
dropdown.appendChild(option);
});
}
}
let currentCategory;
function showDropdown(category, placeholder) {
populateDropdown(category, placeholder);
const dropdownContainer = document.getElementById('dropdownContainer');
dropdownContainer.style.display = 'block';
currentCategory = category;
const searchResults = document.getElementById('searchResults');
searchResults.style.display = 'none';
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function showListings(location) {
const allLists = document.querySelectorAll('#searchResults > div > ul');
allLists.forEach(list => {
list.style.display = 'none';
});
const currentCategoryResults = document.getElementById(`${currentCategory}Result`);
currentCategoryResults.style.display = 'block';
function getCategory() {
const suppliesResults = document.getElementById('suppliesResult');
const groomersResults = document.getElementById('groomersResult');
const vetsResults = document.getElementById('vetsResult');
const boardingResults = document.getElementById('boardingResult');
const othersResults = document.getElementById('othersResult');
if (suppliesResults.style.display === 'block') {
return 'supplies';
} else if (groomersResults.style.display === 'block') {
return 'groomers';
} else if (vetsResults.style.display === 'block') {
return 'vets';
} else if (boardingResults.style.display === 'block') {
return 'boarding';
} else if (othersResults.style.display === 'block') {
return 'others';
}
}
const category = getCategory();
const specificLocationList = document.getElementById(`${currentCategory}${capitalizeFirstLetter(location)}`);
if (specificLocationList) {
const searchResults = document.getElementById('searchResults');
searchResults.style.display = 'block';
specificLocationList.style.display = 'block';
}
}