diff options
| author | xengineering <me@xengineering.eu> | 2023-04-28 12:53:49 +0200 | 
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2023-04-28 16:53:10 +0200 | 
| commit | 127aede391be9defffb2d9afd89ef2c1a9e99627 (patch) | |
| tree | a0d54c41b8a4a3d8bd7f202445e9bbe03bcb91c8 | |
| parent | 2d9e1f6aef7abcd436f5cd5e2f5b5974b329b33e (diff) | |
| download | ceres-127aede391be9defffb2d9afd89ef2c1a9e99627.tar ceres-127aede391be9defffb2d9afd89ef2c1a9e99627.tar.zst ceres-127aede391be9defffb2d9afd89ef2c1a9e99627.zip | |
Implement search bar on index page
This is way it is way easier to filter recipes by name.
| -rw-r--r-- | data/templates/index.html | 22 | 
1 files changed, 21 insertions, 1 deletions
| diff --git a/data/templates/index.html b/data/templates/index.html index ab6c243..0b97187 100644 --- a/data/templates/index.html +++ b/data/templates/index.html @@ -16,7 +16,8 @@  		<main>  			<p>Here are the available recipes 😋🍳🍔🍕🥘</p> -			<ul>{{range .}} +			<input id="search" onkeyup="filter()" type="text" placeholder="Search for a recipe ..."></input> +			<ul id="recipes">{{range .}}  				<li><a href="./recipe?id={{.Id}}">{{.Title}}</a></li>{{end}}  			</ul> @@ -24,6 +25,25 @@  		</main> +		<script> +			function filter() { +				var input, query, ul, li, a, i, txtValue; +				input = document.getElementById('search'); +				query = input.value.toUpperCase(); +				ul = document.getElementById("recipes"); +				li = ul.getElementsByTagName('li'); + +				for (i = 0; i < li.length; i++) { +					a = li[i].getElementsByTagName("a")[0]; +					txtValue = a.textContent || a.innerText; +					if (txtValue.toUpperCase().indexOf(query) > -1) { +						li[i].style.display = ""; +					} else { +						li[i].style.display = "none"; +					} +				} +			} +		</script>  	</body>  </html> | 
