-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtual Keyboard.js
85 lines (81 loc) · 2.12 KB
/
Virtual Keyboard.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
import $ from 'jquery';
import 'virtual-keyboard';
import router from '@/router';
import Timer from '@/modules/common/services/Timer';
const alphaKeyboard = {
normal: [
'{meta1} q w e r t y u i o p ? ! {bksp} {a}',
'{s} a s d f g h j k l \' , . @',
'{t} _ - z x c v b n m {space} {enter}'
],
meta1: [
'{meta1} 1 2 3 {a}',
'{t} 4 5 6 {bksp}',
'7 8 9 0'
],
shift: [
'{meta1} Q W E R T Y U I O P ? ! {bksp} {a}',
'{s} A S D F G H J K L \' , . @',
'{t} _ - Z X C V B N M {space} {enter}'
]
};
const defaultOptions = {
display: {
bksp: ' ',
a: ' ',
space: '\u2334',
meta1: '123',
normal: 'ABC'
},
layout: 'custom',
restrictInput: true,
tabNavigation: true,
usePreview: false,
autoAccept: true,
acceptValid: true,
openOn: 'click',
customLayout: alphaKeyboard,
events: {
keyboardChange: (e, keyboard, element) => {
// In case this event will be overwritten in directive options, it should
// handle v-model update by itself
const event = new Event('input', { bubbles: true });
element.value = $(element).val();
element.dispatchEvent(event);
Timer.restart();
}
}
};
// Initialize the virtual-keyboard directive.
const KeesyKeyboard = {
bind(el, binding) {
const options = Object.assign({}, defaultOptions);
Object.assign(options, binding.value);
let KKeyboard = $(el);
if (options.isContainer) {
KKeyboard = $(el).find('input[type=search]');
}
setTimeout(() => {
KKeyboard = KKeyboard.keyboard(options);
Object.keys(options.events).forEach((item) => {
KKeyboard.bind(item, options.events[item]);
});
if (typeof options.onInit === 'function') {
options.onInit();
}
if (options.keesyKeyboardType === 'numberOnly') {
KKeyboard.bind('visible', (event, keyboard) => {
keyboard.showKeySet('meta1');
});
}
}, 250);
router.beforeEach((from, to, next) => {
const keyboard = KKeyboard.getkeyboard();
if (keyboard) {
keyboard.close();
}
next();
});
}
};
export default KeesyKeyboard;