|
43 | 43 | introItems.push({
|
44 | 44 | element: currentElement,
|
45 | 45 | intro: currentElement.getAttribute("data-intro"),
|
46 |
| - step: parseInt(currentElement.getAttribute("data-step")) |
| 46 | + step: parseInt(currentElement.getAttribute("data-step")), |
| 47 | + position: currentElement.getAttribute("data-position") || 'bottom' |
47 | 48 | });
|
48 | 49 | }
|
49 | 50 |
|
|
76 | 77 | //right arrow
|
77 | 78 | _nextStep.call(self);
|
78 | 79 | }
|
79 |
| - }; |
80 |
| - } |
| 80 | + } |
| 81 | + }; |
81 | 82 | }
|
82 | 83 | return false;
|
83 | 84 | }
|
|
114 | 115 | * @method _nextStep
|
115 | 116 | */
|
116 | 117 | function _previousStep() {
|
117 |
| - if(this._currentStep == 0) |
| 118 | + if(this._currentStep == 0){ |
118 | 119 | return;
|
| 120 | + } |
119 | 121 |
|
120 | 122 | _showElement.call(this, this._introItems[--this._currentStep].element);
|
121 | 123 | }
|
|
155 | 157 | }
|
156 | 158 | }
|
157 | 159 |
|
| 160 | + function _placeTooltip(targetElement, tooltipLayer, arrowLayer){ |
| 161 | + var tooltipLayerPosition = _getOffset(tooltipLayer); |
| 162 | + tooltipLayer.style.top = null; |
| 163 | + tooltipLayer.style.right = null; |
| 164 | + tooltipLayer.style.bottom = null; |
| 165 | + tooltipLayer.style.left = null; |
| 166 | + switch(targetElement.getAttribute('data-position')){ |
| 167 | + case 'top': |
| 168 | + tooltipLayer.style.top = "-" + (tooltipLayerPosition.height + 10) + "px"; |
| 169 | + arrowLayer.className = 'introjs-arrow bottom'; |
| 170 | + break; |
| 171 | + case 'right': |
| 172 | + console.log(tooltipLayerPosition); |
| 173 | + tooltipLayer.style.right = "-" + (tooltipLayerPosition.width + 10) + "px"; |
| 174 | + arrowLayer.className = 'introjs-arrow left'; |
| 175 | + break; |
| 176 | + case 'left': |
| 177 | + tooltipLayer.style.left = "-" + (tooltipLayerPosition.width + 10) + "px"; |
| 178 | + arrowLayer.className = 'introjs-arrow right'; |
| 179 | + break; |
| 180 | + case 'bottom': |
| 181 | + default: |
| 182 | + tooltipLayer.style.bottom = "-" + (tooltipLayerPosition.height + 10) + "px"; |
| 183 | + arrowLayer.className = 'introjs-arrow top'; |
| 184 | + break; |
| 185 | + } |
| 186 | + } |
| 187 | + |
158 | 188 | /**
|
159 | 189 | * Show an element on the page
|
160 | 190 | *
|
|
172 | 202 | if(oldHelperLayer != null) {
|
173 | 203 | var oldHelperNumberLayer = oldHelperLayer.querySelector(".introjs-helperNumberLayer"),
|
174 | 204 | oldtooltipLayer = oldHelperLayer.querySelector(".introjs-tooltiptext"),
|
| 205 | + oldArrowLayer = oldHelperLayer.querySelector(".introjs-arrow"), |
175 | 206 | oldtooltipContainer = oldHelperLayer.querySelector(".introjs-tooltip")
|
176 | 207 |
|
177 | 208 | //set new position to helper layer
|
|
187 | 218 | oldShowElement.className = oldShowElement.className.replace(/introjs-showElement/,'').trim();
|
188 | 219 | //change to new intro item
|
189 | 220 | targetElement.className += " introjs-showElement";
|
190 |
| - |
191 |
| - //wait until the animation is completed |
192 |
| - setTimeout(function() { |
193 |
| - oldtooltipContainer.style.bottom = "-" + (_getOffset(oldtooltipContainer).height + 10) + "px"; |
194 |
| - }, 300); |
195 |
| - |
| 221 | + _placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer); |
196 | 222 | } else {
|
197 | 223 | targetElement.className += " introjs-showElement";
|
198 | 224 |
|
199 | 225 | var helperLayer = document.createElement("div"),
|
200 | 226 | helperNumberLayer = document.createElement("span"),
|
| 227 | + arrowLayer = document.createElement("div"), |
201 | 228 | tooltipLayer = document.createElement("div");
|
202 | 229 |
|
203 | 230 | helperLayer.className = "introjs-helperLayer";
|
|
209 | 236 | document.body.appendChild(helperLayer);
|
210 | 237 |
|
211 | 238 | helperNumberLayer.className = "introjs-helperNumberLayer";
|
| 239 | + arrowLayer.className = 'introjs-arrow'; |
212 | 240 | tooltipLayer.className = "introjs-tooltip";
|
213 | 241 |
|
214 | 242 | helperNumberLayer.innerHTML = targetElement.getAttribute("data-step");
|
215 | 243 | tooltipLayer.innerHTML = "<div class='introjs-tooltiptext'>" + targetElement.getAttribute("data-intro") + "</div><div class='introjs-tooltipbuttons'></div>";
|
216 | 244 | helperLayer.appendChild(helperNumberLayer);
|
| 245 | + tooltipLayer.appendChild(arrowLayer); |
217 | 246 | helperLayer.appendChild(tooltipLayer);
|
218 | 247 |
|
219 | 248 | var skipTooltipButton = document.createElement("a");
|
|
238 | 267 | var tooltipButtonsLayer = tooltipLayer.querySelector('.introjs-tooltipbuttons');
|
239 | 268 | tooltipButtonsLayer.appendChild(skipTooltipButton);
|
240 | 269 | tooltipButtonsLayer.appendChild(nextTooltipButton);
|
241 |
| - |
242 |
| - |
| 270 | + |
243 | 271 | //set proper position
|
244 |
| - tooltipLayer.style.bottom = "-" + (_getOffset(tooltipLayer).height + 10) + "px"; |
| 272 | + _placeTooltip(targetElement, tooltipLayer, arrowLayer); |
245 | 273 | }
|
246 | 274 |
|
247 | 275 | //scroll the page to the element position
|
|
0 commit comments