| 1 |
<html> |
| 2 |
<!-- |
| 3 |
Copyright 2010 The Closure Library Authors. All Rights Reserved. |
| 4 |
|
| 5 |
Use of this source code is governed by the Apache License, Version 2.0. |
| 6 |
See the COPYING file for details. |
| 7 |
--> |
| 8 |
<head> |
| 9 |
<title>Event Test</title> |
| 10 |
<script type="text/javascript" src="../base.js"></script> |
| 11 |
<script type="text/javascript"> |
| 12 |
goog.require('goog.events.EventTarget'); |
| 13 |
goog.require('goog.events.Event'); |
| 14 |
</script> |
| 15 |
</head> |
| 16 |
<body> |
| 17 |
|
| 18 |
<script type="text/javascript"> |
| 19 |
|
| 20 |
var preventDefault = false; |
| 21 |
var stopPropagation = false; |
| 22 |
|
| 23 |
function func1(e) { |
| 24 |
alert('func1'); |
| 25 |
if (preventDefault) e.preventDefault(); |
| 26 |
if (stopPropagation) e.stopPropagation(); |
| 27 |
} |
| 28 |
|
| 29 |
function func2(e) { |
| 30 |
alert('func2'); |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
function Something() { } |
| 35 |
goog.inherits(Something, goog.events.EventTarget); |
| 36 |
|
| 37 |
Something.prototype.DoSomething = function() { |
| 38 |
alert('Doing something'); |
| 39 |
return this.dispatchEvent(new DemoEventObject('Wooo')); |
| 40 |
} |
| 41 |
|
| 42 |
function DemoEventObject(arg) { |
| 43 |
this.type = 'synth'; |
| 44 |
this.arg = arg; |
| 45 |
} |
| 46 |
goog.inherits(DemoEventObject, goog.events.Event); |
| 47 |
|
| 48 |
var st = new Something(); |
| 49 |
|
| 50 |
goog.events.listen(st, 'synth', func1, true); |
| 51 |
goog.events.listen(st, 'synth', func2, false); |
| 52 |
|
| 53 |
|
| 54 |
alert('Response = ' + st.DoSomething() + '\nShould be true'); |
| 55 |
|
| 56 |
preventDefault = true; |
| 57 |
stopPropagation = false; |
| 58 |
alert('Response = ' + st.DoSomething() + '\nShould be false'); |
| 59 |
|
| 60 |
preventDefault = false; |
| 61 |
stopPropagation = true; |
| 62 |
alert('Response = ' + st.DoSomething() + '\nShould be true and only func1 should have been called'); |
| 63 |
|
| 64 |
preventDefault = true; |
| 65 |
stopPropagation = true; |
| 66 |
alert('Response = ' + st.DoSomething() + '\nShould be false and only func1 should have been called'); |
| 67 |
|
| 68 |
</script> |
| 69 |
</body> |
| 70 |
</html> |