-
Notifications
You must be signed in to change notification settings - Fork 164
PluginDomEvent
Jiuqing Song edited this page Mar 7, 2018
·
2 revisions
Go back to Plugin events
interface PluginDomEvent extends PluginEvent {
rawEvent: Event;
}
PluginDomEvent
has one additional property -- rawEvent, which is the DOM event object generated by browser. Programmer can use this object to get all kinds of information of this event, such as key code, mouse position, mouse button, target DOM element, ... In the first plugin sample code it uses this object to check which key user has pressed, and call preventDefault() to prevent the default event behavior as well:
onPluginEvent(event: PluginEvent) {
if (event.eventType == PluginEventType.KeyPress) {
let domEvent = <PluginDomEvent>event;
let keyboardEvent = <KeyboardEvent>domEvent.rawEvent;
if (keyboardEvent.which >= KEY_0 && keyboardEvent.which <= KEY_9) {
let text = NUMBERS[keyboardEvent.which - KEY_0] + ' ';
this.editor.insertContent(text);
keyboardEvent.preventDefault();
}
}
}
Package: roosterjs-editor-types
Support from: 6.0.0
Source code: PluginDomEvent.ts