Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit a0ea1ec

Browse files
committed
Fix parent z-index problem, related usablica#90 usablica#109
1 parent 2c1b831 commit a0ea1ec

File tree

2 files changed

+59
-11
lines changed

2 files changed

+59
-11
lines changed

intro.js

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@
214214
if (showElement) {
215215
showElement.className = showElement.className.replace(/introjs-[a-zA-Z]+/g, '').replace(/^\s+|\s+$/g, ''); // This is a manual trim.
216216
}
217+
218+
//remove `introjs-fixParent` class from the elements
219+
var fixParents = document.querySelectorAll('.introjs-fixParent');
220+
if (fixParents && fixParents.length > 0) {
221+
for (var i = fixParents.length - 1; i >= 0; i--) {
222+
fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, '');
223+
};
224+
}
217225
//clean listeners
218226
if (window.removeEventListener) {
219227
window.removeEventListener('keydown', this._onKeyDown, true);
@@ -302,7 +310,7 @@
302310
* @param {Object} targetElement
303311
*/
304312
function _showElement(targetElement) {
305-
313+
306314
if (typeof (this._introChangeCallback) !== 'undefined') {
307315
this._introChangeCallback.call(this, targetElement.element);
308316
}
@@ -326,6 +334,14 @@
326334
//set new position to helper layer
327335
_setHelperLayerPosition.call(self, oldHelperLayer);
328336

337+
//remove `introjs-fixParent` class from the elements
338+
var fixParents = document.querySelectorAll('.introjs-fixParent');
339+
if (fixParents && fixParents.length > 0) {
340+
for (var i = fixParents.length - 1; i >= 0; i--) {
341+
fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, '');
342+
};
343+
}
344+
329345
//remove old classes
330346
var oldShowElement = document.querySelector('.introjs-showElement');
331347
oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').replace(/^\s+|\s+$/g, '');
@@ -433,22 +449,24 @@
433449
//add target element position style
434450
targetElement.element.className += ' introjs-showElement';
435451

436-
//Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml
437-
var currentElementPosition = '';
438-
if (targetElement.element.currentStyle) { //IE
439-
currentElementPosition = targetElement.element.currentStyle['position'];
440-
} else if (document.defaultView && document.defaultView.getComputedStyle) { //Firefox
441-
currentElementPosition = document.defaultView.getComputedStyle(targetElement.element, null).getPropertyValue('position');
442-
}
443-
444-
//I don't know is this necessary or not, but I clear the position for better comparing
445-
currentElementPosition = currentElementPosition.toLowerCase();
452+
var currentElementPosition = _getPropValue(targetElement.element, 'position');
446453
if (currentElementPosition !== 'absolute' &&
447454
currentElementPosition !== 'relative') {
448455
//change to new intro item
449456
targetElement.element.className += ' introjs-relativePosition';
450457
}
451458

459+
var parentElm = targetElement.element.parentNode;
460+
while(parentElm != null) {
461+
if(parentElm.tagName.toLowerCase() === 'body') break;
462+
463+
var zIndex = _getPropValue(parentElm, 'z-index');
464+
if(/[0-9]+/.test(zIndex)) {
465+
parentElm.className += ' introjs-fixParent';
466+
}
467+
parentElm = parentElm.parentNode;
468+
}
469+
452470
if (!_elementInViewport(targetElement.element)) {
453471
var rect = targetElement.element.getBoundingClientRect(),
454472
top = rect.bottom - (rect.bottom - rect.top),
@@ -465,6 +483,32 @@
465483
}
466484
}
467485

486+
/**
487+
* Get an element CSS property on the page
488+
* Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml
489+
*
490+
* @api private
491+
* @method _getPropValue
492+
* @param {Object} element
493+
* @param {String} propName
494+
* @returns Element's property value
495+
*/
496+
function _getPropValue (element, propName) {
497+
var propValue = '';
498+
if (element.currentStyle) { //IE
499+
propValue = element.currentStyle[propName];
500+
} else if (document.defaultView && document.defaultView.getComputedStyle) { //Others
501+
propValue = document.defaultView.getComputedStyle(element, null).getPropertyValue(propName);
502+
}
503+
504+
//Prevent exception in IE
505+
if(propValue.toLowerCase) {
506+
return propValue.toLowerCase();
507+
} else {
508+
return propValue;
509+
}
510+
}
511+
468512
/**
469513
* Provides a cross-browser way to get the screen dimensions
470514
* via: http://stackoverflow.com/questions/5864467/internet-explorer-innerheight

introjs.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
transition: all 0.3s ease-out;
1313
}
1414

15+
.introjs-fixParent {
16+
z-index: auto !important;
17+
}
18+
1519
.introjs-showElement {
1620
z-index: 9999999;
1721
}

0 commit comments

Comments
 (0)