delegate.html revision 03fb873fb498b91f5def3bb608de5d01374f1e07
0N/A <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>
0N/A Y.delegate('click', function(e) {
0N/A ct = e.currentTarget;
0N/A boundEl = e.container;
0N/A Y.Assert.isTrue(foo, "simple delegation fails, mod1 should pickup the event and test target [firstlink]");
0N/A // Y.Assert.areEqual(t, Y.get('#firstlink'), "event delegate works but the target is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(ct, Y.get('#firstlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(t, Y.get('#firstlink'), "event delegate works but the target is an incorrect node, should be the actual click target");
0N/A Y.Assert.areEqual(boundEl, Y.get('#mod1'), "event delegate works but the container property should be the bound element");
0N/A Y.delegate('click', function(e) {
0N/A ct = e.currentTarget;
0N/A boundEl = e.container;
0N/A Y.Assert.areEqual(ct, Y.get('#mod-header'), "event delegate works but the matched element is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(ct, Y.get('#mod-body'), "event delegate works but the matched element is an incorrect node, should be the matching node");
0N/A Y.delegate('click', function(e) {
0N/A ct = e.currentTarget;
0N/A boundEl = e.container;
0N/A Y.Assert.isTrue(foo, "simple delegation fails, mod1 should pickup the event and test target [firstlink]");
0N/A Y.Assert.areEqual(ct, Y.get('#firstlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(t, Y.get('#firstlink'), "event delegate works but the target is an incorrect node, should be the actual click target");
0N/A Y.Assert.areEqual(boundEl, Y.get('#mod1').get('ownerDocument'), "event delegate works but the container property should be the bound element");
0N/A Y.delegate('click', function(e) {
0N/A ct = e.currentTarget;
0N/A boundEl = e.container;
0N/A Y.Assert.isTrue(foo, "delegation fails for an image within an anchor, mod1 should pickup the event and test target [secondlink]");
0N/A // Y.Assert.areEqual(t, Y.get('#secondlink'), "event delegate works but the target is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(ct, Y.get('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching node");
0N/A Y.Assert.areEqual(t, Y.get('#fakeimage'), "event delegate works but the target is an incorrect node, should be the actual click target");
0N/A Y.Assert.areEqual(boundEl, Y.get('#mod1'), "event delegate works but the container property should be the bound element");
0N/A Y.delegate('click', function(e) {
0N/A Y.Assert.isFalse(foo, "delegation fails, the container (specified in the on) can not be part of the selectors");
0N/A Y.delegate('click', function(e) {
0N/A Y.Assert.isFalse(foo, "delegation fails, delegation without at least one selector should never trigger an event");
0N/A Y.delegate('click', function(e) {
0N/A Y.Assert.isTrue(foo, "multiple selectors fails, delegate should be able to match different selectors");
0N/A Y.Assert.areEqual(t, Y.get('#firstlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
0N/A Y.delegate('click', function(e) {
0N/A ct1 = e.currentTarget;
0N/A Y.delegate('click', function(e) {
0N/A ct2 = e.currentTarget;
0N/A Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
0N/A Y.Assert.isTrue(foo2, "second match fail, delegate should be able to match [a span]");
0N/A Y.Assert.areEqual(ct1, Y.get('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching selector");
0N/A Y.Assert.areEqual(t1, Y.get('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the clicked node");
0N/A Y.Assert.areEqual(ct2, Y.get('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
0N/A Y.Assert.areEqual(t2, Y.get('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the clicked");
0N/A Y.delegate('click', function(e) {
0N/A ct = e.currentTarget;
0N/A Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
0N/A Y.Assert.isTrue(foo2, "second match fail, the event doesn't bubble up after the delegate routine");
0N/A // Y.Assert.areEqual(t1, Y.get('#secondlink'), "event delegate works but the target is an incorrect node, should be the matching selector");
0N/A Y.Assert.areEqual(ct, Y.get('#secondlink'), "event delegate works but the currentTarget is an incorrect node, should be the matching selector");
0N/A Y.Assert.areEqual(t1, Y.get('#spanwithinlink'), "event delegate works but the target is an incorrect node, should be the actual target");
0N/A Y.Assert.areEqual(t2, Y.get('#spanwithinlink'), "event delegate works but it doesn't restore e.target to the original value.");
0N/A Y.delegate('click', function(e) {
0N/A Y.Assert.isTrue(foo1, "first match fail, delegate should be able to match [a]");
0N/A Y.Assert.isFalse(foo2, "the listener for 'doc' got executed, which means that e.halt fails during the delegate routine");
0N/A Y.Assert.areEqual('list-2-li-3', matchID, "The currentTarget is an incorrect node, should be the matching node.");
0N/A Y.Assert.areEqual('div-1-1', matchID, "The currentTarget is an incorrect node, should be the matching node.");
0N/A Y.Assert.isNull(matchID, "The currentTarget is an incorrect node, should be the matching node.");
0N/A Y.delegate('click', function(e) {
0N/A Y.Event.purgeElement('#mod1');
0N/A // calling Y.Event.purgeElement
0N/A Y.Assert.isFalse(bHandler1Called, "No delegated listeners should be called after a call to Y.Event.purgeElement");
// calling Y.Event.purgeElement
Y.delegate('click', function(e) {
Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
// calling Y.Event.purgeElement and passing in a type
Y.Event.purgeElement('#mod1', false, 'click');
Y.Assert.isFalse(bHandler2Called, "The second listener should not be be called.");
Y.delegate("click", function () {
Y.Event.purgeElement('#list-1');
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>');
Y.delegate("click", function () {
Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
var handle = Y.delegate('click', function(e) {
Y.Assert.isFalse(bHandler1Called, "Listener should not be called after being detached.");
Y.delegate('click', function(e) {
Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");
handle = Y.delegate("click", function () {
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>');
Y.delegate("click", function () {
Y.Assert.isFalse(bHandler1Called, "The first listener should not be be called.");
Y.Assert.isTrue(bHandler2Called, "The second delegated listener should be called.");