-
Notifications
You must be signed in to change notification settings - Fork 10
/
rich-text-editor.test.view-key.html
38 lines (36 loc) · 1.23 KB
/
rich-text-editor.test.view-key.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
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Demo</title>
<link href="rich-text-editor.css" rel="stylesheet">
</head>
<body>
<p>Press <kbd>⌘+⇧+O</kbd> to show an alert message.</p>
<p><textarea>Lorem ipsum dolor sit amet.</textarea></p>
<script src="rich-text-editor.js"></script>
<script>
var editor = new RTE(document.querySelector('textarea'), {
update: function(e, node) {
if (node !== this.view) return; // exit if we are not typing in the editor view
var ctrl = e.ctrlKey,
shift = e.shiftKey,
code = e.keyCode,
key = (e.key || String.fromCharCode(code)).toLowerCase();
if (
ctrl &&
shift &&
(
key === 'o' || // native `KeyboardEvent.key`
code === 79 // deprecated `KeyboardEvent.keyCode`
)
) {
e.preventDefault(); // cancel the default behaviour
alert('Hi!'); // test message!
}
}
});
</script>
</body>
</html>