delegate.html revision fb83a09fe023a741781ee955f4e9538d3cbe21a2
3215b14029b163463e7225627b6781e4a049f3d8Caridy<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3215b14029b163463e7225627b6781e4a049f3d8Caridy<html>
3215b14029b163463e7225627b6781e4a049f3d8Caridy<head>
3215b14029b163463e7225627b6781e4a049f3d8Caridy <title>YUI Event Delegate Tests</title>
3215b14029b163463e7225627b6781e4a049f3d8Caridy</head>
0a9c6f9f30a66e52ec4ea4ed93504580b3a5669aAdam Moore<body class="yui3-skin-sam">
3215b14029b163463e7225627b6781e4a049f3d8Caridy <div id="doc">
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy <div id="mod1">
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots <div id="mod-header" class="hd"><h3 class="title">H3 - Title</h3></div>
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots <div id="mod-body" class="bd">
5889c2819167de6bb3c1d1a1e3a5e6af060e8a95Adam Moore <p>simple paragraph with a link <a href="#"id="firstlink">simple link</a></p>
5889c2819167de6bb3c1d1a1e3a5e6af060e8a95Adam Moore <p>another paragraph with a complex link <a href="#" id="secondlink"><strong>strong within link</strong><img alt="fake image" id="fakeimage" /> - complex <span id="spanwithinlink">link</span></a></p>
3215b14029b163463e7225627b6781e4a049f3d8Caridy </div>
3215b14029b163463e7225627b6781e4a049f3d8Caridy </div>
3215b14029b163463e7225627b6781e4a049f3d8Caridy
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots <div id="container">
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots <ul id="list-1">
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots <li id="item-1"><em>Item Type One</em></li>
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots <li id="item-2"><em>Item Type Two</em></li>
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots <li id="item-3"><em>Item Type Three</em></li>
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots </ul>
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots </div>
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <ul id="list-2">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-2-li-1"><em><em>Item One</em></em></li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-2-li-2"><em>Item Two</em></li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-2-li-3"><em>Item Three</em>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <ul id="list-3">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-3-li-1"><em>Item Three - One</em></li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-3-li-1"><em>Item Three - Two</em></li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <li id="list-3-li-1"><em>Item Three - Three</em></li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </ul>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </li>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </ul>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1" class="div-a">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1-1" class="div-b">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1-1-1" class="div-c"><em>Item One</em></div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1-2" class="div-x">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <em>Item Two</em>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1-2-1" class="div-b">
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <em>Item Two - One</em>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots <div id="div-1-2-1-1" class="div-c"><em>Item Two - Two</em></div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots </div>
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <div id="a">
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <p>Div A</p>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <div id="b" class="remove">
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <p>Div B</p>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <div id="c" class="remove">
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith <p>Div C</p>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith </div>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith </div>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith </div>
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith
3215b14029b163463e7225627b6781e4a049f3d8Caridy </div>
3215b14029b163463e7225627b6781e4a049f3d8Caridy <!-- YUI3 Core //-->
cb4f4f79feb7498d1f3406b88fb62209e5f5a444Adam Moore <script type="text/javascript" src="/build/yui/yui.js"></script>
3215b14029b163463e7225627b6781e4a049f3d8Caridy <!-- Initialization process //-->
3215b14029b163463e7225627b6781e4a049f3d8Caridy <script type="text/javascript">
3215b14029b163463e7225627b6781e4a049f3d8Caridy YUI({
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith filter: 'raw',
cb4f4f79feb7498d1f3406b88fb62209e5f5a444Adam Moore logExclude: { Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
3215b14029b163463e7225627b6781e4a049f3d8Caridy }).use('console', 'test', 'event', 'event-simulate', function (Y) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy // creating the console...
20abfc50d1764b9719bc040738ad7f68caff0f4fTodd Kloots (new Y.Console()).render();
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy // starting the testing process
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy // add the test cases and suites
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Test.Runner.add(new Y.Test.Case({
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy name: "Event Delegate Tests",
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_simple_delegate_for_anchors: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
abf248eeaac94371535d800391168fff8d32bb44Adam Moore var foo = false, t, ct, boundEl;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
c2e6a0e082fcb34905724d27cc7f6be467e1a6bcAdam Moore // the detach prefix broke when delegate from converted
c2e6a0e082fcb34905724d27cc7f6be467e1a6bcAdam Moore // from a custom event to a function (the function should
c2e6a0e082fcb34905724d27cc7f6be467e1a6bcAdam Moore // simply delegated to the custom event)
c2e6a0e082fcb34905724d27cc7f6be467e1a6bcAdam Moore // Y.delegate('foo|click', function(e) {
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t = e.target;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore ct = e.currentTarget;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore boundEl = e.container;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('firstlink'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isTrue(foo, "simple delegation fails, mod1 should pickup the event and test target [firstlink]");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith // Y.Assert.areEqual(t, Y.one('#firstlink'), "event delegate works but the target is an incorrect node, should be the matching node");
abf248eeaac94371535d800391168fff8d32bb44Adam Moore
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct, Y.one('#firstlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t, Y.one('#firstlink'), "event delegate works but the target is an incorrect node, should be the actual click target");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(boundEl, Y.one('#mod1'), "event delegate works but the container property should be the bound element");
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy },
3215b14029b163463e7225627b6781e4a049f3d8Caridy
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots test_multiple_selectors: function () {
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots var foo = false, t, ct, boundEl;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots foo = true;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots t = e.target;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots ct = e.currentTarget;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots boundEl = e.container;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', '.hd,.bd');
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots Y.Event.simulate(document.getElementById('mod-header'), 'click');
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct, Y.one('#mod-header'), "event delegate works but the matched element is an incorrect node, should be the matching node");
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots Y.Event.simulate(document.getElementById('mod-body'), 'click');
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct, Y.one('#mod-body'), "event delegate works but the matched element is an incorrect node, should be the matching node");
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots },
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots test_document_as_container: function () {
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots var foo = false, t, ct, boundEl;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots foo = true;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots t = e.target;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots ct = e.currentTarget;
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots boundEl = e.container;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith }, Y.one('#mod1').get('ownerDocument'), 'a');
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots Y.Event.simulate (document.getElementById('firstlink'), 'click');
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots Y.Assert.isTrue(foo, "simple delegation fails, mod1 should pickup the event and test target [firstlink]");
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct, Y.one('#firstlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t, Y.one('#firstlink'), "event delegate works but the target is an incorrect node, should be the actual click target");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(boundEl, Y.one('#mod1').get('ownerDocument'), "event delegate works but the container property should be the bound element");
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots },
379e0306e00b6f0add52f96907da048c03a9f2a1Todd Kloots
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_checking_delegation_target: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
abf248eeaac94371535d800391168fff8d32bb44Adam Moore var foo = false, t, ct, boundEl;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t = e.target;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore ct = e.currentTarget;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore boundEl = e.container;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('fakeimage'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isTrue(foo, "delegation fails for an image within an anchor, mod1 should pickup the event and test target [secondlink]");
3215b14029b163463e7225627b6781e4a049f3d8Caridy // in this case, the target should be the anchor, and not the image
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith // Y.Assert.areEqual(t, Y.one('#secondlink'), "event delegate works but the target is an incorrect node, should be the matching node");
abf248eeaac94371535d800391168fff8d32bb44Adam Moore
abf248eeaac94371535d800391168fff8d32bb44Adam Moore // this has been changed. the target is unchanged, the anchor is
abf248eeaac94371535d800391168fff8d32bb44Adam Moore
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct, Y.one('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t, Y.one('#fakeimage'), "event delegate works but the target is an incorrect node, should be the actual click target");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(boundEl, Y.one('#mod1'), "event delegate works but the container property should be the bound element");
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy },
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_including_container_in_selector: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy var foo = false, t;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t = e.target;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', '#mod1 a');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('firstlink'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isFalse(foo, "delegation fails, the container (specified in the on) can not be part of the selectors");
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy },
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_targeting_container_without_selectors: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy var foo = false, t;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t = e.target;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('firstlink'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isFalse(foo, "delegation fails, delegation without at least one selector should never trigger an event");
3215b14029b163463e7225627b6781e4a049f3d8Caridy },
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_multiple_selectors_one_match: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy var foo = false, t;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t = e.target;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a,a span');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('firstlink'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isTrue(foo, "multiple selectors fails, delegate should be able to match different selectors");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t, Y.one('#firstlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
3215b14029b163463e7225627b6781e4a049f3d8Caridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy },
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy test_multiple_delegate_matches: function(){
3215b14029b163463e7225627b6781e4a049f3d8Caridy
abf248eeaac94371535d800391168fff8d32bb44Adam Moore var foo1 = false, foo2 = false, t1, t2, ct1, ct2;
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo1 = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t1 = e.target;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore ct1 = e.currentTarget;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
3215b14029b163463e7225627b6781e4a049f3d8Caridy foo2 = true;
3215b14029b163463e7225627b6781e4a049f3d8Caridy t2 = e.target;
abf248eeaac94371535d800391168fff8d32bb44Adam Moore ct2 = e.currentTarget;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a span');
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Event.simulate (document.getElementById('spanwithinlink'), 'click');
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Assert.isTrue(foo2, "second match fail, delegate should be able to match [a span]");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct1, Y.one('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching selector");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t1, Y.one('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the clicked node");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct2, Y.one('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t2, Y.one('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the clicked");
3215b14029b163463e7225627b6781e4a049f3d8Caridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy },
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy test_bubble_up_after_delegate: function(){
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith var foo1 = false,
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith foo2 = false,
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith t1, t2, ct1, ct2, container1, container2, this1, this2;
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy foo1 = true;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith t1 = e.target;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith ct1 = e.currentTarget;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith container1 = e.container;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith this1 = this;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.on('click', function(e) {
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy foo2 = true;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith t2 = e.target;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith ct2 = e.currentTarget;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith container2 = e.container;
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith this2 = this;
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy }, '#doc');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Event.simulate (document.getElementById('spanwithinlink'), 'click');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Assert.isTrue(foo2, "second match fail, the event doesn't bubble up after the delegate routine");
abf248eeaac94371535d800391168fff8d32bb44Adam Moore // changed
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith // Y.Assert.areEqual(t1, Y.one('#secondlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(ct1, Y.one('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching selector");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t1, Y.one('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the actual target");
abf248eeaac94371535d800391168fff8d32bb44Adam Moore
abf248eeaac94371535d800391168fff8d32bb44Adam Moore // obsolete
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areEqual(t2, Y.one('#spanwithinlink'), "event delegate works but it doesn't restore e.target to the original value.");
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areSame(ct2, Y.one('#doc'));
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areSame(container1, Y.one('#mod1'));
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.isUndefined(container2);
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areSame(this1, Y.one('#secondlink'));
7b4d1363155303b5bfb852e5639b851bbd4dc255Luke Smith Y.Assert.areSame(this2, Y.one('#doc'));
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy },
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy test_bubble_up_after_delegate_halt: function(){
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy var foo1 = false, foo2 = false;
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy foo1 = true;
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy e.halt();
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.on('click', function(e) {
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy foo2 = true;
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy }, '#doc');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Event.simulate (document.getElementById('spanwithinlink'), 'click');
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
762404fab9a26ffe78629af69b947a582b2ebf1aCaridy Y.Assert.isFalse(foo2, "the listener for 'doc' got executed, which means that e.halt fails during the delegate routine");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots },
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots test_direct_descendant_combinator: function () {
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots var matchID = null;
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.one("#list-2").delegate("click", function (e) {
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots matchID = this.get("id");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots }, ">li");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Event.simulate(document.getElementById('list-3-li-1'), 'click');
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Assert.areEqual('list-2-li-3', matchID, "The currentTarget is an incorrect node, should be the matching node.");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots matchID = null;
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.one("#div-1").delegate("click", function (e) {
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots matchID = this.get("id");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots }, ">.div-b");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Event.simulate(document.getElementById('div-1-1-1'), 'click');
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Assert.areEqual('div-1-1', matchID, "The currentTarget is an incorrect node, should be the matching node.");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots matchID = null;
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Event.simulate(document.getElementById('div-1-2-1'), 'click');
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots Y.Assert.isNull(matchID, "The currentTarget is an incorrect node, should be the matching node.");
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots },
03fb873fb498b91f5def3bb608de5d01374f1e07Todd Kloots
14017741ef334485c65013d129608513161db7c2Luke Smith test_multiple_matches_in_subtree: function () {
14017741ef334485c65013d129608513161db7c2Luke Smith var ids = [];
14017741ef334485c65013d129608513161db7c2Luke Smith
14017741ef334485c65013d129608513161db7c2Luke Smith Y.delegate('click', function (e) {
14017741ef334485c65013d129608513161db7c2Luke Smith ids.push(this.get('id'));
14017741ef334485c65013d129608513161db7c2Luke Smith }, '#div-1', 'div');
14017741ef334485c65013d129608513161db7c2Luke Smith
14017741ef334485c65013d129608513161db7c2Luke Smith Y.Event.simulate(Y.one('#div-1-2-1-1 em')._node, 'click');
14017741ef334485c65013d129608513161db7c2Luke Smith
14017741ef334485c65013d129608513161db7c2Luke Smith Y.Assert.areSame(3, ids.length, "Delegate handler should have fired three times, once for each div in #div-1");
14017741ef334485c65013d129608513161db7c2Luke Smith Y.Assert.areSame('div-1-2', ids[0], "First delegate callback should be from the highest div in the subtree");
14017741ef334485c65013d129608513161db7c2Luke Smith Y.Assert.areSame('div-1-2-1', ids[1]);
14017741ef334485c65013d129608513161db7c2Luke Smith Y.Assert.areSame('div-1-2-1-1', ids[2]);
14017741ef334485c65013d129608513161db7c2Luke Smith },
14017741ef334485c65013d129608513161db7c2Luke Smith
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith test_removing_parent_in_subscriber: function () {
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith var count = 0;
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith Y.one('#a').delegate('click', function (e) {
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith this.get('parentNode').remove();
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith count++;
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith }, '.remove');
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith Y.Event.simulate(Y.one('#c')._node, 'click');
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith Y.Assert.areSame(2, count);
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith },
fb83a09fe023a741781ee955f4e9538d3cbe21a2Luke Smith
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots test_successful_purge: function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots var bHandler1Called = false,
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = true;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.purgeElement('#mod1');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #1: Make sure first handler is not called after
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // calling Y.Event.purgeElement
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate (document.getElementById('firstlink'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "No delegated listeners should be called after a call to Y.Event.purgeElement");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #2: Make sure second handler is called after
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // calling Y.Event.purgeElement
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = true;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate(document.getElementById('firstlink'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
86f93a1b47c3b420a6d9595af8954ec21fb4e413Adam Moore
86f93a1b47c3b420a6d9595af8954ec21fb4e413Adam Moore bHandler1Called = false;
86f93a1b47c3b420a6d9595af8954ec21fb4e413Adam Moore bHandler2Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #3: Make sure first handler is not called after
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // calling Y.Event.purgeElement and passing in a type
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.purgeElement('#mod1', false, 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate(document.getElementById('firstlink'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler2Called, "The second listener should not be be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #4: Make sure that it is possible to delegate
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // a listener to a new element with the same id of
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // an element that used to exist in the DOM.
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.delegate("click", function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = true;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots }, "#list-1", ">li");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.purgeElement('#list-1');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.one("#container").setContent('<ul id="list-1"><li id="item-1"><em>Item Type One</em></li><li id="item-2"><em>Item Type Two</em></li><li id="item-3"><em>Item Type Three</em></li></ul>');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.delegate("click", function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = true;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots }, "#list-1", ">li");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate(document.getElementById('item-1'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots },
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots test_successful_detach: function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots var bHandler1Called = false,
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots var handle = Y.delegate('click', function(e) {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = true;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots handle.detach();
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #1: Make sure first handler is not called after
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // being detached
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate (document.getElementById('firstlink'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "Listener should not be called after being detached.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #2: Make sure second handler is called after
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // detaching the first.
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots Y.delegate('click', function(e) {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = true;
42a76975bee344dcbf51edcc380b921ef3251fb7Todd Kloots }, '#mod1', 'a');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate(document.getElementById('firstlink'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // Test #3: Make sure that it is possible to delegate
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // a listener to a new element with the same id of
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots // an element that used to exist in the DOM.
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = false;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots handle = Y.delegate("click", function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler1Called = true;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots }, "#list-1", ">li");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots handle.detach();
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.one("#container").setContent('<ul id="list-1"><li id="item-1"><em>Item Type One</em></li><li id="item-2"><em>Item Type Two</em></li><li id="item-3"><em>Item Type Three</em></li></ul>');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.delegate("click", function () {
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots bHandler2Called = true;
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots }, "#list-1", ">li");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Event.simulate(document.getElementById('item-1'), 'click');
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
3215b14029b163463e7225627b6781e4a049f3d8Caridy }
3215b14029b163463e7225627b6781e4a049f3d8Caridy
f8f5d63799c8f2045a569d778b0139cf7672ad82Todd Kloots
3215b14029b163463e7225627b6781e4a049f3d8Caridy /*
3215b14029b163463e7225627b6781e4a049f3d8Caridy * Other things that I consider should be tested in the future:
3215b14029b163463e7225627b6781e4a049f3d8Caridy * - stopping the event, verifying the event ourside of the container
3215b14029b163463e7225627b6781e4a049f3d8Caridy * - stopping the event and verify what happen with multiple matches
3215b14029b163463e7225627b6781e4a049f3d8Caridy */
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy }));
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy //run all tests
3215b14029b163463e7225627b6781e4a049f3d8Caridy Y.Test.Runner.run();
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy /* finishing the testing process */
3215b14029b163463e7225627b6781e4a049f3d8Caridy
3215b14029b163463e7225627b6781e4a049f3d8Caridy });
3215b14029b163463e7225627b6781e4a049f3d8Caridy </script>
3215b14029b163463e7225627b6781e4a049f3d8Caridy</body>
5889c2819167de6bb3c1d1a1e3a5e6af060e8a95Adam Moore</html>