CKEditor - get an item after clicking the context menu

I added a link to the img context menu in ckeditor using this code CKEditor - Add context menu item to images

How can I get information about the image that the user clicked on? For example, the identifier of the image. Or the way. For processing with the selected image.

+7
javascript ckeditor contextmenu
source share
3 answers

The solution was quite simple.

$('body').on('contextmenu','img',function(){ var imgid = $(this).attr('id'); alert(imgid); }) 

Using jquery to track clicks on an image, we can store its id in a global variable. Then, inside the plugin command, take the previously saved identifier.

+4
source share

In JavaScript, this keyword refers to the owner of a function or event. Therefore, when you write a click event handler for elements in an HTML document. This will then return the specific html element where the click event is being executed. So inside you click the event handler function, use this.

this keyword has element-specific properties, but id and name are common to most html elements. E.g. here in the img element, the src property can return the value of the image url attribute.

This is a good source to learn more about this keyword http://www.quirksmode.org/js/this.html

0
source share

You can use the editor function getSelection () to find out how the element clicked on the context menu:

 exec: function (editor) { var selection = editor.getSelection(); var selectedElement = selection.getStartElement(); // Use it as jquery object to get id or more ... $(selectedElement.$); } 
0
source share

All Articles