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

CKEditor - Add Context Menu Item to Images

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

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
        }
    });
});

usd getAscendant() 检查元素是 img:

editor.contextMenu.addListener( function( element, selection ) {
    if ( element.getAscendant( 'img', true ) ) {
        return {