mirror of https://gitlab.crans.org/bde/nk20
Moved js code to the external conso file
This commit is contained in:
parent
5e39209ab1
commit
e32c267995
|
@ -258,3 +258,39 @@ function consume (source, source_alias, dest, quantity, amount, reason, type, ca
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const searchbar = document.getElementById("search-input")
|
||||||
|
const search_results = document.getElementById("search-results")
|
||||||
|
|
||||||
|
var old_pattern = null;
|
||||||
|
var firstMatch = null;
|
||||||
|
/**
|
||||||
|
* Updates the button search tab
|
||||||
|
* @param force Forces the update even if the pattern didn't change
|
||||||
|
*/
|
||||||
|
function updateSearch(force = false) {
|
||||||
|
let pattern = searchbar.value
|
||||||
|
if (pattern === "")
|
||||||
|
firstMatch = null;
|
||||||
|
if ((pattern === old_pattern || pattern === "") && !force)
|
||||||
|
return;
|
||||||
|
firstMatch = null;
|
||||||
|
const re = new RegExp(pattern, "i");
|
||||||
|
Array.from(search_results.children).forEach(function(b) {
|
||||||
|
if (re.test(b.innerText)) {
|
||||||
|
b.hidden = false;
|
||||||
|
if (firstMatch === null) {
|
||||||
|
firstMatch = b;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
b.hidden = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
searchbar.addEventListener("input", function (e) {
|
||||||
|
debounce(updateSearch)()
|
||||||
|
});
|
||||||
|
searchbar.addEventListener("keyup", function (e) {
|
||||||
|
if (firstMatch && e.key === "Enter")
|
||||||
|
firstMatch.click()
|
||||||
|
});
|
||||||
|
|
|
@ -211,41 +211,5 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
});
|
});
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
const searchbar = document.getElementById("search-input")
|
|
||||||
const search_results = document.getElementById("search-results")
|
|
||||||
|
|
||||||
var old_pattern = null;
|
|
||||||
var firstMatch = null;
|
|
||||||
/**
|
|
||||||
* Updates the button search tab
|
|
||||||
* @param force Forces the update even if the pattern didn't change
|
|
||||||
*/
|
|
||||||
function updateSearch(force = false) {
|
|
||||||
let pattern = searchbar.value
|
|
||||||
if (pattern === "")
|
|
||||||
firstMatch = null;
|
|
||||||
if ((pattern === old_pattern || pattern === "") && !force)
|
|
||||||
return;
|
|
||||||
firstMatch = null;
|
|
||||||
const re = new RegExp(pattern, "i");
|
|
||||||
Array.from(search_results.children).forEach(function(b) {
|
|
||||||
if (re.test(b.innerText)) {
|
|
||||||
b.hidden = false;
|
|
||||||
if (firstMatch === null) {
|
|
||||||
firstMatch = b;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
b.hidden = true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
searchbar.addEventListener("input", function (e) {
|
|
||||||
debounce(updateSearch)()
|
|
||||||
});
|
|
||||||
searchbar.addEventListener("keyup", function (e) {
|
|
||||||
if (firstMatch && e.key === "Enter")
|
|
||||||
firstMatch.click()
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue