-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (49 loc) · 1.55 KB
/
index.js
File metadata and controls
56 lines (49 loc) · 1.55 KB
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
let Squire = require("squire-rte");
const appDiv = document.getElementById('app');
let squire = new Squire(appDiv, {
blockTag: 'p',
blockAttributes: {'class': 'paragraph'},
tagAttributes: {
ul: {'class': 'UL'},
ol: {'class': 'OL'},
li: {'class': 'listItem'},
pre: {
style: 'border-radius:3px;border:1px solid #ccc;padding:7px 10px;background:#f6f6f6;font-family:menlo,consolas,monospace;font-size:90%;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word;'
}
}
});
let state = {
bold: false,
italic: false,
underline: false
};
const removeActions = {
bold: 'removeBold',
italic: 'removeItalic',
underline: 'removeUnderline'
}
const activate = (e, action) => {
e.currentTarget.classList.add("active");
squire[action]();
};
const disable = (e, action) => {
e.currentTarget.classList.remove("active");
squire[removeActions[action]]();
}
const changeActive = (e) => {
const action = e.currentTarget.id;
if(action in removeActions) {
state[action] = !state[action];
if(state[action]) {
activate(e, action);
} else {
disable(e, action);
}
} else {
squire[action]();
}
};
document.getElementById('bold').addEventListener('click', changeActive);
document.getElementById('italic').addEventListener('click', changeActive);
document.getElementById('underline').addEventListener('click', changeActive);
document.getElementById('makeOrderedList').addEventListener('click', changeActive);