You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following examples illustrate how to use supported native events, editor core events, and plugin events with {productname}. Editor Manager events are handled separately using `+tinymce.on+`, rather than `+editor.on+`.
18
+
19
+
=== Defining an event handler
20
+
21
+
Event handlers can be initialized anywhere using the `+editor.on+` method, as shown in the following example:
=== `+setup+` and `+init_instance_callback+` options
31
+
32
+
A common use case for setting up events is to use the `+setup+` and `+init_instance_callback+` options. These options allow you to bind events before and after the editor instance is initialized.
33
+
34
+
The `+setup+` option can be used to bind an event **before** the editor instance is initialized.
35
+
36
+
The `+init_instance_callback+` option can be used to bind an event **after** the editor instance is initialized.
37
+
38
+
TIP: The `+init_instance_callback+` is functionally equivalent to binding an event listener to the `init` event on the `+setup+` option.
12
39
13
-
The following example uses a function to create a console log entry when the editor has initialized. This is also an example of handling an event which does not return any data.
40
+
For example, the following code:
14
41
15
42
[source,js]
16
43
----
17
44
tinymce.init({
18
45
selector: 'textarea',
19
46
setup: (editor) => {
20
47
editor.on('init', (e) => {
21
-
console.log('The Editor has initialized.');
48
+
console.log('Editor is initialized.');
22
49
});
23
50
}
24
51
});
25
52
----
26
53
27
-
The following example uses a function to create a console log entry when a command is executed in the editor. This is also an example of handling an event that returns data.
54
+
Is equivalent to:
55
+
56
+
[source,js]
57
+
----
58
+
tinymce.init({
59
+
selector: 'textarea',
60
+
init_instance_callback: (editor) => {
61
+
console.log('Editor is initialized.');
62
+
}
63
+
});
64
+
----
65
+
66
+
For more information on these options, see xref:editor-important-options.adoc#setup[setup] and xref:editor-important-options.adoc#init_instance_callback[init_instance_callback].
67
+
68
+
=== Binding an event before editor initialization
69
+
70
+
The following example uses the `+setup+` option to bind an event before the editor instance is initialized. This is an example of handling an event that does not return data, such as the `+ResizeEditor+` editor event. Therefore, the `+e+` parameter is not used.
71
+
72
+
[source,js]
73
+
----
74
+
tinymce.init({
75
+
selector: 'textarea',
76
+
setup: (editor) => {
77
+
editor.on('ResizeEditor', (e) => {
78
+
console.log('Editor was resized.');
79
+
});
80
+
}
81
+
});
82
+
----
83
+
84
+
=== Binding an event after editor initialization
85
+
86
+
The following example uses the `+init_instance_callback+` option to bind an event after the editor instance is initialized. This is an example of handling an event that returns data, such as the `+ExecCommand+` event. Therefore, we can use the `+e+` parameter to access the data returned by the event.
28
87
29
88
[source,js]
30
89
----
@@ -38,6 +97,7 @@ tinymce.init({
38
97
});
39
98
----
40
99
100
+
[[browser-native-events]]
41
101
== Supported browser-native events
42
102
43
103
{productname} supports the following browser-native events. Click the event name for details (links open https://developer.mozilla.org/[MDN Web Docs]).
@@ -176,6 +236,7 @@ The following events are provided by the {productname} editor.
176
236
|FontFamilyTextUpdate |`+{ value: string }+` |Fired after the visible text label of the `fontfamily` bespoke toolbar button is updated. `value` refers to the updated visible text label.
0 commit comments