Skip to content

Commit a2bdc55

Browse files
bustisjrd
authored andcommitted
Add overloads of {add,remove}EventListener with options objects (#343)
1 parent 52ebfcc commit a2bdc55

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

src/main/scala/org/scalajs/dom/raw/lib.scala

+68-2
Original file line numberDiff line numberDiff line change
@@ -2702,8 +2702,46 @@ class Window
27022702
}
27032703

27042704
/**
2705-
* EventTarget is a DOM interface implemented by objects that can receive DOM events
2706-
* and have listeners for them.
2705+
* An options object that specifies characteristics about the event listener.
2706+
*
2707+
* MDN
2708+
*/
2709+
trait EventListenerOptions extends js.Object {
2710+
2711+
/**
2712+
* A Boolean indicating that events of this type
2713+
* will be dispatched to the registered listener
2714+
* before being dispatched to any EventTarget
2715+
* beneath it in the DOM tree.
2716+
*
2717+
* MDN
2718+
*/
2719+
var capture: js.UndefOr[Boolean] = js.undefined
2720+
2721+
/**
2722+
* A Boolean indicating that the listener
2723+
* should be invoked at most once after being added.
2724+
* If true, the listener would be automatically removed when invoked.
2725+
*/
2726+
var once: js.UndefOr[Boolean] = js.undefined
2727+
2728+
/**
2729+
* A Boolean which, if true, indicates
2730+
* that the function specified by listener
2731+
* will never call preventDefault().
2732+
* If a passive listener does call preventDefault(),
2733+
* the user agent will do nothing other
2734+
* than generate a console warning.
2735+
* See Improving scrolling performance with passive listeners to learn more.
2736+
*
2737+
* MDN
2738+
*/
2739+
var passive: js.UndefOr[Boolean] = js.undefined
2740+
}
2741+
2742+
/**
2743+
* EventTarget is a DOM interface implemented by objects
2744+
* that can receive DOM events and have listeners for them.
27072745
*
27082746
* Element, document, and window are the most common event targets, but other
27092747
* objects can be event targets too, for example XMLHttpRequest, AudioNode,
@@ -2740,6 +2778,34 @@ class EventTarget extends js.Object {
27402778
listener: js.Function1[T, _],
27412779
useCapture: Boolean = js.native): Unit = js.native
27422780

2781+
/**
2782+
* Removes the event listener previously registered with
2783+
* EventTarget.addEventListener.
2784+
*
2785+
* This implementation accepts a settings object of type EventListenerOptions.
2786+
*
2787+
* MDN
2788+
*/
2789+
def removeEventListener[T <: Event](`type`: String,
2790+
listener: js.Function1[T, _],
2791+
options: EventListenerOptions): Unit = js.native
2792+
2793+
/**
2794+
* The EventTarget.addEventListener() method
2795+
* registers the specified listener
2796+
* on the EventTarget it's called on.
2797+
* The event target may be an Element in a document,
2798+
* the Document itself, a Window, or any other object that supports events
2799+
* (such as XMLHttpRequest).
2800+
*
2801+
* This implementation accepts a settings object of type EventListenerOptions.
2802+
*
2803+
* MDN
2804+
*/
2805+
def addEventListener[T <: Event](`type`: String,
2806+
listener: js.Function1[T, _],
2807+
options: EventListenerOptions): Unit = js.native
2808+
27432809
/**
27442810
* Dispatches an Event at the specified EventTarget, invoking the affected
27452811
* EventListeners in the appropriate order. The normal event processing rules

0 commit comments

Comments
 (0)