<head>
<script src="vopamoi.js" defer="true"></script>
</head>
- <body>
+ <body onload="browserInit();">
<form onsubmit="return browserCreateTask(this);">
<input name="taskName">
</form>
document.body.appendChild(createTask(description));
}
+function moveCursor(offset: number) {
+ var active = document.activeElement;
+ if (offset === 1 && active) {
+ active = active.nextElementSibling;
+ }
+ if (offset === -1 && active) {
+ active = active.previousElementSibling;
+ }
+ if (active && active instanceof HTMLElement) active.focus();
+}
+
+function handleKey(event: any) {
+ if (event.target.tagName !== "INPUT") {
+ if (event.key == "j") moveCursor(1);
+ if (event.key == "k") moveCursor(-1);
+ }
+}
+
function browserCreateTask(form: any) {
addTask(form.taskName.value);
form.taskName.value = "";
return false;
}
+
+function browserInit() {
+ document.body.addEventListener("keydown", handleKey, { capture: false });
+}