@@ -2693,8 +2693,83 @@ class Window
2693
2693
}
2694
2694
2695
2695
/**
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
+ object EventListenerOptions {
2734
+
2735
+ /**
2736
+ * Construct a new EventListenerOptions
2737
+ *
2738
+ * @param capture
2739
+ * A Boolean indicating that events of this type
2740
+ * will be dispatched to the registered listener
2741
+ * before being dispatched to any EventTarget
2742
+ * beneath it in the DOM tree.
2743
+ * @param once
2744
+ * A Boolean indicating that the listener
2745
+ * should be invoked at most once after being added.
2746
+ * If true, the listener would be automatically removed when invoked.
2747
+ * @param passive
2748
+ * A Boolean which, if true, indicates
2749
+ * that the function specified by listener
2750
+ * will never call preventDefault().
2751
+ * If a passive listener does call preventDefault(),
2752
+ * the user agent will do nothing other
2753
+ * than generate a console warning.
2754
+ * See Improving scrolling performance with passive listeners to learn more.
2755
+ * @return a new EventListenerOptions
2756
+ */
2757
+ def apply (capture : js.UndefOr [Boolean ] = js.undefined,
2758
+ once : js.UndefOr [Boolean ] = js.undefined,
2759
+ passive : js.UndefOr [Boolean ] = js.undefined): EventListenerOptions = {
2760
+ val result = js.Dynamic .literal()
2761
+
2762
+ capture.foreach(result.capture = _)
2763
+ once.foreach(result.once = _)
2764
+ passive.foreach(result.passive = _)
2765
+
2766
+ result.asInstanceOf [EventListenerOptions ]
2767
+ }
2768
+ }
2769
+
2770
+ /**
2771
+ * EventTarget is a DOM interface implemented by objects
2772
+ * that can receive DOM events and have listeners for them.
2698
2773
*
2699
2774
* Element, document, and window are the most common event targets, but other
2700
2775
* objects can be event targets too, for example XMLHttpRequest, AudioNode,
@@ -2731,6 +2806,34 @@ class EventTarget extends js.Object {
2731
2806
listener : js.Function1 [T , _],
2732
2807
useCapture : Boolean = js.native): Unit = js.native
2733
2808
2809
+ /**
2810
+ * Removes the event listener previously registered with
2811
+ * EventTarget.addEventListener.
2812
+ *
2813
+ * This implementation accepts a settings object of type EventListenerOptions.
2814
+ *
2815
+ * MDN
2816
+ */
2817
+ def removeEventListener [T <: Event ](`type` : String ,
2818
+ listener : js.Function1 [T , _],
2819
+ options : EventListenerOptions ): Unit = js.native
2820
+
2821
+ /**
2822
+ * The EventTarget.addEventListener() method
2823
+ * registers the specified listener
2824
+ * on the EventTarget it's called on.
2825
+ * The event target may be an Element in a document,
2826
+ * the Document itself, a Window, or any other object that supports events
2827
+ * (such as XMLHttpRequest).
2828
+ *
2829
+ * This implementation accepts a settings object of type EventListenerOptions.
2830
+ *
2831
+ * MDN
2832
+ */
2833
+ def addEventListener [T <: Event ](`type` : String ,
2834
+ listener : js.Function1 [T , _],
2835
+ options : EventListenerOptions ): Unit = js.native
2836
+
2734
2837
/**
2735
2838
* Dispatches an Event at the specified EventTarget, invoking the affected
2736
2839
* EventListeners in the appropriate order. The normal event processing rules
0 commit comments