Skip to content

ckeditor5-elements / ElementClickable

Class: ElementClickable ​

Calls a function when an element is clicked or double-clicked, with the model element. Elements are matched by name or by a filter function, and the definitions are the elementClickable editor config option (see ElementClickableDefinition):

ts
elementClickable: [
	{ element: 'imageBlock', callback: (element, editor) => console.log(element.getAttribute('src')) },
	{ element: element => element.name.startsWith('heading'), event: 'dblclick', callback: edit }
];

The click is matched against the element that was clicked and its ancestors, the innermost first: the first element that matches a definition for the event calls its callback, and the event goes no further. For two definitions that match the same element, the first one in the config wins.

It works in read-only mode too. The click still does what it does in the editor, e.g. selects an image: the plugin only reports it, before the other plugins handle it (some of them stop the event), and does not stop it.

Extends ​

Constructors ​

Constructor ​

ts
new ElementClickable(editor): ElementClickable;

Parameters ​

ParameterType
editorEditor

Returns ​

ElementClickable

Inherit Doc ​

Inherited from ​

Plugin.constructor

Accessors ​

pluginName ​

Get Signature ​

ts
get static pluginName(): "ElementClickable";
Returns ​

"ElementClickable"

Methods ​

find() ​

ts
find(viewElement, event?): 
  | {
  definition: ElementClickableDefinition;
  element: ModelElement;
}
  | null;

Returns the definition and the element that a click on the view element is for: the innermost element, among the view element and its ancestors, that matches a definition for the event. null when there is none.

Parameters ​

ParameterTypeDefault value
viewElementViewElementundefined
event?ElementClickableEvent'click'

Returns ​

| { definition: ElementClickableDefinition; element: ModelElement; } | null


init() ​

ts
init(): void;

Returns ​

void