dom.html revision f699a6a8ba96e55770b2434f4b2299c8d1a83b32
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2390f77db0b974f19412b6ee655c3983bfcaa812Satyen Desai<script type="text/javascript" src="/build/yui/yui-debug.js"></script>
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<script type="text/javascript" src="/build/oop/oop-debug.js"></script>
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<script type="text/javascript" src="/build/event-custom/event-custom.js"></script>
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<script type="text/javascript" src="/build/event/event-debug.js"></script>
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<script type="text/javascript" src="/build/event-simulate/event-simulate.js"></script>
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<script type="text/javascript" src="/build/dom/dom.js"></script>
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<script type="text/javascript" src="/build/node/node.js"></script>
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<script type="text/javascript" src="/build/dump/dump.js"></script>
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<script type="text/javascript" src="/build/substitute/substitute.js"></script>
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<input id="button1" type="button" value="Button 1" class="button" />
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<input id="button2" type="button" value="Button 2" class="button" />
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly<input id="text1" type="text" value="something" class="nothing" />
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnellyif (typeof loadFirebugConsole == 'function') {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly loadFirebugConsole();
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly}).use('node', 'dump', 'substitute', function(Y) {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.on('load', function(e) {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.log('window load event');
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly // alert('starting JS');
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.on('event:ready', function() {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.log('event:ready SUBSCRIBER');
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.on('domready', function() {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.log('domready SUBSCRIBER');
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly Y.on('click', function(e, arg1, arg2) {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly this.setStyle('background-color', 'red');
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly Y.log('document click' + this);
d3ac39f387c773c28001a1323aa85082051965aemattsnider }, document);
3f8c8f56d68f749e363b10328b2a5c97a5c96863Jenny Donnelly // Y.on('yui:log', function(msg) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider // var d=document, b=d.body, n=d.createElement("div");
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('event:ready', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("onDOMReady fired");
d3ac39f387c773c28001a1323aa85082051965aemattsnider document.getElementById('form1').addEventListener('focus',
d3ac39f387c773c28001a1323aa85082051965aemattsnider function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('bubble phase focus');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('focus', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("focus fired");
d3ac39f387c773c28001a1323aa85082051965aemattsnider }, '#form1');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('blur', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("blur fired");
d3ac39f387c773c28001a1323aa85082051965aemattsnider }, '#form1');
d3ac39f387c773c28001a1323aa85082051965aemattsnider document.getElementById('text1').addEventListener('focus',
d3ac39f387c773c28001a1323aa85082051965aemattsnider function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('capture phase focus');
d3ac39f387c773c28001a1323aa85082051965aemattsnider var el = Y.get('#button1');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("get got " + el);
d3ac39f387c773c28001a1323aa85082051965aemattsnider el.setStyle('border', '3px solid red');
d3ac39f387c773c28001a1323aa85082051965aemattsnider var f = function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("SUB1, " + this.get('id') + " click event facade: " + e.target);
d3ac39f387c773c28001a1323aa85082051965aemattsnider var h =Y.on('click', f, el);
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('click', function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("SUB2, " + this.get('id') + " click event facade: " + e.target);
d3ac39f387c773c28001a1323aa85082051965aemattsnider // Y.detach('click', f, el);
d3ac39f387c773c28001a1323aa85082051965aemattsnider var ret = Y.on('click', function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log(this.get('id') + " click event facade: " + e.target);
d3ac39f387c773c28001a1323aa85082051965aemattsnider }, '#button2');
d3ac39f387c773c28001a1323aa85082051965aemattsnider var buts = Y.Node.all('.button');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('queryAll buttons: ' + Y.Lang.dump(buts.get('length')));
d3ac39f387c773c28001a1323aa85082051965aemattsnider buts.each(function(v, k) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('blah: ' + v);
3f8c8f56d68f749e363b10328b2a5c97a5c96863Jenny Donnelly Y.each(buts, function(v, k) {
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly Y.log('blah2: ' + v);
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('mouseover', function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider // alert('asdf');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log(this.id || this.get('id') + " mouseover: " + e.target);
d3ac39f387c773c28001a1323aa85082051965aemattsnider // }, Y.Node.queryAll('.button'));
d3ac39f387c773c28001a1323aa85082051965aemattsnider //}, Y.Selector.query('.button'));
d3ac39f387c773c28001a1323aa85082051965aemattsnider }, ['#button1', '#button2']);
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.on('TEST:EVENT', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('test event subscriber success: ' + Y.Array(arguments));
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.fire('TEST:EVENT', 1, 2);
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.fire('asdf:asdf', 1);
d3ac39f387c773c28001a1323aa85082051965aemattsnider var obj = new Y.Event.Target();
d3ac39f387c773c28001a1323aa85082051965aemattsnider // test failure
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly obj.subscribe('foo', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.info(notdefined);
d3ac39f387c773c28001a1323aa85082051965aemattsnider obj.subscribe('foo', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.info(notdefined);
d3ac39f387c773c28001a1323aa85082051965aemattsnider obj.subscribe('foo', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.info('foo fired anyway!');
d3ac39f387c773c28001a1323aa85082051965aemattsnider } catch(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.warn('fire() error: ' + Y.Lang.dump(e.errors));
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly //alert('asdf');
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly //alert(window.hasOwnProperty('document'));
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly //alert(Y.object.owns(window, 'blah'));
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnellyfunction handleClick(){
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnellyvar body = Y.Node.get("body");
b9436848b51ee2b4f04b9217e74172c5a05ce276Jenny Han Donnellyhandle = body.on("click", handleClick);
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly//click to confirm it's attached
d3ac39f387c773c28001a1323aa85082051965aemattsnider// body.detach("click", handleClick);
d3ac39f387c773c28001a1323aa85082051965aemattsnider//click again, will still show the alert
d3ac39f387c773c28001a1323aa85082051965aemattsnider// for (var i in window) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider//A function that pops up a "Hello World" alert:
d3ac39f387c773c28001a1323aa85082051965aemattsnidervar helloWorld = function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("helloWorld function firing.", "info", "example");
d3ac39f387c773c28001a1323aa85082051965aemattsnider alert("Hello World!");
d3ac39f387c773c28001a1323aa85082051965aemattsnider//subscribe the helloWorld function as an event
d3ac39f387c773c28001a1323aa85082051965aemattsnider//handler for the click event on the container
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han DonnellyY.on("click", helloWorld, "#container");
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly//A function that pops up an alert and
d3ac39f387c773c28001a1323aa85082051965aemattsnider//prevents the default behavior of the event
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly//for which it is a handler:
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnellyvar interceptLink = function(e) {
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly alert('asdf');
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log("You clicked on the second YUI link.", "info", "example");
d3ac39f387c773c28001a1323aa85082051965aemattsnider alert("You clicked on the second YUI link. Because *preventDefault* was called, this link will not navigate away from the page.");
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly//subscribe our interceptLink function
d3ac39f387c773c28001a1323aa85082051965aemattsnider//as a click handler for the second anchor
d3ac39f387c773c28001a1323aa85082051965aemattsniderY.on("click", interceptLink, "#secondA");
d3ac39f387c773c28001a1323aa85082051965aemattsnider// Y.Event.onAvailable("#secondA", function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider// Y.log('#secondA is READY');
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han DonnellyY.on('available', function() {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('#secondA is READY');
d3ac39f387c773c28001a1323aa85082051965aemattsnider}, '#secondA', Y, 1, 2);
d3ac39f387c773c28001a1323aa85082051965aemattsnider//log message to indicate that the example is ready:
d3ac39f387c773c28001a1323aa85082051965aemattsniderY.log("When you begin interacting with the example at left, you'll see log messages appear here.", "info", "example");
d3ac39f387c773c28001a1323aa85082051965aemattsniderY.on('windowresize', function(e) {
d3ac39f387c773c28001a1323aa85082051965aemattsnider Y.log('window resize');
0d6d1a2d994933a68a100ec3dcdc7c7a0eeeae6cJenny Han Donnelly<a href="http://developer.yahoo.com/yui" id="firstA">The YUI Library. (Link navigates away from page.)</a>
<a href="http://developer.yahoo.com/yui" id="secondA">The YUI Library. (Link's default behavior is suppressed.)</a>