MCPcopy
hub / github.com/shipshapecode/shepherd / bindAdvance

Function bindAdvance

shepherd.js/src/utils/bind.ts:29–64  ·  view source on GitHub ↗
(step: Step)

Source from the content-addressed store, hash-verified

27 * @param step The step instance
28 */
29export function bindAdvance(step: Step) {
30 // An empty selector matches the step element
31 const { event, selector } = step.options.advanceOn || {};
32 if (event) {
33 const handler = _setupAdvanceOnHandler(step, selector);
34
35 // TODO: this should also bind/unbind on show/hide
36 let el: Element | null = null;
37
38 if (!isUndefined(selector)) {
39 el = document.querySelector(selector);
40
41 if (!el) {
42 return console.error(
43 `No element was found for the selector supplied to advanceOn: ${selector}`
44 );
45 }
46 }
47
48 if (el) {
49 el.addEventListener(event, handler);
50 step.on('destroy', () => {
51 return (el as HTMLElement).removeEventListener(event, handler);
52 });
53 } else {
54 document.body.addEventListener(event, handler, true);
55 step.on('destroy', () => {
56 return document.body.removeEventListener(event, handler, true);
57 });
58 }
59 } else {
60 return console.error(
61 'advanceOn was defined, but no event name was passed.'
62 );
63 }
64}

Callers 2

bind.spec.jsFile · 0.90
_setupElementsMethod · 0.90

Calls 3

isUndefinedFunction · 0.90
_setupAdvanceOnHandlerFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected