|
145 | 145 | //remove `introjs-showElement` class from the element
|
146 | 146 | var showElement = document.querySelector(".introjs-showElement");
|
147 | 147 | if (showElement) {
|
148 |
| - showElement.className = showElement.className.replace(/introjs-showElement/,'').trim(); |
| 148 | + showElement.className = showElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim(); |
149 | 149 | }
|
150 | 150 | //clean listeners
|
151 | 151 | targetElement.onkeydown = null;
|
|
226 | 226 | //set current tooltip text
|
227 | 227 | oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
|
228 | 228 | var oldShowElement = document.querySelector(".introjs-showElement");
|
229 |
| - oldShowElement.className = oldShowElement.className.replace(/introjs-showElement/,'').trim(); |
230 |
| - //change to new intro item |
231 |
| - targetElement.className += " introjs-showElement"; |
| 229 | + oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim(); |
232 | 230 | _placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer);
|
233 | 231 | } else {
|
234 |
| - targetElement.className += " introjs-showElement"; |
235 |
| - |
236 | 232 | var helperLayer = document.createElement("div"),
|
237 | 233 | helperNumberLayer = document.createElement("span"),
|
238 | 234 | arrowLayer = document.createElement("div"),
|
|
284 | 280 | _placeTooltip(targetElement, tooltipLayer, arrowLayer);
|
285 | 281 | }
|
286 | 282 |
|
| 283 | + //add target element position style |
| 284 | + targetElement.className += " introjs-showElement"; |
| 285 | + |
| 286 | + //Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml |
| 287 | + var currentElementPosition = ""; |
| 288 | + if (targetElement.currentStyle) { //IE |
| 289 | + currentElementPosition = targetElement.currentStyle["position"]; |
| 290 | + } else if (document.defaultView && document.defaultView.getComputedStyle) { //Firefox |
| 291 | + currentElementPosition = document.defaultView.getComputedStyle(targetElement, null).getPropertyValue("position"); |
| 292 | + } |
| 293 | + |
| 294 | + //I don't know is this necessary or not, but I clear the position for better comparing |
| 295 | + currentElementPosition = currentElementPosition.toLowerCase(); |
| 296 | + if (currentElementPosition != "absolute" && currentElementPosition != "relative") { |
| 297 | + //change to new intro item |
| 298 | + targetElement.className += " introjs-relativePosition"; |
| 299 | + } |
| 300 | + |
287 | 301 | //scroll the page to the element position
|
288 | 302 | if (typeof(targetElement.scrollIntoViewIfNeeded) === "function") {
|
289 | 303 | //awesome method guys: https://bugzilla.mozilla.org/show_bug.cgi?id=403510
|
|
0 commit comments