-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsample2.html
62 lines (55 loc) · 1.59 KB
/
sample2.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
<!DOCTYPE html>
<html>
<head>
<title>Measure Caret Position In Textarea</title></title>
<meta charset="UTF-8">
<script type="text/javascript" src="./caretposition.js"></script>
<style>
#textBox {
width: 320px;
height: 240px;
font-size: 14px;
}
#suggestWindow {
position: absolute;
visibility: hidden;
}
</style>
</head>
<body onkeyup="onKeyUp(event)">
<p>push [Esc] key to show/hide Suggest (like) window.</p>
<textarea id="textBox" wrap="off" onclick="onClick(event)"></textarea>
<div id="debug"></div>
<select id="suggestWindow" size="4">
<option>Suggest</option>
<option>Window</option>
<option>like</option>
<option>Sample</option>
</select>
<script type="text/javascript">
function adjustSuggestWindow() {
var textBox = document.getElementById("textBox");
var caretPosition = Measurement.caretPos(textBox);
document.getElementById("debug").innerHTML = "x:" + caretPosition.left + ", " + "y:" + caretPosition.top;
var suggestWindow = document.getElementById('suggestWindow');
suggestWindow.style.top = (caretPosition.top+14) + 'px';
suggestWindow.style.left = caretPosition.left + 'px';
}
// Click in textarea.
function onClick(event) {
adjustSuggestWindow();
}
// Pressed any key.
function onKeyUp(event) {
adjustSuggestWindow();
if (event.keyCode == 27) {
var suggestWindow = document.getElementById('suggestWindow');
suggestWindow.style.visibility = (suggestWindow.style.visibility == 'hidden')?'visible':'hidden';
}
}
setInterval(function () {
adjustSuggestWindow();
}, 100);
</script>
</body>
</html>