-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
document.addEventListener("click", filterPacks); | ||
function filterPacks() { | ||
const query = document.getElementById("searchBar").value.toLowerCase().trim(); | ||
const resultsDiv = document.getElementById("searchResults"); | ||
|
||
if (query === "") { | ||
if (resultsDiv.hasAttribute("hasMatches")) { | ||
resultsDiv.removeAttribute("hasMatches"); | ||
} | ||
resultsDiv.innerHTML = ""; | ||
return; | ||
} | ||
|
||
const packs = document.querySelectorAll(".tweak"); | ||
let matches = []; | ||
|
||
packs.forEach((pack, index) => { | ||
const title = pack.querySelector(".tweak-title").textContent; | ||
const description = pack.querySelector(".tweak-description").textContent; | ||
const icon = pack.querySelector("img").src; | ||
const isSelected = pack.querySelector("input[type='checkbox']").checked; // Check selection state | ||
|
||
if ( | ||
title.toLowerCase().includes(query) || | ||
description.toLowerCase().includes(query) | ||
) { | ||
matches.push({ | ||
title, | ||
description, | ||
icon, | ||
isSelected, // Track selection state | ||
packIndex: index, // Keep track of the original pack's index | ||
}); | ||
} | ||
}); | ||
|
||
if (matches.length === 0) { | ||
if (resultsDiv.hasAttribute("hasMatches")) { | ||
resultsDiv.removeAttribute("hasMatches"); | ||
} | ||
resultsDiv.innerHTML = ""; | ||
} else { | ||
if (matches.length > 5) matches = matches.slice(0, 5); | ||
resultsDiv.setAttribute("hasMatches", true); | ||
resultsDiv.innerHTML = matches | ||
.map( | ||
(match) => ` | ||
<div | ||
${match.isSelected ? 'oreui-state="active"' : ""} | ||
class="search-result-item" | ||
onclick="triggerPackClick(${match.packIndex})" | ||
style="cursor: pointer;" | ||
oreui-type="button" | ||
oreui-color="dark" | ||
oreui-active-color="green" | ||
> | ||
<img src="${match.icon}" alt="${match.title.trim()}" style="width: 48px; height: 48px;" /> | ||
<div> | ||
<strong>${match.title}</strong> | ||
<p>${match.description}</p> | ||
</div> | ||
</div> | ||
`, | ||
) | ||
.join(""); | ||
} | ||
} | ||
|
||
function triggerPackClick(index) { | ||
// Simulate a click on the corresponding pack | ||
const packs = document.querySelectorAll(".tweak"); | ||
if (packs[index]) { | ||
packs[index].click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.search-container { | ||
margin: 0; | ||
margin-left: 5px; | ||
text-align: center; | ||
} | ||
|
||
.search-results { | ||
margin: 5px auto; | ||
max-width: 80%; | ||
padding: 10px 10px 0 10px; | ||
border-radius: 5px; | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
z-index: 100; | ||
&[hasmatches="true"] { | ||
display: block; | ||
} | ||
&:not(:hover) { | ||
display: none; | ||
} | ||
} | ||
|
||
#searchBar { | ||
width: 95%; | ||
padding: 10px; | ||
font-size: 16px; | ||
&:focus + div[hasmatches="true"] { | ||
display: block; | ||
} | ||
} | ||
|
||
.search-result-item { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
margin-bottom: 10px; | ||
div { | ||
text-align: left; | ||
} | ||
p { | ||
margin: 0; | ||
font-size: 14px; | ||
} | ||
} |