add. ime for real

This commit is contained in:
2022-06-09 02:29:42 +02:00
parent 9c513f8319
commit 57ea079eaf
3 changed files with 23 additions and 1 deletions

20
main.js
View File

@@ -5,6 +5,19 @@ let searchDictionary = {};
let header = null;
let main = null;
let ime = null;
function toggleIME() {
if (ime == null) {
ime = new HeonianIME(header.querySelector("input"));
header.querySelector("#search button").style.color = "var(--fg)";
} else {
ime.imeDetach();
ime = null;
header.querySelector("#search button").style.color = "var(--grey)";
}
}
function animateHeader(inout = false) {
//todo: debounce this
if (inout) {
@@ -47,10 +60,14 @@ document.addEventListener("keydown", (e) => {
if (!header.querySelector("input").matches(":focus") && !header.classList.contains("fullscreen")) {
e.preventDefault();
animateHeader(true);
} else if (header.querySelector("input").matches(":focus") && ime != null) {
toggleIME();
} else if (header.querySelector("input").matches(":focus")) {
header.querySelector("input").value = "";
}
}
if (e.keyCode === 13) {
if (header.querySelector("input").matches(":focus")) {
if (header.querySelector("input").matches(":focus") && ime == null) {
//search
e.preventDefault();
if (header.classList.contains("fullscreen")) {
@@ -262,5 +279,6 @@ function doSearch() {
window.onload = () => {
header = document.querySelector("header");
main = document.querySelector("main");
header.querySelector("#search button").onclick = () => {toggleIME();};
loadDictionary();
}