|
| 1 | +package io.scalajs.dom |
| 2 | + |
| 3 | +import io.scalajs.RawOptions |
| 4 | + |
| 5 | +import scala.scalajs.js |
| 6 | +import scala.scalajs.js.| |
| 7 | + |
| 8 | +/** |
| 9 | + * EventTarget is an interface implemented by objects that can receive events and may have listeners for them. |
| 10 | + * |
| 11 | + * Element, document, and window are the most common event targets, but other objects can be event targets too, |
| 12 | + * for example XMLHttpRequest, AudioNode, AudioContext, and others. |
| 13 | + * |
| 14 | + * Many event targets (including elements, documents, and windows) also support setting event handlers via on... |
| 15 | + * properties and attributes. |
| 16 | + * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget |
| 17 | + */ |
| 18 | +@js.native |
| 19 | +trait EventTarget extends js.Object { |
| 20 | + |
| 21 | + /** |
| 22 | + * Register an event handler of a specific event type on the EventTarget. |
| 23 | + * @param `type` A string representing the event type to listen for. |
| 24 | + * @param listener The object that receives a notification (an object that implements the Event interface) when |
| 25 | + * an event of the specified type occurs. This must be an object implementing the EventListener |
| 26 | + * interface, or simply a JavaScript function. |
| 27 | + */ |
| 28 | + def addEventListener(`type`: String, listener: js.Function): Unit = js.native |
| 29 | + |
| 30 | + /** |
| 31 | + * Register an event handler of a specific event type on the EventTarget. |
| 32 | + * @param `type` A string representing the event type to listen for. |
| 33 | + * @param listener The object that receives a notification (an object that implements the Event interface) when |
| 34 | + * an event of the specified type occurs. This must be an object implementing the EventListener |
| 35 | + * interface, or simply a JavaScript function. |
| 36 | + * @param options An options object that specifies characteristics about the event listener. |
| 37 | + */ |
| 38 | + def addEventListener(`type`: String, listener: js.Function, options: EventTargetOptions | RawOptions): Unit = js.native |
| 39 | + |
| 40 | + /** |
| 41 | + * Register an event handler of a specific event type on the EventTarget. |
| 42 | + * @param `type` A string representing the event type to listen for. |
| 43 | + * @param listener The object that receives a notification (an object that implements the Event interface) when |
| 44 | + * an event of the specified type occurs. This must be an object implementing the EventListener |
| 45 | + * interface, or simply a JavaScript function. |
| 46 | + * @param useCapture A Boolean that indicates that events of this type will be dispatched to the registered listener |
| 47 | + * before being dispatched to any EventTarget beneath it in the DOM tree. Events that are bubbling |
| 48 | + * upward through the tree will not trigger a listener designated to use capture. Event bubbling |
| 49 | + * and capturing are two ways of propagating events that occur in an element that is nested within |
| 50 | + * another element, when both elements have registered a handle for that event. The event |
| 51 | + * propagation mode determines the order in which elements receive the event. |
| 52 | + * See DOM Level 3 Events and JavaScript Event order for a detailed explanation. |
| 53 | + * If not specified, useCapture defaults to false. |
| 54 | + */ |
| 55 | + def addEventListener(`type`: String, listener: js.Function, useCapture: Boolean): Unit = js.native |
| 56 | + |
| 57 | + /** |
| 58 | + * Removes an event listener from the EventTarget. |
| 59 | + * @param `type` A string representing the event type to remove. |
| 60 | + * @param listener The EventListener function to remove from the event target. |
| 61 | + * @param options An options object that specifies characteristics about the event listener. |
| 62 | + */ |
| 63 | + def removeEventListener(`type`: String, listener: js.Function, options: EventTargetOptions | RawOptions): Unit = js.native |
| 64 | + |
| 65 | + /** |
| 66 | + * Removes an event listener from the EventTarget. |
| 67 | + * @param `type` A string representing the event type to remove. |
| 68 | + * @param listener The EventListener function to remove from the event target. |
| 69 | + * @param useCapture Specifies whether the EventListener to be removed is registered as a capturing listener or not. |
| 70 | + * If this parameter is absent, a default value of false is assumed. |
| 71 | + * If a listener is registered twice, one with capture and one without, remove each one separately. |
| 72 | + * Removal of a capturing listener does not affect a non-capturing version of the same listener, |
| 73 | + * and vice versa. |
| 74 | + */ |
| 75 | + def removeEventListener(`type`: String, listener: js.Function, useCapture: Boolean): Unit = js.native |
| 76 | + |
| 77 | + /** |
| 78 | + * Dispatch an event to this EventTarget. |
| 79 | + * @param event event is the Event object to be dispatched. |
| 80 | + * @return false if event is cancelable and at least one of the event handlers which handled this event |
| 81 | + * called Event.preventDefault(). Otherwise it returns true. |
| 82 | + */ |
| 83 | + def dispatchEvent(event: Event): Boolean = js.native |
| 84 | + |
| 85 | +} |
0 commit comments