-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
167 lines (145 loc) · 4.82 KB
/
main.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var isMobileWidth = false;
let Keyboard = window.SimpleKeyboard.default;
let keyboard = new Keyboard({
onChange: function(input){ onChange(input) },
onKeyPress: function(button) { onKeyPress(button) },
physicalKeyboardHighlight: true,
maxLength: 70,
mergeDisplay: true,
onInit: function() {
$('body').addClass('keyboard-shown');
//$(".simple-keyboard-input").focus();
},
layout: null,
display: {}
});
resizeHandler();
function onChange(input) {
if(!window.skTagline){
window.skTagline = document.querySelector('.tagSndLine').textContent;
}
document.querySelector(".tagSndLine").textContent = input || window.skTagline;
console.log("Input changed", input);
}
function onKeyPress(button) {
console.log("Button pressed", button);
if (button === "{shiftleft}" || button === "{shiftright}" || button === "{capslock}" || button === "{shift}" || button === "{lock}") handleShift();
if (button === "{numbers}" || button === "{abc}") handleNumbers();
if($('.dot_icon').hasClass('circ_animate')){
$('.dot_icon').removeClass('circ_animate');
}
}
function handleShift() {
let currentLayout = keyboard.options.layoutName;
let shiftToggle = currentLayout === "default" ? "shift" : "default";
keyboard.setOptions({
layoutName: shiftToggle
});
}
function handleNumbers() {
let currentLayout = keyboard.options.layoutName;
let numbersToggle = currentLayout !== "numbers" ? "numbers" : "default";
keyboard.setOptions({
layoutName: numbersToggle
});
}
document.addEventListener('keydown', function(e) {
if(e.key === "Tab"){
e.preventDefault();
}
});
window.addEventListener('resize', resizeHandler);
window.addEventListener('orientationchange', resizeHandler);
function resizeHandler(){
if (window.innerWidth <= 850){
if(!isMobileWidth){
isMobileWidth = true;
keyboard.setOptions({
mergeDisplay: true,
layoutName: "default",
layout: {
'default': [
'q w e r t y u i o p',
'a s d f g h j k l',
'{shiftleft} z x c v b n m {backspace}',
'{numbers} {space} {ent}'
],
'shift': [
'Q W E R T Y U I O P',
'A S D F G H J K L',
'{shiftleft} Z X C V B N M {backspace}',
'{numbers} {space} {ent}'
],
'numbers': [
"1 2 3",
"4 5 6",
"7 8 9",
"{abc} 0 {backspace}",
]
},
display: {
"{numbers}": "123",
"{ent}": "return",
"{escape}": "esc ⎋",
"{tab}": "tab ⇥",
"{backspace}": "⌫",
"{capslock}": "caps lock ⇪",
"{shiftleft}": "⇧",
"{shiftright}": "shift ⇧",
"{controlleft}": "ctrl ⌃",
"{controlright}": "ctrl ⌃",
"{altleft}": "alt ⌥",
"{altright}": "alt ⌥",
"{metaleft}": "cmd ⌘",
"{metaright}": "cmd ⌘",
"{abc}": "ABC"
}
});
//document.querySelector(".simple-keyboard-input").setAttribute("placeholder", "Tap on the keyboard");
mobileDisableInput();
}
} else {
if(isMobileWidth){
isMobileWidth = false;
keyboard.setOptions({
mergeDisplay: true,
layoutName: "default",
layout: {
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {backspace}',
'{tab} q w e r t y u i o p [ ] \\',
'{capslock} a s d f g h j k l ; \' {enter}',
'{shiftleft} z x c v b n m , . / {shiftright}',
'.com @ {space}'
],
'shift': [
'~ ! @ # $ % ^ & * ( ) _ + {backspace}',
'{tab} Q W E R T Y U I O P { } |',
'{capslock} A S D F G H J K L : " {enter}',
'{shiftleft} Z X C V B N M < > ? {shiftright}',
'.com @ {space}'
]
},
display: {}
});
//document.querySelector(".simple-keyboard-input").setAttribute("placeholder", "Tap on the keyboard or type to start");
allowInput();
}
}
}
function mobileDisableInput(){
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
//document.querySelector(".simple-keyboard-input").setAttribute("readonly", "true");
keyboard.setOptions({
physicalKeyboardHighlight: false
});
$('body').addClass("mobile");
} else {
$('body').removeClass("mobile");
}
}
function allowInput(){
keyboard.setOptions({
physicalKeyboardHighlight: true
});
}