customevent.html revision 80d2034f65b9348e5fd36291f03b0819181efb89
0N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
0N/A<html>
0N/A<head>
0N/A<title>YUI Event Tests</title>
407N/A</head>
0N/A
0N/A<body class="yui-skin-sam">
0N/A<h1>Event Tests</h1>
0N/A<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>
0N/A
0N/A<script type="text/javascript" src="/build/yui/yui.js"></script>
0N/A<script type="text/javascript">
0N/A
0N/A(function() {
0N/A YUI({
0N/A base: "/build/",
0N/A filter: "debug",
0N/A useConsole: true
0N/A }).use("dump", "test", "console", "event-custom", function(Y) {
0N/A
0N/A var button = Y.get('#btnRun');
0N/A
0N/A // Set up the page
0N/A button.set("disabled", false);
0N/A Y.on("click", function() {
392N/A Y.Test.Runner.run();
392N/A }, button);
392N/A
392N/A var myConsole = new Y.Console().render();
392N/A
392N/A var testEventTarget = new Y.Test.Case({
392N/A name: "Event.Target tests",
392N/A
392N/A testAugment: function() {
392N/A
392N/A var fired = false;
271N/A
89N/A var O = function(id) {
0N/A this.id = id;
0N/A Y.log('O constructor executed ' + id);
0N/A }
0N/A
0N/A O.prototype = {
0N/A oOo: function(ok) {
0N/A Y.log('oOo');
0N/A }
225N/A }
225N/A
0N/A // pass configuration info into Event.Target with the following
456N/A // construct
456N/A Y.augment(O, Y.Event.Target, null, null, {
0N/A emitFacade: true
0N/A });
0N/A
0N/A var o = new O();
202N/A o.on('testAugment', function(e, arg1, arg2) {
202N/A Y.Assert.isTrue(this instanceof O);
972N/A Y.Assert.isTrue(e instanceof Y.Event.Facade);
972N/A Y.Assert.isTrue(e.foo === 'afoo');
972N/A Y.Assert.isTrue(e.details[1] === 1);
0N/A Y.Assert.isTrue(arg1 === 1);
0N/A Y.Assert.isTrue(arg2 === 2);
508N/A fired = true;
889N/A });
889N/A
889N/A o.fire('testAugment', { foo: 'afoo' }, 1, 2);
889N/A
889N/A Y.Assert.isTrue(fired);
889N/A },
889N/A
889N/A testExtend: function() {
889N/A
889N/A var fired = false;
889N/A
889N/A var Base = function() {
889N/A Y.log('Base constructor executed');
889N/A arguments.callee.superclass.constructor.apply(this, arguments);
889N/A }
889N/A
889N/A Y.extend(Base, Y.Event.Target, {
889N/A base: function() {
0N/A Y.log('all your base...');
0N/A }
0N/A });
972N/A
972N/A var b = new Base();
972N/A b.on('testExtend', function(arg1, arg2) {
972N/A Y.Assert.isTrue(this instanceof Base);
972N/A Y.Assert.isTrue(arg1 === 1);
0N/A Y.Assert.isTrue(arg2 === 2);
0N/A fired = true;
0N/A });
0N/A
0N/A b.fire('testExtend', 1, 2);
0N/A
0N/A Y.Assert.isTrue(fired);
972N/A },
271N/A
972N/A testPrefix: function() {
972N/A
972N/A var fired1 = false,
0N/A fired2 = false;
0N/A
0N/A var O = function(id) {
0N/A this.id = id;
0N/A Y.log('O constructor executed ' + id);
0N/A }
89N/A
0N/A O.prototype = {
921N/A oOo: function(ok) {
972N/A Y.log('oOo');
271N/A }
972N/A }
972N/A
972N/A // pass configuration info into Event.Target with the following
0N/A // construct
89N/A Y.augment(O, Y.Event.Target, null, null, {
emitFacade: true,
prefix: 'prefix'
});
var o = new O();
o.on('testPrefix', function(e, arg1, arg2) {
Y.Assert.isTrue(this instanceof O);
fired1 = true;
});
o.on('prefix:testPrefix', function(e, arg1, arg2) {
Y.Assert.isTrue(this instanceof O);
fired2 = true;
});
o.fire('testPrefix', { foo: 'afoo' }, 1, 2);
Y.Assert.isTrue(fired1);
// Y.Assert.isTrue(fired2);
fired1 = false;
fired2 = false;
o.fire('prefix:testPrefix', { foo: 'afoo' }, 1, 2);
Y.Assert.isTrue(fired1);
Y.Assert.isTrue(fired2);
}
});
Y.Test.Runner.add(testEventTarget);
Y.Test.Runner.run();
});
})();
</script>
</body>
</html>