Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'querySelectorAll' into notemplate

Conflicts:
	lib/jsdom/selectors/index.js
  • Loading branch information...
commit a55eee23fc72da990c8e06703511ce3a42033511 2 parents 5582a13 + 89dc5b9
@kapouer kapouer authored
Showing with 14 additions and 2 deletions.
  1. +9 −1 lib/jsdom/selectors/index.js
  2. +5 −1 test/jsdom/index.js
View
10 lib/jsdom/selectors/index.js
@@ -22,6 +22,14 @@ exports.applyQuerySelectorPrototype = function(dom) {
dom.Element.prototype.querySelectorAll = function(selector) {
var el = this;
- return new dom.NodeList(addSizzle(this.ownerDocument)(selector, el));
+ if (!this.parentNode) {
+ el = this.ownerDocument.createElement("div");
+ el.appendChild(this);
+ }
+ var res = addSizzle(this.ownerDocument)(selector, el.parentNode || el);
+ for (var i=0, len=res.length; i < len; i++) {
+ if (res[i] == this) res.splice(i, 1);
+ }
+ return new dom.NodeList(res);
};
};
View
6 test/jsdom/index.js
@@ -519,7 +519,7 @@ exports.tests = {
// TODO: look into breaking into a testcase
queryselectorall: function(test) {
- var html = '<html><body><div id="main"><p>Foo</p><p>Bar</p></div></body></html>',
+ var html = '<html><body><div id="main"><p>Foo</p><p>Bar</p><div>Boo</div><div>Far</div></div></body></html>',
document = jsdom.jsdom(html, null, {features: {'QuerySelector': true}}),
div = document.body.children.item(0),
elements = document.querySelectorAll("#main p");
@@ -534,6 +534,10 @@ exports.tests = {
test.equal(elements3.length, 2, 'two results');
test.equal(elements3.item(0), div.children.item(0), 'p and first-p');
test.equal(elements3.item(1), div.children.item(1), 'p and second-p');
+ var elements4 = div.querySelectorAll("div");
+ test.equal(elements4.length, 2, 'two results');
+ test.equal(elements4.item(0), div.children.item(2), 'div and first-div');
+ test.equal(elements4.item(1), div.children.item(3), 'div and second-div');
var topNode = document.createElement('p'),
newNode = document.createElement('p');
topNode.id = "fuz";
Please sign in to comment.
Something went wrong with that request. Please try again.