CKEditor - Add Context Menu Item to Images

坚强是说给别人听的谎言 提交于 2020-01-14 13:39:12

问题


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

回答1:


Use getAscendant() to chcek the element is an img:

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


来源:https://stackoverflow.com/questions/37553405/ckeditor-add-context-menu-item-to-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!