Skip to content

Commit 584607f

Browse files
committed
Add EventListenerOptions trait and implement it in addEventListener
Create removeEventListener function which accepts an options object
1 parent 4cf1503 commit 584607f

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
@@ -2693,8 +2693,46 @@ class Window
26932693
}
26942694

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

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

0 commit comments

Comments
 (0)