happy-dom
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -25,2 +25,18 @@ import Element from '../nodes/basic-types/Element'; | ||
static querySelector(node: Node, selector: string): Element; | ||
/** | ||
* Finds elements based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element[]} HTML elements. | ||
*/ | ||
private static singleQuerySelectorAll; | ||
/** | ||
* Finds an element based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element} HTML element. | ||
*/ | ||
private static singleQuerySelector; | ||
} |
@@ -24,2 +24,37 @@ "use strict"; | ||
QuerySelector.querySelectorAll = function (node, selector) { | ||
var matched = []; | ||
for (var _i = 0, _a = selector.split(','); _i < _a.length; _i++) { | ||
var part = _a[_i]; | ||
var foundElements = this.singleQuerySelectorAll(node, part.trim()); | ||
if (foundElements) { | ||
matched = matched.concat(foundElements); | ||
} | ||
} | ||
return matched; | ||
}; | ||
/** | ||
* Finds an element based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element} HTML element. | ||
*/ | ||
QuerySelector.querySelector = function (node, selector) { | ||
for (var _i = 0, _a = selector.split(','); _i < _a.length; _i++) { | ||
var part = _a[_i]; | ||
var foundElement = this.singleQuerySelector(node, part.trim()); | ||
if (foundElement) { | ||
return foundElement; | ||
} | ||
} | ||
return null; | ||
}; | ||
/** | ||
* Finds elements based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element[]} HTML elements. | ||
*/ | ||
QuerySelector.singleQuerySelectorAll = function (node, selector) { | ||
var parts = selector.split(' '); | ||
@@ -53,3 +88,3 @@ var current = new SelectorItem_1.default(parts[0]); | ||
*/ | ||
QuerySelector.querySelector = function (node, selector) { | ||
QuerySelector.singleQuerySelector = function (node, selector) { | ||
var parts = selector.split(' '); | ||
@@ -56,0 +91,0 @@ var current = new SelectorItem_1.default(parts.shift()); |
@@ -204,25 +204,27 @@ "use strict"; | ||
var key = _a[_i]; | ||
if (key === 'childNodes') { | ||
if (deep) { | ||
for (var _b = 0, _c = this[key]; _b < _c.length; _b++) { | ||
var childNode = _c[_b]; | ||
var childClone = childNode.cloneNode(); | ||
childClone.parentNode = clone; | ||
clone.childNodes.push(childClone); | ||
if (key !== '_isConnected' && key !== 'observers') { | ||
if (key === 'childNodes') { | ||
if (deep) { | ||
for (var _b = 0, _c = this[key]; _b < _c.length; _b++) { | ||
var childNode = _c[_b]; | ||
var childClone = childNode.cloneNode(); | ||
childClone.parentNode = clone; | ||
clone.childNodes.push(childClone); | ||
} | ||
} | ||
} | ||
} | ||
else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) { | ||
if (deep) { | ||
clone[key] = this[key].cloneNode(); | ||
clone[key].parentNode = clone; | ||
else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) { | ||
if (deep) { | ||
clone[key] = this[key].cloneNode(); | ||
clone[key].parentNode = clone; | ||
} | ||
} | ||
else if (key === 'classList') { | ||
// eslint-disable-next-line | ||
clone[key] = new ClassList_1.default(clone); | ||
} | ||
else { | ||
clone[key] = this[key]; | ||
} | ||
} | ||
else if (key === 'classList') { | ||
// eslint-disable-next-line | ||
clone[key] = new ClassList_1.default(clone); | ||
} | ||
else { | ||
clone[key] = this[key]; | ||
} | ||
} | ||
@@ -229,0 +231,0 @@ return clone; |
{ | ||
"name": "happy-dom", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom#readme", |
@@ -19,2 +19,39 @@ import Element from '../nodes/basic-types/Element'; | ||
public static querySelectorAll(node: Node, selector: string): Element[] { | ||
let matched = []; | ||
for(const part of selector.split(',')) { | ||
const foundElements = this.singleQuerySelectorAll(node, part.trim()); | ||
if(foundElements) { | ||
matched = matched.concat(foundElements); | ||
} | ||
} | ||
return matched; | ||
} | ||
/** | ||
* Finds an element based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element} HTML element. | ||
*/ | ||
public static querySelector(node: Node, selector: string): Element { | ||
for(const part of selector.split(',')) { | ||
const foundElement = this.singleQuerySelector(node, part.trim()); | ||
if(foundElement) { | ||
return foundElement; | ||
} | ||
} | ||
return null; | ||
} | ||
/** | ||
* Finds elements based on a query selector. | ||
* | ||
* @param {string} node Node to search in. | ||
* @param {string} selector Selector. | ||
* @return {Element[]} HTML elements. | ||
*/ | ||
private static singleQuerySelectorAll(node: Node, selector: string): Element[] { | ||
const parts = selector.split(' '); | ||
@@ -48,3 +85,3 @@ const current = new SelectorItem(parts[0]); | ||
*/ | ||
public static querySelector(node: Node, selector: string): Element { | ||
private static singleQuerySelector(node: Node, selector: string): Element { | ||
const parts = selector.split(' '); | ||
@@ -51,0 +88,0 @@ const current = new SelectorItem(parts.shift()); |
@@ -187,20 +187,22 @@ import NodeType from './NodeType'; | ||
for (const key of Object.keys(this)) { | ||
if (key === 'childNodes') { | ||
if (deep) { | ||
for (const childNode of this[key]) { | ||
const childClone = childNode.cloneNode(); | ||
childClone.parentNode = clone; | ||
clone.childNodes.push(childClone); | ||
if(key !== '_isConnected' && key !== 'observers') { | ||
if (key === 'childNodes') { | ||
if (deep) { | ||
for (const childNode of this[key]) { | ||
const childClone = childNode.cloneNode(); | ||
childClone.parentNode = clone; | ||
clone.childNodes.push(childClone); | ||
} | ||
} | ||
} else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) { | ||
if (deep) { | ||
clone[key] = this[key].cloneNode(); | ||
clone[key].parentNode = clone; | ||
} | ||
} else if (key === 'classList') { | ||
// eslint-disable-next-line | ||
clone[key] = new ClassList(<any>clone); | ||
} else { | ||
clone[key] = this[key]; | ||
} | ||
} else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) { | ||
if (deep) { | ||
clone[key] = this[key].cloneNode(); | ||
clone[key].parentNode = clone; | ||
} | ||
} else if (key === 'classList') { | ||
// eslint-disable-next-line | ||
clone[key] = new ClassList(<any>clone); | ||
} else { | ||
clone[key] = this[key]; | ||
} | ||
@@ -207,0 +209,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
434896
11202