# MediumEditor Custom Events (v5.0.0) 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. **NOTE:** 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. 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). - [API Methods](#api-methods) - [`MediumEditor.subscribe(name, listener)`](#mediumeditorsubscribename-listener) - [`MediumEditor.unsubscribe(name, listener)`](#mediumeditorunsubscribename-listener) - [`MediumEditor.trigger(name, data, editable)`](#mediumeditortriggername-data-editable) - [Custom Events](#custom-events) - [`addElement`](#addelement) - [`blur`](#blur) - [`editableInput`](#editableinput) - [`externalInteraction`](#externalinteraction) - [`focus`](#focus) - [`removeElement`](#removeelement) - [Toolbar Custom Events](#toolbar-custom-events) - [`hideToolbar`](#hidetoolbar) - [`positionToolbar`](#positiontoolbar) - [`positionedToolbar`](#positionedtoolbar) - [`showToolbar`](#showtoolbar) - [Proxied Custom Events](#proxied-custom-events) - [`editableClick`](#editableclick) - [`editableBlur`](#editableblur) - [`editableKeypress`](#editablekeypress) - [`editableKeyup`](#editablekeyup) - [`editableKeydown`](#editablekeydown) - [`editableKeydownEnter`](#editablekeydownenter) - [`editableKeydownTab`](#editablekeydowntab) - [`editableKeydownDelete`](#editablekeydowndelete) - [`editableKeydownSpace`](#editablekeydownspace) - [`editableMouseover`](#editablemouseover) - [`editableDrag`](#editabledrag) - [`editableDrop`](#editabledrop) - [`editablePaste`](#editablepaste) ## API Methods Use the following methods of [MediumEditor](API.md) for custom event interaction: ### `MediumEditor.subscribe(name, listener)` Attaches a listener for the specified custom event name. **Arguments** 1. _**name** (`String`)_: * Name of the event to listen to. See the list of built-in [Custom Events](#custom-events) below. 2. _**listener(data, editable)** (`function`)_: * Listener method that will be called whenever the custom event is triggered. **Arguments to listener** 1. _**data** (`Event` | `object`)_ * For most custom events, this will be the browser's native `Event` object for the event that triggered the custom event to fire. * For some custom events, this will be an object containing information describing the event (depending on which custom event it is) 2. _**editable** (`HTMLElement`)_ * A reference to the contenteditable container element that this custom event corresponds to. This is especially useful for instances where one instance of MediumEditor contains multiple elements, or there are multiple instances of MediumEditor on the page. * For example, when `blur` fires, this argument will be the `
` element that is about to receive focus. *** ### `MediumEditor.unsubscribe(name, listener)` Detaches a custom event listener for the specified custom event name. **Arguments** 1. _**name** (`String`)_: * Name of the event to detach the listener for. 2. _**listener** (`function`)_: * A reference to the listener to detach. This must be a match by-reference and not a copy. **NOTE** * Calling [destroy()](API.md#destroy) on the MediumEditor object will automatically remove all custom event listeners. *** ### `MediumEditor.trigger(name, data, editable)` Manually triggers a custom event. 1. _**name** (`String`)_: * Name of the custom event to trigger. 2. _**data** (`Event` | `object`)_: * Native `Event` object or custom data object to pass to all the listeners to this custom event. 3. _**editable** (`HTMLElement`)_: * The `` element to pass to all of the listeners to this custom event. ## Custom Events These events are custom to MediumEditor so there may be one or more native events that can trigger them. ### `addElement` `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 `