changeset 2156:d857da05f042

Allow mouse and key events for <body>
author Adam Chlipala <adam@chlipala.net>
date Thu, 02 Jul 2015 12:42:49 -0400
parents 7ce804ecd56b
children 9c8016d99969
files lib/ur/basis.urs tests/bodyClick.ur
diffstat 2 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lib/ur/basis.urs	Thu Jun 11 19:38:03 2015 -0400
+++ b/lib/ur/basis.urs	Thu Jul 02 12:42:49 2015 -0400
@@ -811,21 +811,6 @@
 val title : unit -> tag [Data = data_attr] head [] [] []
 val link : unit -> tag [Data = data_attr, Id = id, Rel = string, Typ = string, Href = url, Media = string] head [] [] []
 
-val body : unit -> tag [Data = data_attr, Onload = transaction unit, Onresize = transaction unit, Onunload = transaction unit, Onhashchange = transaction unit]
-                       html body [] []
-con bodyTag = fn (attrs :: {Type}) =>
-                 ctx ::: {Unit} ->
-                 [[Body] ~ ctx] =>
-                    unit -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
-con bodyTagStandalone = fn (attrs :: {Type}) =>
-                           ctx ::: {Unit}
-                           -> [[Body] ~ ctx] =>
-                                 unit -> tag attrs ([Body] ++ ctx) [] [] []
-
-val br : bodyTagStandalone [Data = data_attr, Id = id]
-
-con focusEvents = [Onblur = transaction unit, Onfocus = transaction unit]
-
 datatype mouseButton = Left | Right | Middle
 
 type mouseEvent = { ScreenX : int, ScreenY : int, ClientX : int, ClientY : int,
@@ -841,6 +826,24 @@
 con keyEvents = map (fn _ :: Unit => keyEvent -> transaction unit)
                         [Onkeydown, Onkeypress, Onkeyup]
 
+val body : unit -> tag ([Data = data_attr, Onload = transaction unit, Onresize = transaction unit, Onunload = transaction unit, Onhashchange = transaction unit]
+                            ++ mouseEvents ++ keyEvents)
+                       html body [] []
+
+con bodyTag = fn (attrs :: {Type}) =>
+                 ctx ::: {Unit} ->
+                 [[Body] ~ ctx] =>
+                    unit -> tag attrs ([Body] ++ ctx) ([Body] ++ ctx) [] []
+con bodyTagStandalone = fn (attrs :: {Type}) =>
+                           ctx ::: {Unit}
+                           -> [[Body] ~ ctx] =>
+                                 unit -> tag attrs ([Body] ++ ctx) [] [] []
+
+val br : bodyTagStandalone [Data = data_attr, Id = id]
+
+con focusEvents = [Onblur = transaction unit, Onfocus = transaction unit]
+
+
 (* Key arguments are character codes. *)
 con resizeEvents = [Onresize = transaction unit]
 con scrollEvents = [Onscroll = transaction unit]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/bodyClick.ur	Thu Jul 02 12:42:49 2015 -0400
@@ -0,0 +1,6 @@
+fun main () : transaction page = return <xml>
+  <body onclick={fn _ => alert "You clicked the body."}
+        onkeyup={fn _ => alert "Key"}>
+    <p>Text</p>
+  </body>
+</xml>