| 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'); |
| 13 |
goog.require('goog.events.EventType'); |
| 14 |
</script> |
| 15 |
</head> |
| 16 |
<body> |
| 17 |
<p> |
| 18 |
<a id="link1" href="#link1">Link 1</a><br /> |
| 19 |
<a id="link2" href="#link2">Link 2</a><br /> |
| 20 |
<a id="link3" href="#link3">Link 3</a><br /> |
| 21 |
<a id="link4" href="#link4">Link 4</a> |
| 22 |
</p> |
| 23 |
<p> |
| 24 |
<a href="javascript:addListeners()">Listen</a> | |
| 25 |
<a href="javascript:removeListeners()">UnListen</a> | |
| 26 |
<a href="javascript:void(goog.events.unlisten($('link1'), 'click', one))">Remove One</a> | |
| 27 |
<a href="javascript:void(goog.events.unlisten($('link1'), 'click', two))">Remove Two</a> | |
| 28 |
<a href="javascript:void(goog.events.unlisten($('link1'), 'click', three))">Remove Three</a> | |
| 29 |
</p> |
| 30 |
<pre id="info"></pre> |
| 31 |
|
| 32 |
<div id="test1" style="background-color: pink;"> |
| 33 |
Test 1 |
| 34 |
<div id="test2" style="background-color: lightblue;"> |
| 35 |
Test 2 |
| 36 |
<div id="test3" style="background-color: lightyellow;"> |
| 37 |
Test 3 |
| 38 |
</div> |
| 39 |
Test 2 |
| 40 |
</div> |
| 41 |
Test 1 |
| 42 |
</div> |
| 43 |
|
| 44 |
<script type="text/javascript"> |
| 45 |
|
| 46 |
function $(el) { return document.getElementById(el); } |
| 47 |
|
| 48 |
function handleEventC(e) { |
| 49 |
alert('capture'); |
| 50 |
$('info').innerHTML = "CAPTURE<br>" + goog.events.expose(e).replace(/\n/g, '<br>'); |
| 51 |
} |
| 52 |
function handleEventB(e) { |
| 53 |
alert('bubble'); |
| 54 |
$('info').innerHTML = "BUBBLE<br>" + goog.events.expose(e).replace(/\n/g, '<br>'); |
| 55 |
} |
| 56 |
|
| 57 |
function one() { |
| 58 |
alert('1'); |
| 59 |
} |
| 60 |
function two() { |
| 61 |
alert('2'); |
| 62 |
} |
| 63 |
function three() { |
| 64 |
alert('3'); |
| 65 |
} |
| 66 |
|
| 67 |
function addListeners() { |
| 68 |
goog.events.listen($('link1'), 'click', one); |
| 69 |
goog.events.listen($('link1'), 'click', two); |
| 70 |
goog.events.listen($('link1'), 'click', three); |
| 71 |
|
| 72 |
goog.events.listen($('link2'), 'click', handleEventB); |
| 73 |
goog.events.listen($('link3'), 'click', handleEventB); |
| 74 |
goog.events.listen($('link4'), 'click', handleEventB); |
| 75 |
} |
| 76 |
|
| 77 |
function removeListeners() { |
| 78 |
goog.events.unlisten($('link1'), 'click', handleEventB); |
| 79 |
goog.events.unlisten($('link2'), 'click', handleEventB); |
| 80 |
goog.events.unlisten($('link3'), 'click', handleEventB); |
| 81 |
goog.events.unlisten($('link4'), 'click', handleEventB); |
| 82 |
} |
| 83 |
|
| 84 |
addListeners(); |
| 85 |
|
| 86 |
goog.events.listen($('test1'), goog.events.EventType.CLICK, handleEventC, |
| 87 |
true, $('test3')); |
| 88 |
goog.events.listen($('test1'), goog.events.EventType.CLICK, handleEventB, |
| 89 |
false, $('test3')); |
| 90 |
|
| 91 |
alert('howdy'); |
| 92 |
</script> |
| 93 |
</body> |
| 94 |
</html> |