Merge branch 'dev' of https://github.com/wangeditor-team/wangEditor into dev
This commit is contained in:
commit
1954d27eff
|
@ -16,7 +16,7 @@
|
|||
<div id="div1">
|
||||
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
|
||||
<p>
|
||||
<img src="http://www.wangeditor.com/imgs/logo.jpeg"/>
|
||||
<img src="http://www.wangeditor.com/imgs/logo.jpeg" />
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>wangEditor example</title>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>
|
||||
wangEditor 自定义菜单
|
||||
</p>
|
||||
<div id="div1"></div>
|
||||
|
||||
<script src="../dist/wangEditor.js"></script>
|
||||
<script>
|
||||
const E = window.wangEditor
|
||||
const editor = new E('#div1')
|
||||
|
||||
// editor.config.menus = ['fontSize', 'bold']
|
||||
|
||||
// 需要排除的菜单
|
||||
editor.config.excludeMenus = ['bold']
|
||||
|
||||
editor.create()
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -25,6 +25,7 @@ export type ConfigType = {
|
|||
languageType: string[]
|
||||
languageTab: string
|
||||
menus: string[]
|
||||
excludeMenus: string[]
|
||||
fontNames: string[]
|
||||
lineHeights: string[]
|
||||
indentation: IndentationType
|
||||
|
|
|
@ -34,6 +34,12 @@ class Menus {
|
|||
public init(): void {
|
||||
// 从用户配置的 menus 入手,看需要初始化哪些菜单
|
||||
const config = this.editor.config
|
||||
|
||||
// 排除exclude包含的菜单
|
||||
let excludeMenus: string[] | any = config.excludeMenus
|
||||
if (Array.isArray(excludeMenus) === false) excludeMenus = []
|
||||
config.menus = config.menus.filter(key => excludeMenus.includes(key) === false)
|
||||
|
||||
config.menus.forEach(menuKey => {
|
||||
const MenuConstructor = this.constructorList[menuKey] // 暂用 any ,后面再替换
|
||||
if (MenuConstructor == null || typeof MenuConstructor !== 'function') {
|
||||
|
|
|
@ -16,3 +16,11 @@ test('菜单数量', () => {
|
|||
})
|
||||
|
||||
// 各个菜单的配置,随后开发的时候再加
|
||||
test('菜单 exclude', () => {
|
||||
const editor = createEditor(document, 'div1', '', {
|
||||
excludeMenus: ['bold'],
|
||||
})
|
||||
const menus = editor.config.menus
|
||||
// 不包含bold
|
||||
expect(menus).not.toContain('bold')
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue