CKEditor - 将上下文菜单项添加到图像

Mik*_*ees 3 javascript contextmenu ckeditor

我想仅为选定的图像元素添加上下文菜单项.上下文菜单项当前正在工作,但它显示在每个元素上而不是仅显示在图像元素上.到目前为止,这是我的代码:

CKEDITOR.on('instanceReady', function(ev) {
    editor.addCommand('editImgCmd', {
        exec : function( editor ) {
            alert('editImgCmd');
        }
    });
    var editImgCmd = {
        label : editor.lang.image.menu,
        command : 'editImgCmd',
        group : 'image'
    };
    editor.contextMenu.addListener(function(element, selection ) {
        return {
            editImgCmd : CKEDITOR.TRISTATE_ON
        };
    });
    editor.addMenuItems({
        editImgCmd : {
            label : 'Edit Image',
            command : 'editImgCmd',
            group : 'image',
            order : 2
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

Atz*_*mon 6

使用getAscendant()来chcek元素是img:

editor.contextMenu.addListener( function( element, selection ) {
    if ( element.getAscendant( 'img', true ) ) {
        return {
Run Code Online (Sandbox Code Playgroud)