-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 950 Bytes
/
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
var $ = require('elem'),
commander = require('./commander');
module.exports = function Ced(container) {
if(!(this instanceof Ced))
return new Ced(container);
container = $(container);
container.append(commander);
container.on('click',oneditor);
this.container = container;
}
function oneditor(e){
var cmd = e.target.getAttribute('data-ced'),
state = document.queryCommandState(cmd);
console.log("command(%s) state:", cmd, state);
switch(cmd) {
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'p':
document.execCommand('formatblock', false, '<'+cmd+'>');
break;
case 'insertUnorderedList':
case 'insertOrderedList':
if(document.queryCommandState(cmd)) { cmd = 'outdent'; }
default:
document.execCommand(cmd, false, null);
break;
}
}