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
Copy file name to clipboardExpand all lines: CUSTOM-EVENTS.md
+36-6
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
# MediumEditor Custom Events (v5.0.0)
2
2
3
-
MediumEditor exposes a variety of custom events for convienience when using the editor with your web application. You can attach and detach listeners to these custom events, as well as manually trigger any custom events including your own custom events.
3
+
MediumEditor exposes a variety of custom events for convenience when using the editor with your web application. You can attach and detach listeners to these custom events, as well as manually trigger any custom events including your own custom events.
4
4
5
5
**NOTE:**
6
6
7
7
Custom event listeners are triggered in the order that they were 'subscribed' to. Most functionality within medium-editor uses these custom events to trigger updates, so in general, it can be assumed that most of the built-in functionality has already been completed before any of your custom event listeners will be called.
8
8
9
-
If you need to override the editor's bult-in behavior, try overriding the built-in extensions with your own [custom extension](src/js/extensions).
9
+
If you need to override the editor's built-in behavior, try overriding the built-in extensions with your own [custom extension](src/js/extensions).
10
10
11
11
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
12
12
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -16,10 +16,12 @@ If you need to override the editor's bult-in behavior, try overriding the built-
@@ -56,7 +58,7 @@ Attaches a listener for the specified custom event name.
56
58
57
59
* Name of the event to listen to. See the list of built-in [Custom Events](#custom-events) below.
58
60
59
-
2._**listener(data, editable)** (`function`)_:
61
+
2._**listener(data, editable)** (`function`)_:
60
62
61
63
* Listener method that will be called whenever the custom event is triggered.
62
64
@@ -80,7 +82,7 @@ Detaches a custom event listener for the specified custom event name.
80
82
81
83
* Name of the event to detach the listener for.
82
84
83
-
2._**listener** (`function`)_:
85
+
2._**listener** (`function`)_:
84
86
85
87
* A reference to the listener to detach. This must be a match by-reference and not a copy.
86
88
@@ -109,6 +111,20 @@ Manually triggers a custom event.
109
111
110
112
These events are custom to MediumEditor so there may be one or more native events that can trigger them.
111
113
114
+
### `addElement`
115
+
116
+
`addElement` is triggered whenever an element is added to the editor after the editor has been instantiated. This custom event will be triggered **after** the element has already been initialized by the editor and added to the internal array of **elements**. If the element being added was a `<textarea>`, the element passed to the listener will be the created `<div contenteditable=true>` element and not the root `<textarea>`.
117
+
118
+
**Arguments to listener**
119
+
120
+
1._**data** (`object`)_
121
+
* Properties of data object
122
+
*`target`: element which was added to the editor
123
+
*`currentTarget`: element which was added to the editor
124
+
2._**editable** (`HTMLElement`)_
125
+
* element which was added to the editor
126
+
127
+
***
112
128
### `blur`
113
129
114
130
`blur` is triggered whenever a `contenteditable` element within an editor has lost focus to an element other than an editor maintained element (ie Toolbar, Anchor Preview, etc).
@@ -140,7 +156,21 @@ Example:
140
156
***
141
157
### `focus`
142
158
143
-
`focus` is triggered whenver a `contenteditable` element within an editor receives focus. If the user interacts with any editor maintained elements (ie toolbar), `blur` is NOT triggered because focus has not been lost. Thus, `focus` will only be triggered when an `contenteditable` element (or the editor that contains it) is first interacted with.
159
+
`focus` is triggered whenever a `contenteditable` element within an editor receives focus. If the user interacts with any editor maintained elements (ie toolbar), `blur` is NOT triggered because focus has not been lost. Thus, `focus` will only be triggered when an `contenteditable` element (or the editor that contains it) is first interacted with.
160
+
161
+
***
162
+
### `removeElement`
163
+
164
+
`removeElement` is triggered whenever an element is removed from the editor after the editor has been instantiated. This custom event will be triggered **after** the element has already been removed from the editor and any events attached to it have already been removed. If the element being removed was a `<div>` created to correspond to a `<textarea>`, the element will already have been removed from the DOM.
165
+
166
+
**Arguments to listener**
167
+
168
+
1._**data** (`object`)_
169
+
* Properties of data object
170
+
*`target`: element which was removed from the editor
171
+
*`currentTarget`: element which was removed from the editor
172
+
2._**editable** (`HTMLElement`)_
173
+
* element which was removed from the editor
144
174
145
175
## Toolbar Custom Events
146
176
@@ -161,7 +191,7 @@ These events are triggered by the toolbar when the toolbar extension has not bee
161
191
162
192
## Proxied Custom Events
163
193
164
-
These events are triggered whenever a native browser event is triggered for any of the `contenteditable` elements monitored by this instnace of MediumEditor.
194
+
These events are triggered whenever a native browser event is triggered for any of the `contenteditable` elements monitored by this instance of MediumEditor.
165
195
166
196
For example, the `editableClick` custom event will be triggered when a native `click` event is fired on any of the `contenteditable` elements. This provides a single event listener that can get fired for all elements, and also allows for the `contenteditable` element that triggered the event to be passed to the listener.
Copy file name to clipboardExpand all lines: spec/dyn-elements.spec.js
+24
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,18 @@ describe('MediumEditor.DynamicElements TestCase', function () {
115
115
expect(editor.events.customEvents['editableKeydownEnter'].length).toBe(2,'editableKeydownEnter should be subscribed to when adding a data-disbale-return element');
116
116
});
117
117
118
+
it('should trigger addElement custom event for each element',function(){
0 commit comments