-
Notifications
You must be signed in to change notification settings - Fork 0
/
ime.go
99 lines (93 loc) · 2.07 KB
/
ime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package imepali
import "github.com/gopherjs/gopherjs/js"
var paliInputElement *js.Object
var lastInput string = ""
func checkLastTwoCharacter(lastChar, newChar string) string {
if lastChar == "A" && newChar == "A" {
return "Ā"
}
if lastChar == "a" && newChar == "a" {
return "ā"
}
if lastChar == "A" && newChar == "a" {
return "ā"
}
if lastChar == "I" && newChar == "I" {
return "Ī"
}
if lastChar == "i" && newChar == "i" {
return "ī"
}
if lastChar == "I" && newChar == "i" {
return "ī"
}
if lastChar == "U" && newChar == "U" {
return "Ū"
}
if lastChar == "u" && newChar == "u" {
return "ū"
}
if lastChar == "U" && newChar == "u" {
return "ū"
}
if lastChar == "\"" && newChar == "N" {
return "Ṅ"
}
if lastChar == "\"" && newChar == "n" {
return "ṅ"
}
if lastChar == "." && newChar == "M" {
return "Ṃ"
}
if lastChar == "." && newChar == "m" {
return "ṃ"
}
if lastChar == "~" && newChar == "N" {
return "Ñ"
}
if lastChar == "~" && newChar == "n" {
return "ñ"
}
if lastChar == "." && newChar == "T" {
return "Ṭ"
}
if lastChar == "." && newChar == "t" {
return "ṭ"
}
if lastChar == "." && newChar == "D" {
return "Ḍ"
}
if lastChar == "." && newChar == "d" {
return "ḍ"
}
if lastChar == "." && newChar == "N" {
return "Ṇ"
}
if lastChar == "." && newChar == "n" {
return "ṇ"
}
if lastChar == "." && newChar == "L" {
return "Ḷ"
}
if lastChar == "." && newChar == "l" {
return "ḷ"
}
return ""
}
func paliIME(event *js.Object) {
value := paliInputElement.Get("value").String()
if lastInput != "" && value != "" {
v := value
if len(v) == (len(lastInput) + 1) {
result := checkLastTwoCharacter(lastInput[len(lastInput)-1:], v[len(v)-1:])
if result != "" {
paliInputElement.Set("value", v[:len(v)-2]+result)
}
}
}
lastInput = paliInputElement.Get("value").String()
}
func BindPaliInputMethodToInputTextElementById(id string) {
paliInputElement = js.Global.Get("document").Call("getElementById", id)
paliInputElement.Call("addEventListener", "keyup", paliIME, false)
}