| <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> |