Permalink
Browse files

Merging changes in from master

  • Loading branch information...
2 parents 8b5a56b + 3a293f6 commit 18c11da98e1daddf61897347431766877c880b4b @davglass committed Jan 6, 2011
Showing with 81 additions and 49 deletions.
  1. +46 −0 lib/yui3-dom-after.js
  2. +22 −14 lib/yui3-dom.js
  3. +1 −1 tests/dom.js
  4. +12 −33 tests/node.js
  5. +0 −1 tests/selector.js
View
@@ -0,0 +1,46 @@
+/**
+* Module contains overrides for Y.DOM.
+* @module nodejs-dom-after
+*/
+YUI.add('nodejs-dom-after', function(Y) {
+ Y.DOM.VALUE_GETTERS.button = function(node) {
+ return node.getAttribute('value');
+ }
+ Y.DOM.VALUE_GETTERS.option = function(opt) {
+ var val = opt.getAttribute('value');
+ if (!opt.hasAttribute('value')) {
+ val = opt.innerHTML;
+ }
+ return val;
+ }
+ Y.DOM.VALUE_GETTERS.select = function(node) {
+ var si = node.selectedIndex;
+ if (!node.options[si]) {
+ si = 0;
+ }
+ var opt = node.options[si];
+ var val;
+ if (opt) {
+ val = opt.getAttribute('value');
+ if (!opt.hasAttribute('value')) {
+ val = opt.innerHTML;
+ }
+ }
+ return val;
+ }
+
+ Y.DOM.VALUE_SETTERS.select = function(node, val) {
+ for (var i = 0, options = node.getElementsByTagName('option'), option;
+ option = options[i++];) {
+ if (Y.DOM.getValue(option) === val) {
+ option.selected = true;
+ break;
+ }
+ }
+ }
+
+ Y.Selector.useNative = false;
+ Y.Selector._nativeQuery = Y.Selector._bruteQuery;
+
+}, 'NODE' );
+
View
@@ -4,37 +4,45 @@
*/
YUI.add('nodejs-dom', function(Y) {
var jsdom = null,
- parser = null,
- browser, dom;
+ browser = {}, dom;
if (!YUI._jsdom) {
YUI._jsdom = YUI.require('jsdom');
}
- //Cache the htmlparser require.
- if (!YUI._htmlparser) {
- YUI._htmlparser = YUI.require('htmlparser');
- }
jsdom = YUI._jsdom;
- parser = YUI._htmlparser;
-
dom = jsdom.defaultLevel;
- if (!dom.Element.prototype.blur) {
- dom.Element.prototype.blur = function() {};
- dom.Element.prototype.focus = function() {};
+ dom.Element.prototype.blur = function() {};
+ dom.Element.prototype.focus = function() {};
+
+ var features = {
+ FetchExternalResources: [],
+ ProcessExternalResources : false
}
+ browser.window = jsdom.jsdom('', null, {features: features}).createWindow();
+ browser.document = browser.window.document;
+ browser.document.getElementsByTagName('head').item(0).appendChild(browser.document.createElement('title'));
- browser = jsdom.windowAugmentation(dom, {
- parser: parser
- });
+ browser.document.scrollTop = browser.document.documentElement.scrollTop = browser.document.body.scrollTop = 0;
+ browser.document.scrollLeft = browser.document.documentElement.scrollLeft = browser.document.body.scrollLeft = 0;
+
browser.window.eval = eval;
+ browser.self = browser.window;
+ browser.navigator = browser.window.navigator;
+ browser.location = browser.window.navigator;
+
+
if (Y.config.UA) {
browser.window.navigator.userAgent = Y.config.UA;
}
+ browser.window.focus = function() {};
+ browser.window.blur = function() {};
+ browser.window.scrollTo = function() {};
+
Y.config.doc = browser.window.document;
Y.config.win = browser.window;
View
@@ -13,7 +13,7 @@ YUI({
logExclude: {
'attribute': true,
'base': true,
- 'get': true,
+ //'get': true,
'loader': true,
'yui': true,
'widget': true,
View
@@ -13,7 +13,7 @@ YUI({
logExclude: {
'attribute': true,
'base': true,
- 'get': true,
+ //'get': true,
'loader': true,
'yui': true,
'widget': true,
@@ -62,9 +62,9 @@ var window = Y.config.win;
Assert.areEqual(byId('test-nodes'), Y.Node.getDOMNode(Y.one('#test-nodes')), 'Y.one("#test-nodes")');
Assert.areEqual('test-nodes', Y.one('#test-nodes').get('id'), 'Y.one("#test-nodes").get("id")');
Assert.areEqual(node, Y.one('#test-nodes'), 'node === Y.one("#test-nodes")');
-
+
Assert.areEqual(byId('test-nodes').getElementsByTagName('li')[0],
- Y.Node.getDOMNode(Y.one('#test-nodes li:first-child')), 'Y.one("#test-nodes")');
+ Y.Node.getDOMNode(Y.one('#test-nodes li:first-child')), 'Y.one("#test-nodes li:first-child")');
Assert.areEqual(byId('test-nodes').getElementsByTagName('li')[1],
Y.Node.getDOMNode(Y.one('#test-nodes li:nth-child(2)')), 'Y.one("#test-nodes:nth-child(2)")');
@@ -98,10 +98,12 @@ var window = Y.config.win;
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'))");
-
+
+ /*
var frameDoc = Y.one('iframe').get('contentWindow.document');
Assert.areEqual('iframe foo', Y.Lang.trim(frameDoc.one('#demo li').get('innerHTML')),
"frameDoc.one('#demo li').get('innerHTML')");
+ */
ArrayAssert.itemsAreEqual([document.body], Y.all(document.body)._nodes, "Y.all(document.body)");
Assert.areSame(Y.one('doc'), Y.one('doc'), "Y.one('doc') === Y.one('doc')");
@@ -309,7 +311,7 @@ var window = Y.config.win;
Y.one('#test-select').set('value', 1);
Assert.areEqual(1, Y.one('#test-select').get('value'), "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)");
+ Assert.areEqual('baz', Y.one('#test-select').get('value'), "Y.one('#test-select').set('value', 'baz')");
},
test_dom_methods: function() {
@@ -341,6 +343,8 @@ var window = Y.config.win;
Assert.areEqual(1, clone.get('nodeType'), 'cloneNode()');
// TODO: test deep clone with bound descendant
+ console.log(node.get('outerHTML'));
+ console.log(node.cloneNode(true).get('outerHTML'));
Assert.isTrue(node.get('childNodes').size() === node.cloneNode(true).get('childNodes').size(), 'node.get("childNodes").size() === node.cloneNode(true).get("childNodes").size()');
Assert.isTrue(Y.one('.bar').test('.bar'), "Y.one('.bar').test('.bar')");
@@ -420,7 +424,8 @@ var window = Y.config.win;
Assert.areEqual(element, Y.Node.getDOMNode(frag.get('firstChild')), 'frag.appendChild()');
Y.one('body').appendChild(frag);
},
-
+
+ /*
test_screen: function() {
var id = 'test-prop';
var element = byId(id);
@@ -438,7 +443,6 @@ var window = Y.config.win;
var y = Math.round(xy[1]);
ArrayAssert.itemsAreEqual([100, 100], [x, y], 'Node.getXY("foo", "bar")');
},
- /*
test_region: function() {
Assert.isTrue(Y.DOM.inRegion(byId('baz'), byId('doc')), 'DOM.inRegion(domNode, domNode)');
Assert.isTrue(Y.one('#get-style').inRegion(byId('doc')), 'node.inRegion(domNode)');
@@ -614,31 +618,6 @@ var window = Y.config.win;
Assert.isNotNull(Y.one('body').get('winHeight'), 'body.get("winHeight")');
},
- test_scroll: function() {
- Y.one('#test-scroll').set('scrollTop', 100);
- Y.one('#test-scroll').set('scrollLeft', 200);
- Assert.areEqual(100, byId('test-scroll').scrollTop, 'test-scroll.set("scrollTop", 100)');
- Assert.areEqual(200, byId('test-scroll').scrollLeft, 'test-scroll.set("scrollLeft", 200)');
- document.body.style.height = '5000px';
- document.body.style.width = '5000px';
-/*
- Y.one(window).set('scrollTop', 100);
- Y.one(window).set('scrollLeft', 200);
- Assert.areEqual(100, Y.DOM.docScrollY(window), 'window.set("scrollTop", 100)');
- Assert.areEqual(200, Y.DOM.docScrollX(window), 'window.set("scrollLeft", 200)');
-*/
-
- Y.one(document).set('scrollTop', 200);
- Y.one(document).set('scrollLeft', 100);
- Assert.areEqual(200, Y.DOM.docScrollY(document), 'document.set("scrollTop", 200)');
- Assert.areEqual(100, Y.DOM.docScrollX(document), 'document.set("scrollLeft", 100)');
-
- document.body.style.height = '';
- document.body.style.width = '';
-
- window.scrollTo(0, 0);
- },
-
test_setContent: function() {
var content = '<strong>foo</strong>';
Y.one('#test-insert-html').setContent(content);
@@ -758,7 +737,7 @@ var window = Y.config.win;
//console.log(node._node.outerHTML);
node.insert('<strong>baz</strong>', node.one('span'));
- console.log(node._node.outerHTML);
+ //console.log(node._node.outerHTML);
Assert.areEqual('STRONG', node._node.childNodes[1].tagName,
"node.insert('<strong>baz</strong>', node.one('span')");
View
@@ -446,7 +446,6 @@ var runTests = function() {
paraChildren.push(el);
}
});
-
ArrayAssert.itemsAreEqual(paraChildren, $('> p', Y.DOM.byId('demo')), '#demo > p');
ArrayAssert.itemsAreEqual($('#demo > p'), $('foo, > p', Y.DOM.byId('demo')), '#demo foo, #demo > p');

0 comments on commit 18c11da

Please sign in to comment.