-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend-menu-select.html
127 lines (109 loc) · 3.67 KB
/
extend-menu-select.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wangEditor extend select menu</title>
<link href="https://cdn.bootcdn.net/ajax/libs/normalize/8.0.1/normalize.min.css" rel="stylesheet">
<!-- <link href="https://cdn.jsdelivr.net/npm/@wangeditor-next/editor@latest/dist/css/style.css" rel="stylesheet"> -->
<link href="https://unpkg.com/@wangeditor-next/editor@latest/dist/css/style.css" rel="stylesheet">
<link href="./css/layout.css" rel="stylesheet">
<script src="./js/custom-elem.js"></script>
</head>
<body>
<demo-nav title="wangEditor extend select menu"></demo-nav>
<div class="page-container">
<div class="page-left">
<demo-menu></demo-menu>
</div>
<div class="page-right">
<!-- 编辑器 DOM -->
<div style="border: 1px solid #ccc;">
<div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
<div id="editor-text-area" style="height: 500px"></div>
</div>
<!-- 内容状态 -->
<p style="background-color: #f1f1f1;">
Text length: <span id="total-length"></span>;
Selected text length: <span id="selected-length"></span>;
</p>
</div>
</div>
<!-- <script src="https://cdn.jsdelivr.net/npm/@wangeditor-next/editor@latest/dist/index.min.js"></script> -->
<script src="https://unpkg.com/@wangeditor-next/editor@latest/dist/index.js"></script>
<script>
const E = window.wangEditor
const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
E.i18nChangeLanguage(LANG) // 切换语言
class MyMenuClass {
constructor() {
this.title = 'My Select Menu',
// this.iconSvg = '<svg>...</svg>'
this.tag = 'select'
this.width = 60
}
getOptions(editor) {
const options = [
{ value: 'beijing', text: '北京', styleForRenderMenuList: { 'font-size': '32px', 'font-weight': 'bold' } },
{ value: 'shanghai', text: '上海', selected: true },
{ value: 'shenzhen', text: '深圳' }
]
return options
}
getValue(editor) {
return 'shanghai' // 匹配 options 其中一个 value
}
isActive(editor) {
return false // or true
}
isDisabled(editor) {
return false // or true
}
exec(editor, value) {
editor.insertText(value) // value 即 this.getValue(editor) 的返回值
editor.insertText(' ')
}
}
const myMenuConf = {
key: 'myMenu',
factory() {
return new MyMenuClass()
}
}
E.Boot.registerMenu(myMenuConf)
window.editor = E.createEditor({
selector: '#editor-text-area',
html: '<p><br></p>',
config: {
placeholder: 'Type here...',
MENU_CONF: {
uploadImage: {
fieldName: 'your-fileName',
base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
}
},
onChange(editor) {
console.log(editor.getHtml())
// 选中文字
const selectionText = editor.getSelectionText()
document.getElementById('selected-length').innerHTML = selectionText.length
// 全部文字
const text = editor.getText().replace(/\n|\r/mg, '')
document.getElementById('total-length').innerHTML = text.length
}
}
})
window.toolbar = E.createToolbar({
editor,
selector: '#editor-toolbar',
config: {
insertKeys: {
index: 0,
keys: ['myMenu'], // show menu in toolbar
}
}
})
</script>
</body>
</html>