forked from jcubic/jquery.terminal-www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtualKeyboard.html
164 lines (158 loc) · 4.88 KB
/
virtualKeyboard.html
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
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="Description" content=""/>
<link rel="shortcut icon" href=""/>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--
<link href="css/style.css" rel="stylesheet"/>
-->
<link href="css/jquery.terminal.css" rel="stylesheet"/>
<link href="css/jquery-ui.min.css" rel="stylesheet"/>
<link href="keyboard/keyboard.css" rel="stylesheet"/>
<style>
body {
margin: 0;
padding: 0;
}
#keyboard-wrapper {
position: relative;
}
#keyboard-wrapper textarea {
position: absolute;
clip: rect(0,0,0,0);
}
.ui-keyboard {
border-width: 1px 0 0 0;
border-radius: 0;
}
button {
outline: none;
}
#keyboard-wrapper .ui-keyboard {
top: 0 !important;
margin-top: -1px; /* fix 1px border */
}
.terminal {
height: calc(100vh - var(--keyboard-height));
box-sizing: border-box;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/jquery.mousewheel-min.js"></script>
<script src="js/jquery.terminal.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="keyboard/jquery.keyboard.min.js"></script>
<script>
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| 'onmsgesturechange' in window; // works on ie10
}
$(function() {
$.keyboard.keyaction.pageup = function() {
term.scroll(-10);
};
$.keyboard.keyaction.pagedown = function() {
term.scroll(10);
};
$.keyboard.keyaction.foo = function() {
console.log('foo');
};
var keyboard = $('textarea').keyboard({
layout: 'custom',
customLayout: {
'default': [
'` 1 2 3 4 5 6 7 8 9 0 - = {bksp}',
'{tab} q w e r t y u i o p [ ] \\',
'a s d f g h j k l ; \' {enter}',
'{shift} z x c v b n m , . / {shift} {pageup}',
'{sp:2} {alt} {space} {sp:1} {left} {right} {pagedown}'
],
'shift': [
'~ ! @ # $ % ^ & * ( ) _ + {bksp}',
'{tab} Q W E R T Y U I O P { } |',
'A S D F G H J K L : " {enter}',
'{shift} Z X C V B N M < > ? {shift}',
'{space} {left} {right}'
]
},
display: { 'pageup': 'pgUp', 'pagedown': 'pgDown' },
usePreview: false,
alwaysOpen: true,
stayOpen: true,
appendTo: '#keyboard-wrapper'
}).getkeyboard().reveal();
// there is no other easy way to make cursor working with keyboard
// the result of this is that textarea can have garbage
(function(insertText) {
keyboard.insertText = function(text) {
if (text == 'bksp') {
var e = $.Event("keydown");
e.which = 8;
$root.trigger(e);
} else {
term.insert(text);
}
//return insertText.apply(keyboard, [].slice.call(arguments));
};
})(keyboard.insertText);
var $root = $(document.documentElement || window);
// proper use of API
$.extend($.keyboard.keyaction, {
enter: function(base, el, e) {
var event = $.Event("keydown");
event.which = event.keyCode = 13;
event.shiftKey = e.shiftKey;
$root.trigger(event);
},
tab: function(base, el, e) {
var event = $.Event("keydown");
event.which = 9;
event.shiftKey = e.shiftKey;
$root.trigger(event);
return false;
},
left: (function(left) {
return function(base, el, e) {
// match terminal postion with
var cmd = term.cmd();
cmd.position(-1, true);
left.apply(this, [].slice.call(arguments));
};
})($.keyboard.keyaction.left),
right: (function(right) {
return function(base, el, e) {
var cmd = term.cmd();
cmd.position(1, true);
right.apply(this, [].slice.call(arguments));
};
})($.keyboard.keyaction.right)
});
var intepreter = {
foo: function() {
this.echo('bar');
},
help: function() {
this.echo('Avaiable commands: ' + Object.keys(intepreter).join(', '));
}
};
var term = $('#term').terminal(intepreter, {
name: 'virtual',
greetings: 'Virtual Keyboard Demo',
completion: true
});
document.body.style.setProperty('--keyboard-height', $('#keyboard-wrapper').height() + 'px');
});
</script>
</head>
<body>
<div id="term"></div>
<div id="keyboard-wrapper">
<textarea></textarea>
</div>
</body>
</html>