Skip to content

Commit 6d37653

Browse files
gooddaytodaykiselev
authored andcommitted
waitforElement function applied in nextStep
1 parent 5f58f8d commit 6d37653

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/core/steps.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import forEach from "../util/forEach";
22
import showElement from "./showElement";
33
import exitIntro from "./exitIntro";
4+
import waitForElement from "../util/waitForElement";
45

56
/**
67
* Go to specific step of introduction
@@ -59,7 +60,8 @@ export function nextStep() {
5960
if (typeof this._introBeforeChangeCallback !== "undefined") {
6061
continueStep = this._introBeforeChangeCallback.call(
6162
this,
62-
nextStep && nextStep.element
63+
nextStep &&
64+
(elementBySelectorNotExists(nextStep) ? undefined : nextStep.element)
6365
);
6466
}
6567

@@ -79,7 +81,21 @@ export function nextStep() {
7981
return;
8082
}
8183

82-
showElement.call(this, nextStep);
84+
if (elementBySelectorNotExists(nextStep)) {
85+
waitForElement(nextStep._element, () => showElement.call(this, nextStep));
86+
} else {
87+
showElement.call(this, nextStep);
88+
}
89+
}
90+
91+
/**
92+
* Return true if element locates by selector and doesn't exists yet
93+
*/
94+
function elementBySelectorNotExists(step) {
95+
return (
96+
typeof step._element === "string" &&
97+
document.querySelector(step._element) === null
98+
);
8399
}
84100

85101
/**

0 commit comments

Comments
 (0)