Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1558:6fe6bda2b928 | 1559:df6a7a22760a |
---|---|
213 // Document events | 213 // Document events |
214 | 214 |
215 function uw_handler(name, f) { | 215 function uw_handler(name, f) { |
216 var old = document[name]; | 216 var old = document[name]; |
217 if (old == undefined) | 217 if (old == undefined) |
218 document[name] = function() { execF(f); return false; }; | 218 document[name] = function(event) { uw_event = event; execF(f); }; |
219 else | 219 else |
220 document[name] = function() { old(); execF(f); return false; }; | 220 document[name] = function(event) { uw_event = event; old(); execF(f); }; |
221 } | 221 } |
222 | 222 |
223 function uw_onClick(f) { | 223 function uw_onClick(f) { |
224 uw_handler("onclick", f); | 224 uw_handler("onclick", f); |
225 } | 225 } |
237 } | 237 } |
238 | 238 |
239 function uw_keyHandler(name, f) { | 239 function uw_keyHandler(name, f) { |
240 var old = document[name]; | 240 var old = document[name]; |
241 if (old == undefined) | 241 if (old == undefined) |
242 document[name] = function(event) { uw_event = event; execF(execF(f, kc())); return false; }; | 242 document[name] = function(event) { uw_event = event; execF(execF(f, kc())); }; |
243 else | 243 else |
244 document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); return false; }; | 244 document[name] = function(event) { uw_event = event; old(); execF(execF(f, kc())); }; |
245 } | 245 } |
246 | 246 |
247 function uw_onKeydown(f) { | 247 function uw_onKeydown(f) { |
248 uw_keyHandler("onkeydown", f); | 248 uw_keyHandler("onkeydown", f); |
249 } | 249 } |
254 | 254 |
255 function uw_onKeyup(f) { | 255 function uw_onKeyup(f) { |
256 uw_keyHandler("onkeyup", f); | 256 uw_keyHandler("onkeyup", f); |
257 } | 257 } |
258 | 258 |
259 // Cancelling of further event processing | |
260 | |
261 function uw_preventDefault() { | |
262 var e = window.event ? window.event : uw_event; | |
263 e.returnValue = false; | |
264 if (e.preventDefault) e.preventDefault(); | |
265 } | |
266 | |
267 function uw_stopPropagation() { | |
268 var e = window.event ? window.event : uw_event; | |
269 e.cancelBubble = true; | |
270 if (e.stopPropagation) e.stopPropagation(); | |
271 } | |
259 | 272 |
260 // Embedding closures in XML strings | 273 // Embedding closures in XML strings |
261 | 274 |
262 function cs(f) { | 275 function cs(f) { |
263 return {closure: f}; | 276 return {closure: f}; |