【问题标题】:CKEditor - Add Context Menu Item to ImagesCKEditor - 将上下文菜单项添加到图像
【发布时间】:2016-05-31 18:47:27
【问题描述】:

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

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

【问题讨论】:

标签: javascript ckeditor contextmenu


【解决方案1】:

使用getAscendant() 来检查元素是否为img:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多