-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getCSSProperty.js #46
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Gets the specified CSS Property of a given element | ||
* | ||
* @param {object} mablInputs - Object containing mabl inputs such as variables (mablInputs.variables). | ||
* Use mablInputs.variables.user for user defined variables | ||
* (For example myVar may be accessed as mablInputs.variables.user.myVar) | ||
* | ||
* @param {function} callback - A callback function that must be called to complete | ||
* the javascript step and provide a value to the following | ||
* steps of the flow/journey. A return statement from this | ||
* function call will not provide any results for use | ||
* in the following steps in this flow or journey. | ||
* | ||
* Simplified Example: | ||
* function mablJavaScriptStep(mablInputs, callback) { | ||
* let selector = document.querySelector('[class="button demo"] div:nth-of-type(2)'); | ||
* let element = getComputedStyle(selector); | ||
* callback(element.getPropertyValue('background-color')); | ||
* } | ||
*/ | ||
|
||
function mablJavaScriptStep(mablInputs, callback) { | ||
// using an xpath | ||
//let selector = getElementByXpath(mablInputs.variables.user.selector_xpath); | ||
|
||
// using a css selector | ||
let selector = document.querySelector(mablInputs.variables.user.selector_css); | ||
|
||
let element = getComputedStyle(selector); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so I'm curious, we don't need |
||
callback(element.getPropertyValue(mablInputs.variables.user.css_property)); | ||
} | ||
|
||
function getElementByXpath(path) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea having this here, it's handy :-) |
||
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of
querySelector
isn't a selector, but rather an element. Would it make sense to change this variable name toelement
and the one below this tostyle
?[nit] - selector_css could be be
selectorCss
to match the camel casing used below.