diff lib/js/urweb.js @ 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 e1f5d9c4cc20
children f403e129c276
line wrap: on
line diff
--- 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