Mercurial > urweb
changeset 1559:df6a7a22760a
New Basis functions: preventDefault and stopPropagation (code contributed by Vladimir Shabanov)
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 11 Sep 2011 14:14:49 -0400 |
parents | 6fe6bda2b928 |
children | 63311c13d9f7 |
files | doc/manual.tex lib/js/urweb.js lib/ur/basis.urs src/settings.sml |
diffstat | 4 files changed, 36 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/manual.tex Sun Sep 11 11:37:26 2011 -0400 +++ b/doc/manual.tex Sun Sep 11 14:14:49 2011 -0400 @@ -1983,6 +1983,13 @@ \mt{val} \; \mt{onMouseup} : \mt{transaction} \; \mt{unit} \to \mt{transaction} \; \mt{unit} \end{array}$$ +Versions of standard JavaScript functions are provided that event handlers may call to mask default handling or prevent bubbling of events up to parent DOM nodes, respectively. + +$$\begin{array}{l} + \mt{val} \; \mt{preventDefault} : \mt{transaction} \; \mt{unit} \\ + \mt{val} \; \mt{stopPropagation} : \mt{transaction} \; \mt{unit} +\end{array}$$ + \subsubsection{Node IDs} There is an abstract type of node IDs that may be assigned to \cd{id} attributes of most HTML tags.
--- a/lib/js/urweb.js Sun Sep 11 11:37:26 2011 -0400 +++ b/lib/js/urweb.js Sun Sep 11 14:14:49 2011 -0400 @@ -215,9 +215,9 @@ function uw_handler(name, f) { var old = document[name]; if (old == undefined) - document[name] = function() { execF(f); return false; }; + document[name] = function(event) { uw_event = event; execF(f); }; else - document[name] = function() { old(); execF(f); return false; }; + document[name] = function(event) { uw_event = event; old(); execF(f); }; } function uw_onClick(f) { @@ -239,9 +239,9 @@ function uw_keyHandler(name, f) { var old = document[name]; if (old == undefined) - document[name] = function(event) { uw_event = event; execF(execF(f, kc())); return false; }; + document[name] = function(event) { uw_event = event; execF(execF(f, kc())); }; else - document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); return false; }; + document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); }; } function uw_onKeydown(f) { @@ -256,6 +256,19 @@ uw_keyHandler("onkeyup", f); } +// Cancelling of further event processing + +function uw_preventDefault() { + var e = window.event ? window.event : uw_event; + e.returnValue = false; + if (e.preventDefault) e.preventDefault(); +} + +function uw_stopPropagation() { + var e = window.event ? window.event : uw_event; + e.cancelBubble = true; + if (e.stopPropagation) e.stopPropagation(); +} // Embedding closures in XML strings
--- a/lib/ur/basis.urs Sun Sep 11 11:37:26 2011 -0400 +++ b/lib/ur/basis.urs Sun Sep 11 14:14:49 2011 -0400 @@ -870,6 +870,11 @@ val onMousedown : transaction unit -> transaction unit val onMouseup : transaction unit -> transaction unit +(* Prevents default handling of current event *) +val preventDefault : transaction unit +(* Stops propagation of current event *) +val stopPropagation : transaction unit + val show_xml : ctx ::: {Unit} -> use ::: {Type} -> bind ::: {Type} -> show (xml ctx use bind)
--- a/src/settings.sml Sun Sep 11 11:37:26 2011 -0400 +++ b/src/settings.sml Sun Sep 11 14:14:49 2011 -0400 @@ -156,6 +156,8 @@ "onKeyup", "onMousedown", "onMouseup", + "preventDefault", + "stopPropagation", "fresh"] val benign = ref benignBase @@ -182,7 +184,9 @@ "onKeypress", "onKeyup", "onMousedown", - "onMouseup"] + "onMouseup", + "preventDefault", + "stopPropagation"] val client = ref clientBase fun setClientOnly ls = client := S.addList (clientBase, ls) fun isClientOnly x = S.member (!client, x) @@ -280,6 +284,8 @@ ("onKeyup", "uw_onKeyup"), ("onMousedown", "uw_onMousedown"), ("onMouseup", "uw_onMouseup"), + ("preventDefault", "uw_preventDefault"), + ("stopPropagation", "uw_stopPropagation"), ("fresh", "fresh")] val jsFuncs = ref jsFuncsBase