node.html revision b4bd98fdbecaafbd2f8e490a5c5be0eb2e6286ce
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
0cf10c63df6e2a8987111847ea456ac9e464f5eeMatt Sweeney<script type="text/javascript" src="/build/yui/yui.js"></script>
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney min-height:200px;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney width:1000px;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney background:#ccc;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney font-size:10px;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney height:10em;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney padding:15px 0;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney width:200px;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney background:#ccc;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney position:absolute;
81d93d38efaf7a1b64cadce31010d3368548483dMatt Sweeney overflow:hidden;
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<div id="test-prop" tabindex="4">text<em id="test-contains">test<span></span></em><strong>node</strong></div>
YUI({base: '/build/', filter: 'raw'}).use('selector-css3', 'anim', 'console', 'test', 'node-event-simulate', function(Y) {
var Assert = Y.Assert,
ArrayAssert = Y.ArrayAssert,
suite = new Y.Test.Suite("yuisuite");
new Y.Console({node: '#yui-log', height: '1000px' }).render('#yui-log');
return document.getElementById(id);
var $ = Y.Selector.query;
name: 'Y.Node Instance',
var node = Y.one('#test-nodes'),
nodes = Y.all('#test-nodes *');
Y.one("a[href$='?t=5']");
Assert.areEqual(byId('test-nodes'), Y.Node.getDOMNode(Y.one('#test-nodes')), 'Y.one("#test-nodes")');
Assert.areEqual(byId('test-nodes'), Y.Node.getDOMNode(Y.one('#test-nodes')), 'Y.one("#test-nodes")');
Assert.areEqual(byId('test-nodes').getElementsByTagName('li')[0],
Assert.areEqual(byId('test-nodes').getElementsByTagName('li')[1],
Assert.areEqual(byId('test-nodes').getElementsByTagName('li')[1],
Assert.areEqual(byId('form.foo@bar:baz'), Y.Node.getDOMNode(Y.one('[id="form.foo@bar:baz"]')), "[id=form.foo@bar:baz]");
var firstChild = Y.one('body :first-child');
Assert.isFalse(firstChild._node === Y.one('body :first-child')._node, "wrong node: Y.one('body :first-child')");
Assert.areEqual(Y.Selector.query('body :first-child', null, true), Y.one('body :first-child')._node, "body :first-child === #test-append");
ArrayAssert.itemsAreEqual($('#test-select option'), Y.NodeList.getDOMNodes(Y.all('#test-select option')), 'Y.one("#test-select option")');
Assert.areEqual(nodes.size(), Y.all('#test-nodes *').size(), 'nodes.size() === Y.all("#test-nodes").size()');
ArrayAssert.itemsAreEqual(Y.Selector.query('div'), Y.all(Y.Selector.query('div'))._nodes, "Y.all(Y.Selector.query('div'))");
//ArrayAssert.itemsAreEqual(document.getElementsByTagName('div'), Y.all(Y.Selector.query('div'))._nodes, "Y.all(Y.Selector.query('div'))");
ArrayAssert.itemsAreEqual(Y.Selector.query('input[name]'), Y.all(Y.Selector.query('input[name]'))._nodes, "Y.all(Y.Selector.query('input[name]'))");
ArrayAssert.itemsAreEqual(Y.Selector.query('.foo'), Y.all(Y.Selector.query('.foo'))._nodes, "Y.all(Y.Selector.query('.foo'))");
"frameDoc.one('#demo li').get('innerHTML')");
Assert.areEqual(byId('test-text-value'),
Y.one('doc').one('.test-class #test-text-value')._node,
"Y.one('doc').one('.test-class #test-text-value')");
nodes = Y.all('#test-nodes *'),
nodes.each(function(node, i, list) {
Assert.areEqual(nodes, list, 'nodes === instance');
Assert.areEqual(node, this, 'this === node');
var nodes = Y.all('#test-nodes *'),
}), 'nodes.some(function() { return true; })');
}), 'nodes.some(function() {})');
node = Y.one('#' + id),
nodes = Y.all('#' + id + ' *');
Assert.areEqual(element.firstChild.nextSibling.nodeName, node.get('firstChild').get('nextSibling').get('nodeName'), 'node.firstChild.nextSibling.nodeName"');
Assert.areEqual(element.lastChild.nodeName, node.get('lastChild').get('nodeName'), 'lastChild.nodeName"');
Assert.areEqual('test-nodes', nodes.get('parentNode').get('id')[0], 'nodes.get(parentNode)[0].get("id") === test-nodes');
Assert.areEqual(element.firstChild.nodeType, node.get('firstChild').get('nodeType'), 'firstChild.get("nodeType")');
Assert.areEqual(element.offsetParent.tagName, node.get('offsetParent').get('tagName'), 'offsetParent.tagName === offsetParent.tagName');
Assert.areEqual('item 1', Y.Lang.trim(nodes.get('children')[0].get('text')[0]), 'nodes.get("children")[0].get("text")[0]');
Assert.areEqual('item 1', Y.Lang.trim(nodes.get('children')[0].get('text')[0]), 'nodes.get("children")[0].get("text")[0]');
textContainer.set('text', 'bar');
ArrayAssert.itemsAreEqual($('#test-select option'),
Assert.areEqual(0, Y.one('#test-empty-children').get('children').size(), "Y.one('#test-empty-children').get('children')");
Assert.areEqual(byId('test-nodes').childNodes.length, node.get('childNodes').size(), 'node.get("childNodes").size()');
Assert.areEqual(byId('test-nodes').childNodes.length, node.get('childNodes').get('tagName').length, 'node.get("childNodes")');
ArrayAssert.itemsAreEqual(byId('test-nodes').childNodes.length, node.get('childNodes').get('length').length, "node.get('childNodes').get('length')");
Assert.areEqual(element.lastChild.nodeName, node.get('lastChild.nodeName'), 'node.get("lastChild.nodeName")');
Assert.areEqual(element.lastChild.previousSibling.nodeName, node.get('lastChild').get('previousSibling').get('nodeName'), 'node.lastChild.previousSibling.nodeName');
Assert.areEqual(byId('test-prop').tabIndex, Y.one('#test-prop').get('tabIndex'), 'Y.one("#test-prop").get("tabIndex")');
Assert.areEqual(byId('doc').tabIndex, Y.one('#doc').get('tabIndex'), 'Y.one("#doc".get("tabIndex"))');
Assert.areEqual(byId('link-1').tabIndex, Y.one('#link-1').get('tabIndex'), 'Y.one("#link1".get("tabIndex"))');
Assert.areEqual(byId('link-2').tabIndex, Y.one('#link-2').get('tabIndex'), 'Y.one("#link1".get("tabIndex"))');
Assert.areEqual(undefined, Y.one('form').get('childNodes')._nodes.item, 'convert live list to static');
Assert.isTrue(Y.all('input').get('parentNode') instanceof Y.NodeList, "Y.all('input').get('parentNode')");
node = Y.one('#' + id);
Assert.areEqual('fresh', node.create('<div id="fresh">fresh</div>').get('id'), 'node.create from string)');
node.appendChild(option);
Assert.isTrue(Y.Node.getDOMNode(option).selected, "Y.Node.create('<option>test</option>').set('selected', 'selected'))");
node = Y.Node.create(html);
node = Y.Node.create(html);
node = Y.Node.create(html);
Assert.areEqual('3', node.get('firstChild').get('nodeType'), "node.get('firstChild').get('nodeType')");
Assert.areEqual('3', Y.Node.getDOMNode(node.get('firstChild')).nodeType, "Y.Node.getDOMNode(node.get('firstChild')).nodeType");
Assert.areEqual(html, node.get('innerHTML').toLowerCase(), "node.setContent(Y.all(Y.Node.create(html)))");
node = Y.one('#' + id),
nodes = Y.all('#test-nodes *');
var childNodes = Y.one('body').get('childNodes');
childNodes.set('title', 'foo bar');
Assert.isTrue(byId('test-nodes').title == 'foo bar', 'Y.one("body").get("childNodes").set("title")');
node.set('foo', 'foo');
node.set('title', 'my title');
nodes.set('className', 'foo');
node.setAttrs(attrMap);
var getAttrs = node.getAttrs(['className', 'title']);
Y.one('#test-select').set('selectedIndex', 2);
"Y.one('#test-select').set('selectedIndex', 2)");
Assert.areEqual(2, byId('test-select').selectedIndex,
var index = Y.one('#test-select').one('option[value=1]').set('selected', true);
"Y.one('#test-select').set('selectedIndex', 1)");
Y.one('#test-select').set('value', 1);
Y.one('#test-select').set('value', 'baz');
Assert.areEqual('baz', Y.one('#test-select').get('value'), "Y.one('#test-select').set('value', 1)");
var node = Y.one('#test-prop');
Assert.areEqual(element.getElementsByTagName('em')[0].nodeName, node.getElementsByTagName('em').item(0).get('nodeName'), 'getElementsByTagName');
var insertNode = document.createElement('div');
Y.stamp(insertNode);
insertNode.innerHTML = 'inserted node';
Assert.isTrue(Y.one('body').get('lastChild').compareTo(Y.one('#test-append')), 'get("body").appendChild(Y.one("#test-append"))');
Assert.areEqual(byId('test-append'), Y.Node.getDOMNode(Y.one('body').get('lastChild')), 'get("body").appendChild(Y.one([0]"#test-append"))');
Assert.areEqual('inserted node', node.appendChild(insertNode).get('innerHTML'), 'appendChild(element input)');
Assert.areEqual('inserted node', node.removeChild(insertNode).get('innerHTML'), 'removeChild(element input)');
Assert.areEqual('inserted node', node.appendChild(Y.one(insertNode)).get('innerHTML'), 'appendChild(Node input)');
Assert.areEqual('inserted node', node.removeChild(Y.one(insertNode)).get('innerHTML'), 'removeChild(Node input)');
var clone = node.cloneNode();
Assert.isTrue(node.get('childNodes').size() === node.cloneNode(true).get('childNodes').size(), 'node.get("childNodes").size() === node.cloneNode(true).get("childNodes").size()');
clone = Y.one('.bar').cloneNode(true);
Y.one('body').appendChild(clone);
clone.set('id', 'new-bar');
Assert.isFalse(node.contains(document.getElementsByTagName('div')), 'contains() false positive for collection');
return el.get('id') === 'doc';
return el.getAttribute('foo') !== '';
Assert.areEqual(byId('test-contains'), Y.Node.getDOMNode(node.getById('test-contains')), 'node.getById("test-contains")');
node.removeAttribute('tabIndex');
Assert.areEqual('0', Y.one('select[name=test-select] option:nth-child(1)').getAttribute('value'), 'option1.getAttribute("value") (from innerText)');
Assert.areEqual('1', Y.one('select[name=test-select] option:nth-child(2)').getAttribute('value'), 'option2.getAttribute("value") (from innerText)');
Assert.areEqual('', Y.one('select[name=test-select] option:nth-child(3)').getAttribute('value'), 'option3.getAttribute("value") (from innerText)');
Assert.areEqual('http://www.yahoo.com/foo', Y.one('#link-1').getAttribute('href'), "Y.one('#link1').getAttribute('href')");
Assert.areEqual('foo.html', Y.one('#link-2').getAttribute('href'), "Y.one('#link1').getAttribute('href')");
var frag = Y.one('document').invoke('createDocumentFragment'),
frag.appendChild(element);
Y.one('body').appendChild(frag);
var node = Y.one(element);
node = Y.one('#test-xy');
node.setXY([100, 100]);
var xy = node.getXY();
var x = Math.round(xy[0]);
var y = Math.round(xy[1]);
ArrayAssert.itemsAreEqual(Y.DOM.region(Y.DOM.byId('doc')), Y.one('#doc').get('region'), 'node.get("region")');
var node = Y.one(element);
Assert.isTrue(node.get('previousSibling').hasClass('test-class'), 'node.get("previousSibling").hasClass("test-class")');
node.addClass('foo');
node.removeClass('foo');
node.addClass('foo');
Y.one('body').get('childNodes').addClass('foo');
node.replaceClass('foo', 'bar');
var nodes = Y.all('#test-nodes li');
nodes.addClass('foo').addClass('bar');
nodes.each(function(n) {
nodes.removeClass('bar');
nodes.each(function(n) {
Y.DOM.addClass(node, 'foo');
Y.DOM.replaceClass('foo', 'foo');
var node = Y.one('#test-class');
node.toggleClass('foo');
node.toggleClass('foo');
node.toggleClass('foo', false);
node.toggleClass('foo');
node.toggleClass('foo', true);
node = Y.one(element),
nodes = node.get('childNodes');
node.setStyle('width', '20em');
node.setStyle('marginTop', '1em');
node.setStyle('opacity', 0.5);
node.setStyle('float', 'left');
node.setStyle('float', 'left');
nodes.setStyle('marginTop', '1em');
var node = Y.one('#get-style');
node.setStyle('opacity', 0.5);
node.setStyle('visibility', 'hidden');
node.setStyle('visibility', 'visible');
var node = Y.one('#test-computed'),
Assert.areEqual(h, Math.ceil(parseFloat(node.getComputedStyle('height'))), "height: auto (offset minus padding and border)");
Assert.areEqual(w, Math.round(parseFloat(node.getComputedStyle('width'))), "percent width (from CSS)");
//Assert.areEqual(window, Y.Node.getDOMNode(Y.one('document').get('defaultView')), 'win.get(document)');
"Y.one('#test-insert-html').setContent(element)");
"node.insert('<strong>bar</strong>', node.one('span')");
"node.insert('<code>var lorem</code>', node.one('em')._node)");
"node.insert(Y.Node.create('<div>foo</div>'))");
Assert.areEqual(Y.one('#test-insert-html')._node.childNodes[2], html, 'node.insert(someDOMNode, 2)');
"Y.one('input[name=test-text-value]').get('value')");
"Y.one('input[name=test-text-novalue]').get('value')");
Assert.areEqual('',
Assert.areEqual('',
Assert.areEqual('',
Assert.areEqual('',
parent = domNode.parentNode;
node.remove();
node = Y.Node.create('<div/>');
node.remove();
var node = Y.one('#test-replace').get('firstChild'),
newNode = document.createElement('div');
node.replace(newNode);
node = Y.one('#test-replace').get('firstChild');
node.replace(newNode);
var elements = Y.one('#test-form').get('elements');
ArrayAssert.itemsAreEqual(Y.DOM.byId('test-form').elements, elements._nodes, "Y.one('#test-form').get('elements')");
var frag = Y.all('#test-frag p').toFrag();
Y.one('body').set('role', 'menu');
Y.one('body').set('aria-checked', true);
Assert.areEqual('true', document.body.getAttribute('aria-checked', 2), "Y.one('body').set('aria-checked', true)")
Assert.areEqual('true', Y.one('body').getAttribute('aria-checked'), "Y.one('body').set('aria-checked', true)")
Y.one('body').set('aria-checked', false);
Assert.areEqual('false', Y.one('body').get('aria-checked'), "Y.one('body').set('aria-checked', false)");
Y.all('input').each(function(n) {
Y.all('input').each(function(n) {
var mask = document.createElement('div');
mask.className = 'mask';
document.body.appendChild(mask);
var doc = Y.one('document');
window.scrollTo(0,0);
Y.DOM.setStyle(mask, 'opacity', 0.4);
mask.className = '';
var node = Y.one('#test-nodes'),
nodelist = node.all('li');
nodelist.item(1).remove();
nodelist = Y.all('#test-nodes li');
nodelist.item(1).remove();
var node = Y.DOM.byId('test:colon');
node = Y.DOM.byId('_funky:id{$400}');
var node = Y.DOM.byId('test:colon');
Y.one(node).all('h2')._nodes,
node = Y.DOM.byId('_funky:id{$400}');
Y.one(node).all('h2')._nodes,
node = Y.one('body');
var parent = Y.one('#test-nodes > ol'),
children = parent.get('children');
children.item(2).siblings()._nodes,
"children.item(2).siblings()"
children.item(2).siblings('li')._nodes,
"children.item(2).siblings('li')"
children.addClass('bar');
children.item(1).removeClass('bar');
var elements = Y.DOM.byId('test-swap').getElementsByTagName('li'),
nodes = Y.all('#test-swap li');
var node = Y.one('body');
node.set('data', 'foo');
"node.set('data', 'foo')");
node.setData('foo', 'foo');
"node.setData('foo', 'foo')");
node.setData({'bar': 'bar', 'baz': 'baz'});
"node.setData({'bar': 'bar', 'baz': 'baz'})");
"node.setData({'bar': 'bar', 'baz': 'baz'})");
node.clearData('bar');
"node.clearData('bar')");
"node.clearData('bar')");
"node.clearData()");
Y.one('head').append(html);
"Y.one('head').append(" + html + ")");
var node = Y.one('#test-table div div').ancestor('td');
Y.Assert.areEqual(byId('test-td'), node._node,
"Y.one('#test-table div').ancestor('td'))");
node = Y.Node.create('<div><div><table><tbody><tr></tr><tr></tr><tr><td><div><div class="inner"></div></div></td></tr></tbody></table></div></div>');
var inner = node.one('.inner');
inner.ancestor('td');
var nodelist = Y.all('div'),
item = nodelist.item(0),
Assert.areEqual('foo', foo, "foo === 'foo'");
Assert.areEqual('bar', bar, "bar === 'bar'");
nodelist.on('click', function(e) {
Assert.areEqual(this, nodelist);
Y.on(evtObj, null, nodelist, null, 'foo', 'bar');
nodelist.on(evtObj, null, null, 'foo', 'bar');
nodelist.on({mouseup: true}, function(e) {
Assert.areEqual(this, nodelist);
nodelist.on({mouseup: function(e) {
Assert.areEqual(this, nodelist);
nodelist.on({keydown: true}, function(e) {
nodelist.on({keydown: true}, function(e) {
nodelist.after('click', function(e) {
Assert.areEqual(this, nodelist);
Y.after(evtObj, null, nodelist, null, 'foo', 'bar');
nodelist.after(evtObj, null, null, 'foo', 'bar');
nodelist.after({mouseup: true}, function(e) {
Assert.areEqual(this, nodelist);
nodelist.after({keydown: true}, function(e) {
item.simulate('mousedown');
item.simulate('click');
item.simulate('mouseup');
item.simulate('keydown');
Y.Test.Runner.add(suite);
Y.on('load', function() {