CKEditor-向图像添加上下文菜单项 [英] CKEditor - Add Context Menu Item to Images

查看:77
本文介绍了CKEditor-向图像添加上下文菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add a context menu item for selected image elements only. The context menu item is currently working but it shows up on every element instead of only image elements. Here is my code so far:

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


推荐答案

使用 getAscendant()来选择元素是 img

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

这篇关于CKEditor-向图像添加上下文菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆