|
23 | 23 | var SHAPE_BACKGROUND_COLOR = _options.backgroundColor || "rgba(0,0,0,0.6)";
|
24 | 24 |
|
25 | 25 | var body = "body"; // TODO: Is it possible case when we need to define enjoyhint somewhere else?
|
| 26 | + var elementAvailableEventName = "enjoyhint-element-available"; |
26 | 27 |
|
27 | 28 | var defaults = {
|
28 | 29 | onStart: function() {},
|
|
97 | 98 | $body.enjoyhint("hide_skip");
|
98 | 99 | };
|
99 | 100 |
|
100 |
| - var stepAction = function() { |
| 101 | + var stepAction = function(unpause) { |
101 | 102 | if (!(data && data[current_step])) {
|
102 | 103 | $body.enjoyhint("hide");
|
103 | 104 | options.onEnd();
|
|
113 | 114 | $enjoyhint.removeClass("enjoyhint-step-" + (current_step + 1));
|
114 | 115 | $enjoyhint.removeClass("enjoyhint-step-" + (current_step + 2));
|
115 | 116 | $enjoyhint.addClass("enjoyhint-step-" + (current_step + 1));
|
116 |
| - |
| 117 | + |
117 | 118 | var step_data = data[current_step];
|
118 | 119 |
|
| 120 | + $body.off(elementAvailableEventName); |
| 121 | + |
| 122 | + //loops waiting until specified element becomes visible |
| 123 | + var waitUntilAvailable = function (selector, interval) { |
| 124 | + if (interval == null) |
| 125 | + interval = 150; |
| 126 | + |
| 127 | + var triggerIfAvailable = function () { |
| 128 | + if ($(selector).is(":visible")) { |
| 129 | + $body.trigger(elementAvailableEventName); |
| 130 | + } |
| 131 | + else { |
| 132 | + setTimeout(triggerIfAvailable, interval) |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + setTimeout(triggerIfAvailable, 0); |
| 137 | + } |
| 138 | + |
| 139 | + //if pausedUntil was specified, hide current overlay and wait until specified event occurs |
| 140 | + if (!unpause && step_data.pausedUntil != null && step_data.pausedUntil.event != null) { |
| 141 | + //hide current overlay during waiting time |
| 142 | + $body.enjoyhint("hide"); |
| 143 | + |
| 144 | + //if 'available' event was chosen wait for the custom event, which is triggered when the element becomes visible |
| 145 | + if (step_data.pausedUntil.event === 'available') { |
| 146 | + $body.on(elementAvailableEventName, function () { |
| 147 | + stepAction(true); //restart the step without pause |
| 148 | + $body.off(elementAvailableEventName); |
| 149 | + }); |
| 150 | + |
| 151 | + //check if element is available every 150ms |
| 152 | + waitUntilAvailable(step_data.pausedUntil.selector); |
| 153 | + } |
| 154 | + else { |
| 155 | + //delay the actual action until 'the event' happens on body or selector |
| 156 | + if (step_data.pausedUntil.selector == null) { |
| 157 | + on(step_data.pausedUntil.event, function () { |
| 158 | + stepAction(true); //restart the step without pause |
| 159 | + off(step_data.pausedUntil.event); |
| 160 | + }); |
| 161 | + } |
| 162 | + else { |
| 163 | + $(step_data.pausedUntil.selector).on(step_data.pausedUntil.event, function () { |
| 164 | + stepAction(true); //restart the step without pause |
| 165 | + $(step_data.pausedUntil.selector).off(step_data.pausedUntil.event) |
| 166 | + }); |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + //the rest of the logic will be executed whenever the step is restarted |
| 171 | + return; |
| 172 | + } |
| 173 | + |
119 | 174 | var scrollSpeed = step_data.scrollAnimationSpeed;
|
120 | 175 |
|
121 | 176 | if (
|
|
0 commit comments