(step: Step)
| 35 | * `on` is a string position value |
| 36 | */ |
| 37 | export function parseAttachTo(step: Step) { |
| 38 | const options = step.options.attachTo || {}; |
| 39 | const returnOpts = Object.assign({}, options); |
| 40 | |
| 41 | if (isFunction(returnOpts.element)) { |
| 42 | // Bind the callback to step so that it has access to the object, to enable running additional logic |
| 43 | returnOpts.element = returnOpts.element.call(step); |
| 44 | } |
| 45 | |
| 46 | if (isString(returnOpts.element)) { |
| 47 | // Can't override the element in user opts reference because we can't |
| 48 | // guarantee that the element will exist in the future. |
| 49 | try { |
| 50 | returnOpts.element = document.querySelector( |
| 51 | returnOpts.element |
| 52 | ) as HTMLElement; |
| 53 | } catch (_e) { |
| 54 | // TODO |
| 55 | } |
| 56 | if (!returnOpts.element) { |
| 57 | console.error( |
| 58 | `The element for this Shepherd step was not found ${options.element}` |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return returnOpts; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Resolves the step's `extraHighlights` option, converting any locator values to HTMLElements. |
no test coverage detected