Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit a10c3b8

Browse files
spockeglennsl
authored andcommitted
selectionchange event (#161)
* added selection change event * separated out the selectionchange event into a GlobalsEventHandlers
1 parent ff1c9ef commit a10c3b8

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

src/Webapi/Webapi__Dom/Webapi__Dom__Element.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type t = Dom.element;
111111

112112
include Webapi__Dom__Node.Impl({ type nonrec t = t; });
113113
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; });
114+
include Webapi__Dom__GlobalEventHandlers.Impl({ type nonrec t = t; });
114115
include Webapi__Dom__ParentNode.Impl({ type nonrec t = t; });
115116
include Webapi__Dom__NonDocumentTypeChildNode.Impl({ type nonrec t = t; });
116117
include Webapi__Dom__ChildNode.Impl({ type nonrec t = t; });
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Mixin */
2+
module Impl = (T: {type t;}) => {
3+
[@bs.send.pipe : T.t] external addSelectionChangeEventListener : ([@bs.as "selectionchange"] _, Dom.focusEvent => unit) => unit = "addEventListener";
4+
[@bs.send.pipe : T.t] external addSelectionChangeEventListenerWithOptions : ([@bs.as "selectionchange"] _, Dom.focusEvent => unit, {. "capture": bool, "once": bool, "passive": bool}) => unit = "addEventListener"; /* not widely supported */
5+
[@bs.send.pipe : T.t] external addSelectionChangeEventListenerUseCapture : ([@bs.as "selectionchange"] _, Dom.focusEvent => unit, [@bs.as {json|true|json}] _) => unit = "addEventListener";
6+
[@bs.send.pipe : T.t] external removeSelectionChangeEventListener : ([@bs.as "selectionchange"] _, Dom.focusEvent => unit) => unit = "removeEventListener";
7+
[@bs.send.pipe : T.t] external removeSelectionChangeEventListenerWithOptions : ([@bs.as "selectionchange"] _, Dom.focusEvent => unit, {. "capture": bool, "passive": bool}) => unit = "removeEventListener"; /* not widely supported */
8+
[@bs.send.pipe : T.t] external removeSelectionChangeEventListenerUseCapture : ([@bs.as "selectionchange"] _, Dom.focusEvent =>unit, [@bs.as {json|true|json}] _) => unit = "removeEventListener";
9+
};

src/Webapi/Webapi__Dom/Webapi__Dom__HtmlDocument.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ type t = Dom.htmlDocument;
5959

6060
include Webapi__Dom__Node.Impl({ type nonrec t = t; });
6161
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; });
62+
include Webapi__Dom__GlobalEventHandlers.Impl({ type nonrec t = t; });
6263
include Webapi__Dom__Document.Impl({ type nonrec t = t; });
6364
include Impl({ type nonrec t = t; });

src/Webapi/Webapi__Dom/Webapi__Dom__HtmlElement.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ type t = Dom.htmlElement;
9999

100100
include Webapi__Dom__Node.Impl({ type nonrec t = t; });
101101
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; });
102+
include Webapi__Dom__GlobalEventHandlers.Impl({ type nonrec t = t; });
102103
include Webapi__Dom__Element.Impl({ type nonrec t = t; });
103104
include Impl({ type nonrec t = t; });

src/Webapi/Webapi__Dom/Webapi__Dom__Window.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ type t = Dom.window;
103103

104104
/* include WindowOrWorkerGlobalScope? not really "dom" though */
105105
include Webapi__Dom__EventTarget.Impl({ type nonrec t = t; });
106+
include Webapi__Dom__GlobalEventHandlers.Impl({ type nonrec t = t; });
106107
include Impl({ type nonrec t = t; });
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
open Webapi.Dom;
2+
3+
let handleSelection = (_) => print_endline("change");
4+
5+
let elm = document |> Document.createElement("strong");
6+
7+
Element.addSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "once": true, "capture": false}, elm);
8+
Element.addSelectionChangeEventListenerUseCapture(handleSelection, elm);
9+
Element.removeSelectionChangeEventListener(handleSelection, elm);
10+
Element.removeSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "capture": false}, elm);
11+
Element.removeSelectionChangeEventListenerUseCapture(handleSelection, elm);
12+
13+
let htmlElm = document |> Document.createElement("strong") |> HtmlElement.ofElement |> TestHelpers.unsafelyUnwrapOption;
14+
15+
HtmlElement.addSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "once": true, "capture": false}, htmlElm);
16+
HtmlElement.addSelectionChangeEventListenerUseCapture(handleSelection, htmlElm);
17+
HtmlElement.removeSelectionChangeEventListener(handleSelection, htmlElm);
18+
HtmlElement.removeSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "capture": false}, htmlElm);
19+
HtmlElement.removeSelectionChangeEventListenerUseCapture(handleSelection, htmlElm);
20+
21+
let htmlDoc = document |> Document.asHtmlDocument |> TestHelpers.unsafelyUnwrapOption;
22+
23+
HtmlDocument.addSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "once": true, "capture": false}, htmlDoc);
24+
HtmlDocument.addSelectionChangeEventListenerUseCapture(handleSelection, htmlDoc);
25+
HtmlDocument.removeSelectionChangeEventListener(handleSelection, htmlDoc);
26+
HtmlDocument.removeSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "capture": false}, htmlDoc);
27+
HtmlDocument.removeSelectionChangeEventListenerUseCapture(handleSelection, htmlDoc);
28+
29+
Window.addSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "once": true, "capture": false}, window);
30+
Window.addSelectionChangeEventListenerUseCapture(handleSelection, window);
31+
Window.removeSelectionChangeEventListener(handleSelection, window);
32+
Window.removeSelectionChangeEventListenerWithOptions(handleSelection, {"passive": true, "capture": false}, window);
33+
Window.removeSelectionChangeEventListenerUseCapture(handleSelection, window);

0 commit comments

Comments
 (0)