Files
reallife-gamemode/ReallifeGamemode.Client/assets/js/inputhelper/application.js

71 lines
1.5 KiB
JavaScript

let content = document.getElementById('content');
let heading = document.getElementById('heading');
let description = document.getElementById('description');
let input = document.getElementById('input');
let close = document.getElementById('close');
function setInputFieldType(value) {
if (input.type == value) return;
var field = document.createElement('input');
field.type = value;
field.id = input.id;
field.name = input.name;
input.parentNode.replaceChild(field, input);
input = field;
input.focus();
return field;
}
function setText(heading, description) {
setHeading(heading);
setDescription(description);
}
function setHeading(value) {
heading.innerText = value;
}
function setDescription(value) {
if (value.length <= 5) {
description.remove();
return false;
}
description.innerText = value;
}
function removeDescription() {
document.removeChild(description);
}
function getInput() {
return input.value.length != 0 ? input.value : null;
}
/* Enter wird im Input-Feld gedrückt */
input.onkeyup = e => {
let code = e.keyCode ? e.keyCode : e.which;
if (code === 13) {
// TODO: Wert entgegennehmen
closeWindow();
}
}
/* ESC wird gedrückt */
document.onkeyup = e => {
let code = e.keyCode ? e.keyCode : e.which;
if (code === 27) { closeWindow(); }
}
close.onclick = e => {
mp.trigger('closeinputhelper');
console.log('Fenster geschlossen!');
}
setInputFieldType('text');