CKEditor - 为图片添加上下文菜单项

3

我想为选定的图像元素添加上下文菜单项。目前,上下文菜单项可以正常工作,但它会出现在每个元素上,而不仅仅是图像元素上。以下是我的代码:

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

嗨,Mike。也许你可以帮我解答一个问题吗?谢谢!https://dev59.com/QZ7ha4cB1Zd3GeqPosyN - VGranin
1个回答

6
使用getAscendant()方法来检查元素是否为img
editor.contextMenu.addListener( function( element, selection ) {
    if ( element.getAscendant( 'img', true ) ) {
        return {

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接