-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
53 lines (44 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (C) 2020 Labs64 GmbH
*
* This source code is licensed under the European Union Public License, version 1.2
* located in the LICENSE file
*/
/**
*
* @param {Class} cls GuideChimp class
* @param {Object} factory GuideChimp factory
* @param {Object} options the options object
*/
module.exports = (cls, factory, options) => {
const opt = options || {};
let { timeout = 5000 } = opt;
const { frequency = 100 } = opt;
const parentInit = cls.prototype.init;
// eslint-disable-next-line func-names,no-param-reassign
cls.prototype.init = function () {
parentInit.call(this);
this.on('onBeforeChange', (toStep) => new Promise((resolve) => {
const { element } = toStep;
if (!element) {
resolve();
return;
}
const isElExists = () => {
const el = this.getStepEl(toStep);
return (el && !this.isEl(el, 'fakeStep'));
};
if (isElExists()) {
resolve();
return;
}
const interval = setInterval(() => {
timeout -= frequency;
if (isElExists() || timeout <= 0) {
clearInterval(interval);
resolve();
}
}, frequency);
}));
};
};