TinyMCE How to access right-click target from context menu?

时间:2019-03-06 11:41:49

标签: javascript tinymce target tinymce-4

I am trying to create my own image manipulation plugin for TinyMCE (4.7.0). I want to set the current image properties in the form when you right-click > context menu > imageplugin.

To copy over the properties I need access to to the element I right clicked. I can't find the target however.

I console.log() the event but it's target is the context menu item not the right-click target...

editor.addMenuItem('imageplugin', {
        text: 'imageplugin',
        context: 'tools',
        onclick: function(e) {
            console.log(e); //target is incorrect...
            editor.windowManager.open({
                title: 'Afbeelding instellingen',
                body: [
                    {
                        type: 'textbox',
                        name: 'title',
                        label: 'Title',
                        value: e.src
                    },
                    {
                        type   : 'listbox',
                        name   : 'width',
                        label  : 'Breedte',
                        values : [
                            { text: '100%', value: '100' },
                            { text: '50%', value: '50' },
                            { text: '33%', value: '33' },
                            { text: '25%', value: '25' },
                        ],
                        value : 'test2'
                    },
                    {
                        type   : 'listbox',
                        name   : 'float',
                        label  : 'Uitlijnen',
                        values : [
                            { text: 'Geen', value: 'none' },
                            { text: 'Links', value: 'left' },
                            { text: 'Rechts', value: 'right' },
                        ],
                        value : 'test2',
                    },
                ],
                onsubmit: function(e) {
                    editor.insertContent('Title: ' + e.data.title);
                }
            });
        }
    });

1 个答案:

答案 0 :(得分:0)

使用editor.selection.getNode()访问当前选定的项目。

相关问题