Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

扩展菜单注册太过繁琐 #2493

Closed
clinfc opened this issue Nov 21, 2020 · 0 comments · Fixed by #2811
Closed

扩展菜单注册太过繁琐 #2493

clinfc opened this issue Nov 21, 2020 · 0 comments · Fixed by #2811

Comments

@clinfc
Copy link
Contributor

clinfc commented Nov 21, 2020

问题描述

当前扩展菜单是在每个实例中都去注册,但是其实这并没有必要,其实第一个实例注册后,后续的实例只需要设置 editor.config.menus 即可。

既然如此,何不直接在 wangEditor 上提供一个静态接口呢,实例化之前全局注册,后续就没必要这么麻烦了

wangEditor 版本

v4

是否查阅了文档 ?

最小成本的复现步骤

当前实现

<div id="div1"></div>
<div id="div2"></div>

<script src="../dist/wangEditor.js"></script>
<script>
    const E = window.wangEditor

    const { BtnMenu, DropListMenu, PanelMenu, DropList, Panel, Tooltip } = E

    class InsertABCMenu extends BtnMenu {
        constructor(editor) {
            const $elem = E.$(
                `<div class="w-e-menu">
                    <button>ABC</button>
                </div>`
            )
            super($elem, editor)
        }
        clickHandler() {
            this.editor.cmd.do('insertHTML', 'ABC')
        }
        tryChangeActive() {
            this.active() 
        }
    }
    
    const editor = new E('#div1')
    // 注册菜单
    editor.menus.extend('insertABC', InsertABCMenu)
    // 重新配置 editor.config.menus
    editor.config.menus.push('insertABC')

    editor.create()
    
    const editor2 = new E('#div2')
    // 实例2并未注册菜单一样可以拥有实例1注册的菜单功能
    editor2.config.menus.push('insertABC')
    editor2.create()
</script>

期望实现

<div id="div1"></div>
<div id="div2"></div>

<script src="../dist/wangEditor.js"></script>
<script>
    const E = window.wangEditor

    const { BtnMenu, DropListMenu, PanelMenu, DropList, Panel, Tooltip } = E

    class InsertABCMenu extends BtnMenu {
        constructor(editor) {
            const $elem = E.$(
                `<div class="w-e-menu">
                    <button>ABC</button>
                </div>`
            )
            super($elem, editor)
        }
        clickHandler() {
            this.editor.cmd.do('insertHTML', 'ABC')
        }
        tryChangeActive() {
            this.active() 
        }
    }
    
    // 注册菜单
    E.registerMenu('insertABC', InsertABCMenu)
    
    const editor = new E('#div1')
    editor.create()
    
    const editor2 = new E('#div2')
    editor2.create()
</script>
@UltramanWeiLai UltramanWeiLai linked a pull request Jan 15, 2021 that will close this issue
wangfupeng1988 added a commit that referenced this issue Jan 19, 2021
@ilifewebdev ilifewebdev linked a pull request Jan 20, 2021 that will close this issue
@ilifewebdev ilifewebdev removed a link to a pull request Jan 20, 2021
@echoLC echoLC closed this as completed Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants