-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch.html
More file actions
172 lines (156 loc) · 6.54 KB
/
search.html
File metadata and controls
172 lines (156 loc) · 6.54 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html>
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4RN7HSGW86"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-4RN7HSGW86');
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Staying Healthy Home</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400" rel="stylesheet" />
<link href="css/templatemo-style.css" rel="stylesheet" />
<script src="data.js"></script>
</head>
<body>
<div class="container">
<!-- Top box -->
<!-- Logo & Site Name -->
<div class="placeholder">
<div class="parallax-window" data-parallax="scroll" data-image-src="img/theme/search_slider.jpg">
<div class="tm-header">
<div class="header_row tm-header-inner">
<div class="col-md-6 col-12">
<img src="img/logo/logo1_notext-removebg.png" alt="Logo" class="tm-site-logo" />
<div class="tm-site-text-box">
<h1 class="tm-site-title">Staying Healthy</h1>
<h6 class="tm-site-description">Eating clean has never been easier !</h6>
</div>
</div>
<nav class="col-md-6 col-12 tm-nav">
<ul class="tm-nav-ul">
<li class="tm-nav-li"><a href="index.html" class="tm-nav-link">Home</a></li>
<li class="tm-nav-li"><a href="search.html" class="tm-nav-link active">Search</a></li>
<li class="tm-nav-li"><a href="about.html" class="tm-nav-link">About</a></li>
<li class="tm-nav-li"><a href="contact.html" class="tm-nav-link">Contact</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<main>
<header class="row tm-welcome-section">
<h2 class="col-12 text-center tm-section-title">Tell Us Your Desires</h2>
<p class="col-12 text-center">We'll make an effort to suggest recipes on our website that fit your preferences. Because of the calorie restriction, the outcome can resemble your request somewhat but not exactly.</p>
</header>
<div class="row-search">
<div class="col-12">
<h4 class="tm-info-title tm-text-success">Choose Your Ingredients</h4>
<div class="form-group">
<textarea id="inputIngre" rows="5" name="ingred" class="form-control" placeholder="Ex: salmon, chicken, beef... (Keyword should be in lower case)" required=""></textarea>
</div>
</div>
<div class="col-12">
<h4 class="tm-info-title tm-text-success">Energy in kcal</h4>
<div class="range-wrap">
<div class="range-value" id="rangeV"></div>
<input id="range" type="range" min="0" max="2500" value="0" step="1">
<div class="form-group">
<input id="rangeNum" type="number" min="0" max="2500" class="form-control">
</div>
<div id="rangeNumSub" class="form-group tm-d-flex">
<button type="submit" class="tm-btn tm-btn-success tm-btn-right">
OK
</button>
</div>
</div>
<script>
const range = document.getElementById('range');
const rangeV = document.getElementById('rangeV');
const setValue = ()=>{
const newValue = Number((range.value - range.min) * 100 / (range.max - range.min));
const newPosition = 10 - (newValue * 0.2);
rangeV.innerHTML = `<span>${range.value}</span>`;
rangeV.style.left = `calc(${newValue}% + (${newPosition}px))`;
};
const setValue2 = ()=>{
const temp = document.getElementById('rangeNum').value;
range.value = temp;
const newValue = Number((temp - rangeNum.min) * 100 / (rangeNum.max - rangeNum.min));
const newPosition = 10 - (newValue * 0.2);
rangeV.innerHTML = `<span>${rangeNum.value}</span>`;
rangeV.style.left = `calc(${newValue}% + (${newPosition}px))`;
};
document.addEventListener("DOMContentLoaded", setValue);
range.addEventListener('input', setValue);
document.getElementById('rangeNumSub').addEventListener('click', setValue2);
</script>
</div>
<div class="col-12">
<div class="form-group tm-d-flex">
<button id="inputSub" type="submit" class="tm-btn tm-btn-success tm-btn-right">
Search
</button>
</div>
</div>
<div class="col-12">
<h4 class="tm-info-title tm-text-success">Result</h4>
<ul class="tm-gallery-description text-justify" id="recipeList"></ul>
</div>
<script>
document.getElementById("inputSub").addEventListener("click", function (){
const inputCalo1 = document.getElementById("rangeNum").value;
const inputCalo2 = document.getElementById("range").value;
const inputIngre = document.getElementById("inputIngre").value;
// console.log(inputIngre);
const inputIngreArray = inputIngre.split(", ");
// console.log(inputIngreArray);
const recipeDis = recipes.filter(
// console.log(inputIngreArray);
// console.log(recipe.ingre);
(recipe) => inputIngreArray.every(
(item) => (recipe.ingr_search.includes(item) && recipe.calo <= inputCalo1) || (recipe.ingr_search.includes(item) && recipe.calo <= inputCalo2)
)
);
console.log(recipeDis);
// clear input
document.getElementById("inputIngre").value = "";
document.getElementById("rangeNum").value = 0;
document.getElementById("range").value = 0;
// clear current list
document.getElementById("recipeList").innerHTML = "";
// display new filtered list
if(recipeDis==""){
document.getElementById("recipeList")
let listItem = document.createElement("li");
listItem.innerHTML = "Sorry but we were unable to locate a recipe that met your requirements. Change the component or the amount of energy!"
document.getElementById("recipeList").appendChild(listItem);
} else{
recipeDis.forEach((element) => {
let listItem = document.createElement("li");
let listItemA = document.createElement("a");
listItemA.innerHTML = element.title;
listItemA.href = "recipe.html?id=" + element.id;
listItem.appendChild(listItemA);
console.log(listItem);
document.getElementById("recipeList").appendChild(listItem);
});
}
});
</script>
</div>
</main>
<footer class="tm-footer text-center">
<p>Copyright © 2023 Staying Healthy</p>
</footer>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/parallax.min.js"></script>
</body>
</html>