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