Skip to content

Commit

Permalink
Merge branch 'destroy-all' of git://github.com/lsmith/yui3 into lsmit…
Browse files Browse the repository at this point in the history
…h-destroy-all
  • Loading branch information
ericf committed Apr 4, 2013
2 parents 4fa781c + caf4894 commit 5680ad6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/node/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Node Change History
===================

@VERSION@
-----

* Fix node.all() to return an empty NodeList if the node was destroyed - Fixes #580 (hat tip Dallas Wheeler)

3.9.1
-----

Expand Down
13 changes: 9 additions & 4 deletions src/node/js/node-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,15 @@ Y.mix(Y_Node.prototype, {
* @return {NodeList} A NodeList instance for the matching HTMLCollection/Array.
*/
all: function(selector) {
var nodelist = Y.all(Y.Selector.query(selector, this._node));
nodelist._query = selector;
nodelist._queryRoot = this._node;
return nodelist;
var nodelist;

if (this._node) {
nodelist = Y.all(Y.Selector.query(selector, this._node));
nodelist._query = selector;
nodelist._queryRoot = this._node;
}

return nodelist || Y.all([]);
},

// TODO: allow fn test
Expand Down
10 changes: 10 additions & 0 deletions src/node/tests/unit/node.html
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,16 @@ <h2>test</h2>
Assert.isTrue(Y.DOM.isWindow(Y.all(window)._nodes[0], "Y.all(window)"));
},

test_all_after_destroy: function () {
var node = Y.one('#test-form');

Assert.isTrue((node.all('*').size() > 0), "node.all('*').size() should be > 0");

node.destroy();

Assert.areSame(0, node.all('*').size(), "destroyed node.all('*').size() should be 0");
},

test_isEmpty: function() {
Assert.isFalse(Y.all('input').isEmpty());
Assert.isTrue(Y.all('.nomatch').isEmpty());
Expand Down

0 comments on commit 5680ad6

Please sign in to comment.