You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
Commands-Creator/public/scripts/functions.js

34 lines
1.0 KiB

function search(dropdown, searchbar, JSON, className) {
q(dropdown).innerHTML = "";
// Get JSON
axios.get(JSON).then(res => {
var searchElement = Object.keys(res.data);
for (var i = 0; i < searchElement.length; i++) {
// Check if matches
if (searchElement[i].match(q(searchbar).value.toLowerCase().replace(/ /gi, "_").replace("minecraft:", ""))) {
// Create dropdown item
found = searchElement[i];
var format = capitalize(found.replace(/_/gi, " "));
var a = c("a");
a.addEventListener("click", x => {
setBlock(x.target.innerHTML)
});
a.innerHTML = format;
a.className = "dropdown-item " + className;
q(dropdown).appendChild(a);
};
};
});
}
function upperCase(str) {
return str.toUpperCase();
};
function capitalize(str) {
var firstLetterRx = /(^|\s)[a-z]/g;
return str.replace(firstLetterRx, upperCase);
};