@@ -352,16 +352,37 @@ end
352352
353353type event_listener_id = unit -> unit
354354
355- let addEventListener (e : (< .. > as 'a) t ) typ h capt =
355+ class type event_listener_options =
356+ object
357+ method capture : bool t writeonly_prop
358+
359+ method once : bool t writeonly_prop
360+
361+ method passive : bool t writeonly_prop
362+ end
363+
364+ let addEventListenerWithOptions (e : (< .. > as 'a) t ) typ ?capture ?once ?passive h =
356365 if (Js.Unsafe. coerce e)##.addEventListener == Js. undefined
357366 then
358367 let ev = (Js. string " on" )##concat typ in
359368 let callback e = Js.Unsafe. call (h, e, [||]) in
360369 let () = (Js.Unsafe. coerce e)##attachEvent ev callback in
361370 fun () -> (Js.Unsafe. coerce e)##detachEvent ev callback
362371 else
363- let () = (Js.Unsafe. coerce e)##addEventListener typ h capt in
364- fun () -> (Js.Unsafe. coerce e)##removeEventListener typ h capt
372+ let opts : event_listener_options t = Js.Unsafe. obj [||] in
373+ let iter t f =
374+ match t with
375+ | None -> ()
376+ | Some b -> f b
377+ in
378+ iter capture (fun b -> opts##.capture := b);
379+ iter once (fun b -> opts##.once := b);
380+ iter passive (fun b -> opts##.passive := b);
381+ let () = (Js.Unsafe. coerce e)##addEventListener typ h opts in
382+ fun () -> (Js.Unsafe. coerce e)##removeEventListener typ h opts
383+
384+ let addEventListener (e : (< .. > as 'a) t ) typ h capt =
385+ addEventListenerWithOptions e typ ~capture: capt h
365386
366387let removeEventListener id = id ()
367388
0 commit comments