summaryrefslogtreecommitdiff
path: root/lib/js/urweb.js
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-09-03 11:48:12 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2011-09-03 11:48:12 -0400
commit3c860c3c95d4d085499fd01e3140f32aafbc1bd7 (patch)
tree7c32d9dad6206562624b1bb483a1c7b8bbdc4fec /lib/js/urweb.js
parentad19583df3d07b968a9fb983813e45dc55fe2cc6 (diff)
New client-side, document-level event handlers
Diffstat (limited to 'lib/js/urweb.js')
-rw-r--r--lib/js/urweb.js63
1 files changed, 54 insertions, 9 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index 4d9a1419..1277175d 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -202,6 +202,60 @@ function servErr(s) {
window.setTimeout(function () { runHandlers("Server", serverHandlers, s); }, 0);
}
+// Key events
+
+var uw_event = null;
+
+function kc() {
+ return window.event ? event.keyCode : (uw_event ? uw_event.which : 0);
+}
+
+// Document events
+
+function uw_handler(name, f) {
+ var old = document[name];
+ if (old == undefined)
+ document[name] = function() { execF(f); return false; };
+ else
+ document[name] = function() { old(); execF(f); return false; };
+}
+
+function uw_onClick(f) {
+ uw_handler("onclick", f);
+}
+
+function uw_onDblclick(f) {
+ uw_handler("ondblclick", f);
+}
+
+function uw_onMousedown(f) {
+ uw_handler("onmousedown", f);
+}
+
+function uw_onMouseup(f) {
+ uw_handler("onmouseup", f);
+}
+
+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; };
+ else
+ document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); return false; };
+}
+
+function uw_onKeydown(f) {
+ uw_keyHandler("onkeydown", f);
+}
+
+function uw_onKeypress(f) {
+ uw_keyHandler("onkeypress", f);
+}
+
+function uw_onKeyup(f) {
+ uw_keyHandler("onkeyup", f);
+}
+
// Embedding closures in XML strings
@@ -1025,15 +1079,6 @@ function sp(e) {
}
-// Key events
-
-var uw_event = null;
-
-function kc() {
- return window.event ? event.keyCode : (uw_event ? uw_event.keyCode : 0);
-}
-
-
// The Ur interpreter
var urfuncs = [];