commit 7367b71f66510e973417f466fdf3efd1642706b5
parent ca790c29734691489483489a183e7bb8d2a514ca
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Thu, 17 Oct 2024 22:00:45 +0200
fix: clean up and document javascript code
Diffstat:
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/index.php b/index.php
@@ -419,8 +419,8 @@
<!-- Script to scroll entire category table into view -->
<script>
scroll_to = function(id) {
- var obj = document.querySelector('#' + id);
- // use a delay of 1ms to the object may already be expanded
+ var obj = document.getElementById(id);
+ // use a delay of 1ms so animations are already accounted for
setTimeout(
function() {
obj.scrollIntoView({
@@ -434,9 +434,13 @@
}
</script>
+ <!-- Script to search through the list of search engines -->
<script>
search_engines = function(bar) {
+ // Get text from search bar
var pat = document.getElementById(bar).value.toLowerCase();
+ // Compare text in article objects with text in search bar
+ // Mark those hidden that do not match
var entries = document.querySelectorAll("article")
for (let i = 0; i < entries.length; i++) {
if (
@@ -447,11 +451,19 @@
entries[i].classList.remove("hidden");
}
}
+ // Scroll back to search bar
setTimeout(scroll_to("engines"), 500);
}
+ </script>
+
+ <!-- Script to search through search engines via category buttons -->
+ <script>
search_for_category = function(category) {
+ // Insert category name into category-searchbar
document.getElementById("engines_searchbar").value = category;
+ // collapse category summary
document.getElementById("categories").open = false;
+ // filter through search engines list
setTimeout(search_engines("engines_searchbar"), 500);
}
</script>