Skip to content

Commit 4773051

Browse files
author
Nishchay Kaushik
committed
fix(helperLayer): for when element is scrollable
- when element is scrollable, helperLayer height is set to that of element which is incorrect as it causes the tooltip to go out of page visible area Set the height to be max to that of viewport height Set the top to not go outside the page (< 0px)
1 parent d3059b0 commit 4773051

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

intro.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,21 @@
155155

156156
if (currentItem.element !== null) {
157157
introItems.push(currentItem);
158-
}
158+
}
159159
}.bind(this));
160160

161161
} else {
162162
//use steps from data-* annotations
163163
var elmsLength = allIntroSteps.length;
164164
var disableInteraction;
165-
165+
166166
//if there's no element to intro
167167
if (elmsLength < 1) {
168168
return false;
169169
}
170170

171171
_forEach(allIntroSteps, function (currentElement) {
172-
172+
173173
// PR #80
174174
// start intro for groups of elements
175175
if (group && (currentElement.getAttribute("data-intro-group") !== group)) {
@@ -208,13 +208,13 @@
208208
var nextStep = 0;
209209

210210
_forEach(allIntroSteps, function (currentElement) {
211-
211+
212212
// PR #80
213213
// start intro for groups of elements
214214
if (group && (currentElement.getAttribute("data-intro-group") !== group)) {
215215
return;
216216
}
217-
217+
218218
if (currentElement.getAttribute('data-step') === null) {
219219

220220
while (true) {
@@ -223,7 +223,7 @@
223223
} else {
224224
nextStep++;
225225
}
226-
}
226+
}
227227

228228
if (typeof (currentElement.getAttribute('data-disable-interaction')) !== 'undefined') {
229229
disableInteraction = !!currentElement.getAttribute('data-disable-interaction');
@@ -250,8 +250,8 @@
250250
for (var z = 0; z < introItems.length; z++) {
251251
if (introItems[z]) {
252252
// copy non-falsy values to the end of the array
253-
tempIntroItems.push(introItems[z]);
254-
}
253+
tempIntroItems.push(introItems[z]);
254+
}
255255
}
256256

257257
introItems = tempIntroItems;
@@ -307,7 +307,7 @@
307307
if (code === null) {
308308
code = (e.charCode === null) ? e.keyCode : e.charCode;
309309
}
310-
310+
311311
if ((code === 'Escape' || code === 27) && this._options.exitOnEsc === true) {
312312
//escape key pressed, exit the intro
313313
//check if exit callback is defined
@@ -631,7 +631,7 @@
631631
currentTooltipPosition = this._introItems[this._currentStep].position;
632632

633633
// Floating is always valid, no point in calculating
634-
if (currentTooltipPosition !== "floating") {
634+
if (currentTooltipPosition !== "floating") {
635635
currentTooltipPosition = _determineAutoPosition.call(this, targetElement, tooltipLayer, currentTooltipPosition);
636636
}
637637

@@ -812,7 +812,7 @@
812812
var calculatedPosition = "floating";
813813

814814
/*
815-
* auto determine position
815+
* auto determine position
816816
*/
817817

818818
// Check for space below
@@ -884,16 +884,16 @@
884884
winWidth = Math.min(windowSize.width, window.screen.width),
885885
possibleAlignments = ['-left-aligned', '-middle-aligned', '-right-aligned'],
886886
calculatedAlignment = '';
887-
887+
888888
// valid left must be at least a tooltipWidth
889889
// away from right side
890890
if (winWidth - offsetLeft < tooltipWidth) {
891891
_removeEntry(possibleAlignments, '-left-aligned');
892892
}
893893

894-
// valid middle must be at least half
894+
// valid middle must be at least half
895895
// width away from both sides
896-
if (offsetLeft < halfTooltipWidth ||
896+
if (offsetLeft < halfTooltipWidth ||
897897
winWidth - offsetLeft < halfTooltipWidth) {
898898
_removeEntry(possibleAlignments, '-middle-aligned');
899899
}
@@ -913,8 +913,8 @@
913913
calculatedAlignment = possibleAlignments[0];
914914
}
915915
} else {
916-
// if screen width is too small
917-
// for ANY alignment, middle is
916+
// if screen width is too small
917+
// for ANY alignment, middle is
918918
// probably the best for visibility
919919
calculatedAlignment = '-middle-aligned';
920920
}
@@ -963,10 +963,13 @@
963963
widthHeightPadding = 0;
964964
}
965965

966+
var helperLayerMinTop = Math.max(0, (elementPosition.top - widthHeightPadding / 2));
967+
var helperLayerMaxHeight = Math.min(Math.max(document.documentElement.clientHeight, window.innerHeight || 0), elementPosition.height + widthHeightPadding);
968+
966969
//set new position to helper layer
967970
helperLayer.style.cssText = 'width: ' + (elementPosition.width + widthHeightPadding) + 'px; ' +
968-
'height:' + (elementPosition.height + widthHeightPadding) + 'px; ' +
969-
'top:' + (elementPosition.top - widthHeightPadding / 2) + 'px;' +
971+
'height:' + helperLayerMaxHeight + 'px; ' +
972+
'top:' + helperLayerMinTop + 'px;' +
970973
'left: ' + (elementPosition.left - widthHeightPadding / 2) + 'px;';
971974

972975
}
@@ -1036,7 +1039,7 @@
10361039
oldtooltipLayer = oldReferenceLayer.querySelector('.introjs-tooltiptext'),
10371040
oldArrowLayer = oldReferenceLayer.querySelector('.introjs-arrow'),
10381041
oldtooltipContainer = oldReferenceLayer.querySelector('.introjs-tooltip');
1039-
1042+
10401043
skipTooltipButton = oldReferenceLayer.querySelector('.introjs-skipbutton');
10411044
prevTooltipButton = oldReferenceLayer.querySelector('.introjs-prevbutton');
10421045
nextTooltipButton = oldReferenceLayer.querySelector('.introjs-nextbutton');
@@ -1072,7 +1075,7 @@
10721075
_forEach(fixParents, function (parent) {
10731076
_removeClass(parent, /introjs-fixParent/g);
10741077
});
1075-
1078+
10761079
//remove old classes if the element still exist
10771080
_removeShowElement();
10781081

@@ -1168,15 +1171,15 @@
11681171
_forEach(this._introItems, function (item, i) {
11691172
var innerLi = document.createElement('li');
11701173
var anchorLink = document.createElement('a');
1171-
1174+
11721175
innerLi.setAttribute('role', 'presentation');
11731176
anchorLink.setAttribute('role', 'tab');
11741177

11751178
anchorLink.onclick = anchorClick;
11761179

11771180
if (i === (targetElement.step-1)) {
11781181
anchorLink.className = 'active';
1179-
}
1182+
}
11801183

11811184
_setAnchorAsButton(anchorLink);
11821185
anchorLink.innerHTML = "&nbsp;";
@@ -1390,7 +1393,7 @@
13901393
* @param {Object} tooltipLayer
13911394
*/
13921395
function _scrollTo(scrollTo, targetElement, tooltipLayer) {
1393-
if (scrollTo === 'off') return;
1396+
if (scrollTo === 'off') return;
13941397
var rect;
13951398

13961399
if (!this._options.scrollToElement) return;
@@ -1518,7 +1521,7 @@
15181521
var _stamp = (function () {
15191522
var keys = {};
15201523
return function stamp (obj, key) {
1521-
1524+
15221525
// get group key
15231526
key = key || 'introjs-stamp';
15241527

@@ -1546,7 +1549,7 @@
15461549
var DOMEvent = (function () {
15471550
function DOMEvent () {
15481551
var events_key = 'introjs_event';
1549-
1552+
15501553
/**
15511554
* Gets a unique ID for an event listener
15521555
*
@@ -1867,9 +1870,9 @@
18671870

18681871
_addHints.call(this);
18691872

1870-
/*
1873+
/*
18711874
todo:
1872-
these events should be removed at some point
1875+
these events should be removed at some point
18731876
*/
18741877
DOMEvent.on(document, 'click', _removeHintTooltip, this, false);
18751878
DOMEvent.on(window, 'resize', _reAlignHints, this, true);
@@ -1910,7 +1913,7 @@
19101913
*/
19111914
function _hideHint(stepId) {
19121915
var hint = _hintQuerySelectorAll('.introjs-hint[data-step="' + stepId + '"]')[0];
1913-
1916+
19141917
_removeHintTooltip.call(this);
19151918

19161919
if (hint) {
@@ -2018,14 +2021,14 @@
20182021

20192022
/**
20202023
* Returns an event handler unique to the hint iteration
2021-
*
2024+
*
20222025
* @param {Integer} i
20232026
* @return {Function}
20242027
*/
20252028
var getHintClick = function (i) {
20262029
return function(e) {
20272030
var evt = e ? e : window.event;
2028-
2031+
20292032
if (evt.stopPropagation) {
20302033
evt.stopPropagation();
20312034
}
@@ -2258,7 +2261,7 @@
22582261
var overflowRegex = /(auto|scroll)/;
22592262

22602263
if (style.position === "fixed") return document.body;
2261-
2264+
22622265
for (var parent = element; (parent = parent.parentElement);) {
22632266
style = window.getComputedStyle(parent);
22642267
if (excludeStaticParent && style.position === "static") {

0 commit comments

Comments
 (0)