customevent.html revision 0d1c0eaa8a51a181149d802dacbe840f9990e7f5
4115N/A // Y.Global.on('yui:log', function(e) {
3952N/A button.set("disabled", false);
3952N/A var testEventTarget = new Y.Test.Case({
3952N/A O.prototype = {
4305N/A Y.Assert.isTrue(this instanceof O);
3952N/A Y.Assert.isTrue(arg1 === 1);
3952N/A Y.Assert.isTrue(arg2 === 2);
3952N/A Y.Assert.isTrue(fired);
3952N/A Y.Assert.areEqual(1, arg1);
3952N/A Y.Assert.areEqual(2, arg2);
3952N/A arguments.callee.superclass.constructor.apply(this, arguments);
4305N/A Y.Assert.isTrue(this instanceof Base);
3952N/A Y.Assert.isTrue(arg1 === 1);
3952N/A Y.Assert.isTrue(arg2 === 2);
3952N/A Y.Assert.isTrue(fired);
3952N/A O.prototype = {
3952N/A Y.Assert.isTrue(this instanceof O);
3952N/A Y.Assert.isTrue(this instanceof O);
3952N/A Y.Assert.isTrue(fired1);
3952N/A // Y.Assert.isTrue(fired2);
3952N/A Y.Assert.isTrue(fired1);
3952N/A Y.Assert.isTrue(fired2);
3952N/A Y.Assert.isTrue(fired1);
3952N/A Y.Assert.isFalse(fired2);
3952N/A Y.Assert.isFalse(fired1);
3952N/A Y.Assert.isTrue(fired2);
3952N/A Y.Assert.areEqual('orange', arg1);
4305N/A Y.Assert.isTrue(fired1);
3952N/A Y.Assert.areEqual('orange', arg1);
3952N/A Y.Assert.isFalse(fired2);
3952N/A Y.Assert.areEqual(Y, ret);
3952N/A Y.Assert.isFalse(fired1);
3952N/A Y.Assert.isFalse(fired2);
3952N/A Y.Assert.isFalse(fired1, 'fired1, the after listener should not have fired.');
3952N/A Y.Assert.isFalse(fired2, 'fired2, the on listener should not have fired.');
3952N/A Y.Assert.isTrue(fired2);
3952N/A Y.Assert.isFalse(fired1);
3952N/A var o = new Y2.EventTarget({
3952N/A // Y2.after('p:e', f1).on('p:e', f2).on('p:e2', f3).on('detach, p:e', f4).detach('detach, p:e').fire('p:e').fire('p:e2');
3952N/Ao.after('e', f1).on('foo:e', f2).on('foo:e2', f3).on('detach, e', f4).detach('detach,e').fire('foo:e').fire('e2').on('pre:e', f5).fire('pre:e');
3952N/A Y.Assert.isTrue(fired1); // verifies chaining, on/after order, and adding the event target prefix
3952N/A Y.Assert.isTrue(fired2); // verifies chaining, on/after order, and accepting the prefix in the event name
3952N/A Y.Assert.isTrue(fired3); // verifies no interaction between events, and prefix manipulation
3952N/A Y.Assert.isFalse(fired4); // verifies detach works (regardless of spaces after comma)
3952N/A Y.Assert.isTrue(fired5); // verifies custom prefix
3952N/A Y.Assert.isTrue(f1);
3952N/A Y.Assert.isTrue(f2);
3952N/A a = new Y.EventTarget(config),
3952N/A b = new Y.EventTarget(config);
3952N/A b.addTarget(a);
3952N/A Y.Assert.areEqual(1, count);
3952N/A Y.Assert.isTrue(ret);
3952N/A Y.Assert.areEqual(1, count);
3952N/A Y.Assert.isFalse(ret);
4305N/A Y.Assert.isTrue(this instanceof YUI);
3952N/A Y.Assert.areEqual(1, count);
3952N/A Y.Assert.areEqual(1, count);
3952N/A var o = new Y.EventTarget();
3952N/A Y.Assert.areEqual(0, count);
3952N/A Y.Assert.areEqual(1, count);
3952N/A var o = new Y.EventTarget(), s1, s2, s3, s4;
3952N/A Y.Global.on('y:foo2', function() {
3952N/A Y.Assert.areEqual(1, s1);
3952N/A Y.Assert.areNotEqual(1, s2);
3952N/A Y.Global.on('y:bar', function() {
3952N/A Y.Assert.areEqual(1, s3);
3952N/A Y.Assert.areEqual(1, s4);
3952N/A Y.Global.on('y:bar', function(e) {
4115N/A Y.Assert.areEqual('foo', arg1, 'arg1 not correct for lazy fireOnce listener')
3952N/A Y.Assert.areEqual('bar', arg2, 'arg2 not correct for lazy fireOnce listener')
3952N/A Y.Assert.areEqual(1, notified, 'listener notified more than once.');
3952N/A Y.Assert.isFalse(global_notified, 'notification was not asynchronous');
3952N/A Y.Assert.isTrue(global_notified, 'asynchronous notification did not seem to work.');
3952N/A node.publish('foo1', {
3952N/A Y.Assert.areEqual('foo1', e._type);
3952N/A Y.Assert.areEqual(1, preventCount);
3952N/A Y.Assert.areEqual(2, heard);
3952N/A leaf = new Y.EventTarget(config),
3952N/A branch = new Y.EventTarget(config),
3952N/A root = new Y.EventTarget(config);
3952N/A branch.name = 'branch';
3952N/A leaf.addTarget(branch);
3952N/A branch.addTarget(root);
3952N/A leaf.publish('test:foo', { defaultFn: fn});
3952N/A branch.publish('test:foo', { defaultFn: fn});
3952N/A root.publish('test:foo', { defaultFn: fn});
3952N/A root.after('test:foo', function() {
3952N/A Y.Assert.areEqual('root', called, 'root.after should be executed after the root default function');
3952N/A branch.after('test:foo', function() {
3952N/A Y.Assert.areEqual('branch', called, 'branch.after should be executed after the branch default function');
3952N/A leaf.after('test:foo', function(e) {
4305N/A Y.Assert.areEqual('leaf', called, 'leaf.after should be executed after the leaf default function');
3952N/A Y.Assert.areEqual(6, count);
3952N/A // BUBBLE, DEFAULT BEHAVIOR (unless configured to only execute the default function on the target)
3952N/A // SRC, DEFAULT BEHAVIOR (unless configured to only execute the default function on the target)
3952N/A leaf = new Y.EventTarget(config),
3952N/A branch = new Y.EventTarget(config),
4305N/A root = new Y.EventTarget(config);
3952N/A branch.name = 'branch';
4305N/A leaf.addTarget(branch);
4115N/A branch.addTarget(root);
3952N/A leaf.publish('test:foo', { defaultFn: fn});
3952N/A branch.publish('test:foo', { defaultFn: fn});
3952N/A root.publish('test:foo', { defaultFn: fn});
3952N/A leaf.after('test:foo', function(e) {
3952N/A // Y.Assert.areEqual('root', called, 'leaf.after should be executed after the root default function');
3952N/A Y.Assert.areEqual('leaf', called, 'leaf.after should be executed after the root default function');
3952N/A branch.after('test:foo', function() {
3952N/A // Y.Assert.areEqual('root', called, 'leaf.after should be executed after the root default function');
3952N/A Y.Assert.areEqual('leaf', called, 'leaf.after should be executed after the root default function');
3952N/A root.after('test:foo', function() {
3952N/A // Y.Assert.areEqual('root', called, 'leaf.after should be executed after the root default function');
3952N/A Y.Assert.areEqual('leaf', called, 'leaf.after should be executed after the root default function');
4115N/A Y.Assert.areEqual(6, count, 'total subscriber count');
3952N/A z = new Y.EventTarget(config),
3952N/A a = new Y.EventTarget(config),
3952N/A b = new Y.EventTarget(config);
3952N/A b.addTarget(a);
3952N/A a.addTarget(z);
3952N/A Y.Assert.areEqual(1, count);
3952N/A Y.Assert.isTrue(ret);
3952N/A Y.Assert.areEqual(2, count);
3952N/A Y.Assert.isTrue(ret);
3952N/A Y.Assert.areEqual(3, count);
3952N/A Y.Assert.isTrue(ret);
3952N/A z = new Y.EventTarget(config),
3952N/A a = new Y.EventTarget(config),
3952N/A b = new Y.EventTarget(config);
3952N/A b.addTarget(a);
3952N/A a.addTarget(z);
3952N/A // e.preventDefault();
3952N/A Y.Assert.areEqual(0, count);
3952N/A Y.Assert.areEqual(1, count);
4305N/A Y.Assert.areEqual(1, count);
4305N/A Y.Test.Runner.add(testEventTarget);