-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (45 loc) · 1.47 KB
/
index.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
(function(){
'use strict';
var editor = document.getElementById('js-editor');
var isComposition = false;
//----------------------------------------------------------------------------
document.addEventListener('selectionstart', onSelectionstart, false);
document.addEventListener('selectionchange', onSelectionchange, false);
function onSelectionstart(event) {
console.log(event);
}
function onSelectionchange(event) {
console.log(event);
var sel = window.getSelection();
console.log(sel.toString());
console.log(sel.anchorNode, sel.anchorOffset);
console.log(sel.focusNode, sel.focusOffset);
}
//----------------------------------------------------------------------------
editor.addEventListener('beforeinput', onBeforeInput, false);
editor.addEventListener('input', onInput, false);
editor.addEventListener('keydown', onKeydown, false);
editor.addEventListener('compositionstart', onCompositionStart, false)
editor.addEventListener('compositionend', onCompositionEnd, false)
function onBeforeInput(event) {
console.log(event)
}
function onInput(event) {
console.log(event)
}
function onKeydown(event) {
console.log(isComposition);
if (isComposition) {
event.preventDefault();
}
console.log(event);
}
function onCompositionStart(event) {
isComposition = true;
console.log(event);
}
function onCompositionEnd(event) {
isComposition = false;
console.log(event);
}
}());