-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from angrykoala/dev
wendigo 0.7.4
- Loading branch information
Showing
26 changed files
with
775 additions
and
470 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ env: | |
- NO_SANDBOX=true | ||
|
||
script: | ||
- npm test | ||
- travis_retry npm test | ||
|
||
cache: | ||
directories: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,80 @@ | ||
"use strict"; | ||
if(!window.WendigoQuery) { | ||
window.WendigoQuery = { | ||
selectorTypes: { // Warning: Same as selector type | ||
css: "css", | ||
xpath: "xpath", | ||
domElement: "domElement" | ||
}, | ||
query(selector) { | ||
const type = this._parseSelectorType(selector); | ||
switch(type) { | ||
case this.selectorTypes.css: | ||
return this.queryCss(selector); | ||
case this.selectorTypes.xpath: | ||
return this.queryXPath(selector); | ||
case this.selectorTypes.domElement: | ||
return this.queryDomElement(selector); | ||
default: | ||
throw new Error(`Query Error: ${selector} with type ${type}`); | ||
} | ||
}, | ||
queryAll(selector) { | ||
const type = this._parseSelectorType(selector); | ||
|
||
window.WendigoQuery = { | ||
selectorTypes: { // Warning: Same as selector type | ||
css: "css", | ||
xpath: "xpath", | ||
domElement: "domElement" | ||
}, | ||
query(selector) { | ||
const type = this._parseSelectorType(selector); | ||
switch(type) { | ||
case this.selectorTypes.css: | ||
return this.queryCss(selector); | ||
case this.selectorTypes.xpath: | ||
return this.queryXPath(selector); | ||
case this.selectorTypes.domElement: | ||
return this.queryDomElement(selector); | ||
default: | ||
throw new Error(`Query Error: ${selector} with type ${type}`); | ||
} | ||
}, | ||
queryAll(selector) { | ||
const type = this._parseSelectorType(selector); | ||
switch(type) { | ||
case this.selectorTypes.css: | ||
return this.queryCssAll(selector); | ||
case this.selectorTypes.xpath: | ||
return this.queryXPathAll(selector); | ||
case this.selectorTypes.domElement: | ||
return this.queryDomElementAll(selector); | ||
default: | ||
throw new Error(`QueryAll Error: ${selector} with type ${type}`); | ||
} | ||
}, | ||
queryCss(cssSelector) { | ||
return document.querySelector(cssSelector); | ||
}, | ||
queryCssAll(cssSelector) { | ||
return Array.from(document.querySelectorAll(cssSelector)); | ||
}, | ||
queryDomElement(element) { | ||
if(Array.isArray(element)) return element[0]; | ||
else return element; | ||
}, | ||
queryDomElementAll(elements) { | ||
if(Array.isArray(elements)) return elements; | ||
else return [elements]; | ||
}, | ||
queryXPath(xPath) { | ||
const xPathResult = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null); | ||
const result = xPathResult.iterateNext(); | ||
return result; | ||
}, | ||
queryXPathAll(xPath) { | ||
const xPathResult = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null); | ||
const result = []; | ||
let r = xPathResult.iterateNext(); | ||
while(r !== null) { | ||
result.push(r); | ||
r = xPathResult.iterateNext(); | ||
} | ||
return result; | ||
}, | ||
|
||
switch(type) { | ||
case this.selectorTypes.css: | ||
return this.queryCssAll(selector); | ||
case this.selectorTypes.xpath: | ||
return this.queryXPathAll(selector); | ||
case this.selectorTypes.domElement: | ||
return this.queryDomElementAll(selector); | ||
default: | ||
throw new Error(`QueryAll Error: ${selector} with type ${type}`); | ||
} | ||
}, | ||
queryCss(cssSelector) { | ||
return document.querySelector(cssSelector); | ||
}, | ||
queryCssAll(cssSelector) { | ||
return Array.from(document.querySelectorAll(cssSelector)); | ||
}, | ||
queryDomElement(element) { | ||
if(Array.isArray(element)) return element[0]; | ||
else return element; | ||
}, | ||
queryDomElementAll(elements) { | ||
if(Array.isArray(elements)) return elements; | ||
else return [elements]; | ||
}, | ||
queryXPath(xPath) { | ||
const xPathResult = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null); | ||
const result = xPathResult.iterateNext(); | ||
return result; | ||
}, | ||
queryXPathAll(xPath) { | ||
const xPathResult = document.evaluate(xPath, document, null, XPathResult.ANY_TYPE, null); | ||
const result = []; | ||
let r = xPathResult.iterateNext(); | ||
while(r !== null) { | ||
result.push(r); | ||
r = xPathResult.iterateNext(); | ||
} | ||
return result; | ||
}, | ||
_parseSelectorType(selector) { | ||
if(typeof(selector) === "string") { | ||
return this._parseStringSelector(selector); | ||
} else if(typeof(selector) === "object") { | ||
return this.selectorTypes.domElement; | ||
} else return null; | ||
}, | ||
|
||
_parseSelectorType(selector) { | ||
if(typeof(selector) === "string") { | ||
return this._parseStringSelector(selector); | ||
} else if(typeof(selector) === "object") { | ||
return this.selectorTypes.domElement; | ||
} else return null; | ||
}, | ||
|
||
_parseStringSelector(selector) { | ||
if(selector.length === 0) return null; | ||
if(selector[0] === "/") return this.selectorTypes.xpath; | ||
else return this.selectorTypes.css; | ||
} | ||
}; | ||
_parseStringSelector(selector) { | ||
if(selector.length === 0) return null; | ||
if(selector[0] === "/") return this.selectorTypes.xpath; | ||
else return this.selectorTypes.css; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
/* global WendigoQuery */ | ||
"use strict"; | ||
|
||
window.WendigoUtils = { | ||
isVisible(element) { | ||
if(!element) return false; | ||
if (element === document) return true; // Top element, always visible | ||
const style = window.getComputedStyle(element); | ||
if (style.display === 'none') return false; | ||
if (style.visibility === 'hidden') return false; | ||
return this.isVisible(element.parentNode); | ||
}, | ||
queryElement(selector) { | ||
return WendigoQuery.query(selector); | ||
}, | ||
queryAll(selector) { | ||
return WendigoQuery.queryAll(selector); | ||
}, | ||
xPathQuery(xPath) { | ||
return WendigoQuery.queryXPathAll(xPath); | ||
}, | ||
getStyles(element) { | ||
const rawStyles = getComputedStyle(element); | ||
const result = {}; | ||
for(let i = 0;i < rawStyles.length;i++) { | ||
const name = rawStyles[i]; | ||
result[name] = rawStyles.getPropertyValue(name); | ||
if(!window.WendigoUtils) { | ||
window.WendigoUtils = { | ||
isVisible(element) { | ||
if(!element) return false; | ||
if (element === document) return true; // Top element, always visible | ||
const style = window.getComputedStyle(element); | ||
if (style.display === 'none') return false; | ||
if (style.visibility === 'hidden') return false; | ||
return this.isVisible(element.parentNode); | ||
}, | ||
queryElement(selector) { | ||
return WendigoQuery.query(selector); | ||
}, | ||
queryAll(selector) { | ||
return WendigoQuery.queryAll(selector); | ||
}, | ||
xPathQuery(xPath) { | ||
return WendigoQuery.queryXPathAll(xPath); | ||
}, | ||
getStyles(element) { | ||
const rawStyles = getComputedStyle(element); | ||
const result = {}; | ||
for(let i = 0;i < rawStyles.length;i++) { | ||
const name = rawStyles[i]; | ||
result[name] = rawStyles.getPropertyValue(name); | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
}; | ||
}; | ||
} |
Oops, something went wrong.