EventEmitter

event-emitter.EventEmitter

The module editor's event manager

Implements

constructor

new EventEmitter(doc?): EventEmitter

Parameters

Name Type
doc? Document

Returns

EventEmitter

Defined in

src/core/event-emitter/event-emitter.ts#766

__key

Readonly __key: string = '__JoditEventEmitterNamespaces'

Defined in

src/core/event-emitter/event-emitter.ts#56


currents

currents: string[] = []

Implementation of

IEventEmitter.currents

Defined in

src/core/event-emitter/event-emitter.ts#208

current

get current(): string

Get current event name

Returns

string

Example

parent.e.on('openDialog closeDialog', function () {
    if (parent.e.current === 'closeDialog') {
        alert('Dialog was closed');
    } else {
        alert('Dialog was opened');
    }
});

Implementation of

IEventEmitter.current

Defined in

src/core/event-emitter/event-emitter.ts#204

mute

mute(event?): this

Doesn't start any handler

Parameters

Name Type
event? string

Returns

this

Implementation of

IEventEmitter.mute

Defined in

src/core/event-emitter/event-emitter.ts#38


isMuted

isMuted(event?): boolean

No handlers are triggered for the event

Parameters

Name Type
event? string

Returns

boolean

Implementation of

IEventEmitter.isMuted

Defined in

src/core/event-emitter/event-emitter.ts#43


unmute

unmute(event?): this

Returns event handling

Parameters

Name Type
event? string

Returns

this

Implementation of

IEventEmitter.unmute

Defined in

src/core/event-emitter/event-emitter.ts#51


on

on(events, callback, options?): this

Sets the handler for the specified event ( Event List ) for a given element

Parameters

Name Type
events CanArray<string>
callback CallbackFunction<any>
options? IEventEmitterOnOptions

Returns

this

Example

// set global handler
editor.events.on('beforeCommand', function (command) {
    alert('command');
});

Example

// set global handler
editor.events.on(document.body, 'click', function (e) {
    alert(this.href);
});

Implementation of

IEventEmitter.on

Defined in

src/core/event-emitter/event-emitter.ts#228

on(subjects, events, callback, options?): this

Parameters

Name Type
subjects CanArray<object | Window | HTMLElement>
events CanArray<string>
callback CallbackFunction<any>
options? IEventEmitterOnOptions

Returns

this

Implementation of

IEventEmitter.on

Defined in

src/core/event-emitter/event-emitter.ts#234


one

one(eventsOrSubjects, callbackOrEvents, optionsOrCallback, opts?): this

Parameters

Name Type
eventsOrSubjects CanArray<string> | CanArray<object | Window | HTMLElement>
callbackOrEvents CallbackFunction<any> | CanArray<string>
optionsOrCallback void | CallbackFunction<any> | IEventEmitterOnOptions
opts? IEventEmitterOnOptions

Returns

this

Implementation of

IEventEmitter.one

Defined in

src/core/event-emitter/event-emitter.ts#389


off

off(events, callback?): this

Disable all handlers specified event ( Event List ) for a given element. Either a specific event handler.

Parameters

Name Type
events CanArray<string>
callback? CallbackFunction<any>

Returns

this

Example

var a = {name: "Anton"};
parent.e.on(a, 'open', function () {
    alert(this.name);
});

parent.e.fire(a, 'open');
parent.e.off(a, 'open');
var b = {name: "Ivan"}, hndlr = function () {
 alert(this.name);
};
parent.e.on(b, 'open close', hndlr);
parent.e.fire(a, 'open');
parent.e.off(a, 'open', hndlr);
parent.e.fire(a, 'close');
parent.e.on('someGlobalEvents', function () {
  console.log(this); // parent
});
parent.e.fire('someGlobalEvents');
parent.e.off('someGlobalEvents');

Implementation of

IEventEmitter.off

Defined in

src/core/event-emitter/event-emitter.ts#455

off(subjects, events?, callback?): this

Parameters

Name Type
subjects CanArray<object | Window | HTMLElement>
events? CanArray<string>
callback? CallbackFunction<any>

Returns

this

Implementation of

IEventEmitter.off

Defined in

src/core/event-emitter/event-emitter.ts#457


stopPropagation

stopPropagation(events): void

Stop execute all another listeners for this event

Parameters

Name Type
events string

Returns

void

Implementation of

IEventEmitter.stopPropagation

Defined in

src/core/event-emitter/event-emitter.ts#578

stopPropagation(subject, eventsList): void

Parameters

Name Type
subject object
eventsList string

Returns

void

Implementation of

IEventEmitter.stopPropagation

Defined in

src/core/event-emitter/event-emitter.ts#579


fire

fire(subjectOrEvents, ...args): any

Emits an event to all handlers and calls them

Parameters

Name Type Description
subjectOrEvents string The object which is caused by certain events
...args any[] Options for the event handler

Returns

any

false if one of the handlers return false

Example

var dialog = new Jodit.modules.Dialog();
parent.e.on('afterClose', function () {
    dialog.destruct(); // will be removed from DOM
});
dialog.open('Hello world!!!');

or you can trigger native browser listener

 var events = new Jodit.modules.EventEmitter();
 events.on(document.body, 'click',function (event) {
     alert('click on ' + event.target.id );
 });
 events.fire(document.body.querySelector('div'), 'click');

Implementation of

IEventEmitter.fire

Defined in

src/core/event-emitter/event-emitter.ts#659

fire(subjectOrEvents, eventsList, ...args): any

Parameters

Name Type
subjectOrEvents object
eventsList string | Event
...args any[]

Returns

any

Implementation of

IEventEmitter.fire

Defined in

src/core/event-emitter/event-emitter.ts#660


destruct

destruct(): void

Returns

void

Implementation of

IEventEmitter.destruct

Defined in

jodit/src/core/event-emitter/event-emitter.ts:774