ce.html revision efa57736d44cf446f1661497a8645bd388b493fb
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html debug="true">
<head>
<title>YUI 3.0</title>
<script type="text/javascript" src="/build/yui/yui-debug.js"></script>
<!--
<script type="text/javascript" src="/build/event/event-debug.js"></script>
<script type="text/javascript" src="/build/dump/dump.js"></script>
-->
<body>
<input id="button1" type="button" value="Button 1" class='button' />
<input id="button2" type="button" value="Button 2" class='button' />
<input id="text1" type="text" value="something" class='nothing' />
<script>
YUI({
base: '/build/',
// filter: 'debug',
filter: 'raw',
// throwFail: false,
combine: false
}).use('dump', 'substitute', 'event-custom', function(Y) {
Y.log('instanceof: ' + (Y instanceof YUI));
Y.log('constructor: ' + (Y.constructor == YUI));
Y.on('yui:log', function(e) {
var d=document, b=d.body, n=d.createElement("div");
if (b) {
n.appendChild(d.createTextNode(e.msg));
b.appendChild(n);
}
});
/*
Y.on("mycategory|myevent", function () {
alert("here");
});
Y.fire("myevent");
Y.detach('mycategory|*');
Y.fire("myevent");
*/
/*
Y.on("mycategory|myevent", function () {
alert("here");
});
Y.fire("myevent");
Y.detach('mycategory|myevent');
Y.fire("myevent");
*/
var handler = function () {
alert("here");
};
Y.on("myevent", handler);
Y.fire("myevent");
Y.detach('myevent', handler);
Y.fire("myevent");
/*
EventTarget hasEvent replaced with getEvent
Event.Custom constructor signature is now type and options ---
removed context and silent as arguments in the constructor, now these
must be passed into the config.
Added 'defaultFn' custom event property
Added 'emitFacade' config that publish() can use to use the Event.Facade signature.
This is in place until we can configure EventTarget to always produce events
with the Event.Facade signature.
When the facade in place, if the first argument is an object, these properties are
mixed into the event facade. This provides some transparency to events that are
already being used this way, and makes it so that the consumer can use well known
property names rather than e.details[1]
*/
// o1.addTarget(o3);
var Base = function() {
Y.log('Base constructor executed');
arguments.callee.superclass.constructor.apply(this, arguments);
}
Y.extend(Base, Y.EventTarget, {
base: function() {
Y.log('all your base...');
}
});
var O = function(id) {
this.id = id;
Y.log('O constructor executed ' + id);
}
O.prototype = {
oOo: function(ok) {
Y.log('oOo');
}
}
Y.augment(O, Base, null, null, {
// Y.augment(O, Y.EventTarget, null, null, {
emitFacade: true
});
// augmented class
var o1 = new O('1');
// event target instance or subclass
// var o2 = new Y.EventTarget();
var o2 = new O('2');
// augmented object
var o3 = new Object();
Y.augment(o3, Y.EventTarget, null, null, {
emitFacade: true
});
o1.publish('o:1', {
defaultFn: function() {
Y.log('1 DEFAULT FN');
},
stoppedFn: function() {
Y.log('1 STOPPED');
},
preventedFn: function() {
Y.log('1 PREVENTED');
}
, emitFacade: true
});
o2.publish('o:1', {
defaultFn: function() {
Y.log('2 DEFAULT FN');
}
, emitFacade: true
});
o1.publish('chain', {
defaultFn: function() {
Y.log('DEFAULT FN CHAIN');
}
, emitFacade: true
});
o1.addTarget(o2);
// o2.addTarget(o3);
o1.on('o:1', function(e) {
// Y.log('o1, o:1: ' + Y.Lang.dump(Y.Array(arguments)));
// Y.log('o1, o:1: ');
Y.log('o1, o:1 O1 TARGET: ' + Y.Lang.dump(e.target.id));
// this.fire('chain', 1, 2);
// e.halt();
});
o1.after('o:1', function(e) {
// Y.log('AFTER o1, o:1: ' + Y.Lang.dump(Y.Array(arguments)));
Y.log('AFTER o1, o:1: ');
// e.halt();
});
o1.on('chain', function(e) {
Y.log('o1, chain o1' + Y.Lang.dump(Y.Array(arguments)));
});
o2.on('o:1', function(e) {
// Y.log('o2, o:1 from o1: ' + Y.Lang.dump(Y.Array(arguments)));
Y.log('o2, o:1 from o1, O2 TARGET: ' + e.target.id + ', currentTarget ' + e.currentTarget.id);
//e.halt();
});
o2.on('chain', function(e) {
Y.log('o2, chain from o1: ' + Y.Lang.dump(Y.Array(arguments)));
});
o2.after('o:1', function(e) {
// Y.log('AFTER o1, o:1: ' + Y.Lang.dump(Y.Array(arguments)));
Y.log('AFTER o2, o:1 from o1: ');
// e.halt();
});
o3.on('o:1', function(e) {
Y.log('o1 to o3: ' + Y.Lang.dump(e.target));
});
o3.on('o:2', function(e) {
Y.log('o2 to o3: ' + Y.Lang.dump(Y.Array(arguments)));
});
o1.on('o:1', function(e) {
//broken;
});
// with facade
o1.fire('o:1', {
foo: {
nested_foo: [1,2,3]
},
bar: {
nested_bar: "absorbed from fire arg 0"
}
}, 2, 3);
(o1 && o1['base'] && o1.base());
// without facade
//o1.fire('o:2', 4, 5, 6);
// should throw error
// var ns = YUI.applyTo(Y.id, 'namespace', ['foo.bar']);
// var o = YUI.applyTo('id', 'io.start', [obj, args]);
// should throw error
// var a = YUI.applyTo(Y.id, 'Object.keys', [{
// foo: 1,
// bar: 2
// }]);
// Y.log('keys: ' + a);
o3.on('o:nosubscribe_on_1', function(e) {
Y.log('o1 to o3: NO SUBSCRIBER ON 1' + Y.Lang.dump(e.target));
});
o1.fire('o:nosubscribe_on_1');
Y.on('test:test', function() {
Y.log('test:test: ' + Y.Array(arguments, 0, true));
}, Y, 1, 2);
Y.fire('test:test');
//-------------------
Y.after('handle|test:event2', function() {
Y.log('this after listener for string detach should not have fired');
});
Y.on('handle|test:event2', function() {
Y.log('this on listener for string detach should not have fired');
});
// detachAll
Y.detach('handle|*');
Y.fire('test:event2');
});
</script>
</body>
</html>