Skip to content

Commit 31bb258

Browse files
committed
Add EventListenerOptions trait and implement it in addEventListener
1 parent 4cf1503 commit 31bb258

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,38 @@ class Window
26922692
var lostpointercapture: js.Function1[PointerEvent, _] = js.native
26932693
}
26942694

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

2766+
/**
2767+
* The EventTarget.addEventListener() method registers the specified listener on
2768+
* the EventTarget it's called on. The event target may be an Element in a document, the
2769+
* Document itself, a Window, or any other object that supports events (such as
2770+
* XMLHttpRequest).
2771+
*
2772+
* This implementation accepts a settings object of type EventListenerOptions.
2773+
*
2774+
* MDN
2775+
*/
2776+
def addEventListener[T <: Event](`type`: String,
2777+
listener: js.Function1[T, _],
2778+
options: EventListenerOptions): Unit = js.native
2779+
27342780
/**
27352781
* Dispatches an Event at the specified EventTarget, invoking the affected
27362782
* EventListeners in the appropriate order. The normal event processing rules

0 commit comments

Comments
 (0)