-
Notifications
You must be signed in to change notification settings - Fork 0
/
starterFile.js
104 lines (83 loc) · 2.97 KB
/
starterFile.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const runPoll = (condition, options = {}) => {
return new Promise((resolve, reject) => {
let count = 0;
if (typeof condition !== 'function' && typeof condition !== 'object') {
reject(new Error(`invalid first parameter. expected type: 'function' or 'object' but found type: ${typeof condition}`));
} else if (typeof condition === 'function' && typeof options !== 'object') {
reject(new Error(`invalid second parameter. expected type: 'object' but found type: ${typeof options}`));
} else {
let _condition = null;
let _options = null;
if (typeof condition === 'function') {
_condition = condition;
_options = options;
} else if (typeof condition === 'object') {
_options = condition;
}
const {
pollLimit = 100,
duration = 50,
elements = []
} = _options;
const elementsCondition = () => {
let results = true;
elements.forEach(elem => {
if (document.querySelectorAll(elem).length === 0) {
results = false;
}
});
return results;
};
const fullPollCondition = () => {
let result = false;
if (typeof _condition === 'function') {
result = (_condition() && elementsCondition());
} else {
result = elementsCondition();
}
return result;
};
const iterator = () => {
if (count < pollLimit) {
count += 1;
if (fullPollCondition()) {
let resolveValue = null;
if (elements.length > 0) {
resolveValue = [];
elements.forEach(elem => {
if (document.querySelectorAll(elem).length === 1) {
resolveValue.push(document.querySelector(elem));
} else {
resolveValue.push(document.querySelectorAll(elem));
}
});
}
resolve(resolveValue);
} else {
setTimeout(() => {
iterator();
}, duration);
}
} else {
reject(new Error('poll timed out'));
}
};
iterator();
}
});
};
/**
* ADD YOUR TEST CODE IN THE FUNCTION BELOW
* 1) Update the herospace header text from "Today, get closer to your goals." to "Get closer to your goals."
* 2) Update the herospace CTA button text from "Open a Brokerage Account" to "Open a Brokerage Account Today"
* 3) Move the section with header text "Easily trade and manage investments..." to directly below the herospace/blue section.
* 4) Use Optimizely utils to ensure you are waiting for elements to exist on the page before executing code.
* 5) Fire an Adobe Analytics custom link metric using s.tl(). Ensure this call completes successfully by looking in the Network tab.
*/
const executeTest = () => {
};
const pollCondition = () => {
return !!window.optimizely &&
!!window.optimizely.get;
}
runPoll(pollCondition).then(executeTest);