fix: clear search input also clear query (#178)

close #161
This commit is contained in:
sigoden 2023-02-20 12:07:40 +08:00 committed by GitHub
parent 7d6d7d49ca
commit 111103f26b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -37,7 +37,7 @@
<div class="icon">
<svg width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/></svg>
</div>
<input id="search" name="q" type="text" maxlength="128" autocomplete="off" tabindex="1" required>
<input id="search" name="q" type="text" maxlength="128" autocomplete="off" tabindex="1">
<input type="submit" hidden />
</form>
</div>

View file

@ -453,6 +453,7 @@ async function addFileEntries(entries, dirs) {
function getUrl(name) {
let url = location.href.split('?')[0];
if (!url.endsWith("/")) url += "/";
if (!name) return url;
url += name.split("/").map(encodeURIComponent).join("/");
return url;
}
@ -522,10 +523,21 @@ function ready() {
$pathsTableBody = document.querySelector(".paths-table tbody");
$uploadersTable = document.querySelector(".uploaders-table");
$emptyFolder = document.querySelector(".empty-folder");
$searchForm = document.querySelector(".searchbar");
$newFolder = document.querySelector(".new-folder");
if (DATA.allow_search) {
document.querySelector(".searchbar").classList.remove("hidden");
$searchForm.classList.remove("hidden");
$searchForm.addEventListener("submit", event => {
event.preventDefault();
const formData = new FormData($searchForm);
const q = formData.get("q");
let href = getUrl();
if (q) {
href += "?q=" + q;
}
location.href = href;
});
if (PARAMS.q) {
document.getElementById('search').value = PARAMS.q;
}