-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdungankeyboard.js
59 lines (58 loc) · 1.78 KB
/
dungankeyboard.js
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
eventCode = {
"KeyQ": "й",
"KeyW": "ц",
"KeyE": "у",
"KeyR": "к",
"KeyT": "е",
"KeyY": "н",
"KeyU": "г",
"KeyI": "ш",
"KeyO": "щ",
"KeyP": "з",
"BracketLeft": "х",
"BracketRight": "ў",
"Backslash": "ё",
"KeyA": "ф",
"KeyS": "ы",
"KeyD": "в",
"KeyF": "а",
"KeyG": "п",
"KeyH": "р",
"KeyJ": "о",
"KeyK": "л",
"KeyL": "д",
"Semicolon": "ж",
"Quote": "э",
"KeyZ": "я",
"KeyX": "ч",
"KeyC": "с",
"KeyV": "м",
"KeyB": "и",
"KeyN": "т",
"KeyM": "җ",
"Comma": "б",
"Period": "ю",
"Slash": "ң",
}
document.addEventListener("DOMContentLoaded", function(){
var textarea = [].slice.call(document.getElementsByTagName("textarea"))[0]
var key = [].slice.call(document.getElementsByClassName('key'))
key.forEach((element, index) => {
element.addEventListener('click', (event) => {
textarea.value += event.target.textContent.trim().charAt(0)
})
})
this.addEventListener('keydown', event => {
if(Object.keys(eventCode).includes(event.code)) event.preventDefault()
if(eventCode[event.code] !== undefined){
textarea.value += eventCode[event.code]
if(event.code != "Enter" && event.code != "Space") document.getElementById(event.code).style.backgroundColor = "#2aa198"
if(event.code == "Enter") textarea.value = ""
update(textarea.value)
}
})
this.addEventListener('keyup', event => {
if(Object.keys(eventCode).includes(event.code)) event.preventDefault()
if(eventCode[event.code] !== undefined && event.code != "Enter" && event.code != "Space") document.getElementById(event.code).style.backgroundColor = "#fdf6e3"
})
})