Skip to content

Dom_html: add window.matchMedia & MediaQueryList #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* Compiler: deadcode elimination of cyclic values (#1978)
* Compiler: directly write Wasm binary modules (#2000, #2003)
* Compiler: rewrote inlining pass (#1935, #2018, #2027)
* Library: add Dom_html.window.matchMedia & Dom_html.mediaQueryList (#2017)

## Bug fixes
* Compiler: fix stack overflow issues with double translation (#1869)
Expand Down
20 changes: 20 additions & 0 deletions lib/js_of_ocaml/dom_html.ml
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ and toggleEvent = object
method oldState : js_string t readonly_prop
end

and mediaQueryListEvent = object
inherit event

method matches : js_string t readonly_prop

method media : bool t readonly_prop
end

and dataTransfer = object
method dropEffect : js_string t prop

Expand Down Expand Up @@ -2312,6 +2320,16 @@ class type _URL = object
method revokeObjectURL : js_string t -> unit meth
end

class type mediaQueryList = object
method media : js_string t prop

method matches : bool readonly_prop

method onchange : (mediaQueryList t, mediaQueryListEvent t) event_listener prop

inherit eventTarget
end

class type window = object
inherit eventTarget

Expand Down Expand Up @@ -2428,6 +2446,8 @@ class type window = object
method _URL : _URL t readonly_prop

method devicePixelRatio : number_t readonly_prop

method matchMedia : js_string t -> mediaQueryList t meth
end

let window : window t = Js.Unsafe.global
Expand Down
20 changes: 20 additions & 0 deletions lib/js_of_ocaml/dom_html.mli
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ and toggleEvent = object
method oldState : js_string t readonly_prop
end

and mediaQueryListEvent = object
inherit event

method matches : js_string t readonly_prop

method media : bool t readonly_prop
end

and dataTransfer = object
method dropEffect : js_string t prop

Expand Down Expand Up @@ -2164,6 +2172,16 @@ class type _URL = object
method revokeObjectURL : js_string t -> unit meth
end

class type mediaQueryList = object
method media : js_string t prop

method matches : bool readonly_prop

method onchange : (mediaQueryList t, mediaQueryListEvent t) event_listener prop

inherit eventTarget
end

(** Specification of window objects *)
class type window = object
inherit eventTarget
Expand Down Expand Up @@ -2285,6 +2303,8 @@ class type window = object
method _URL : _URL t readonly_prop

method devicePixelRatio : number_t readonly_prop

method matchMedia : js_string t -> mediaQueryList t meth
end

val window : window t
Expand Down