Skip to content

Commit cd2ec80

Browse files
committed
commonaliz some of the bottom positions
1 parent ad28e40 commit cd2ec80

File tree

2 files changed

+70
-35
lines changed

2 files changed

+70
-35
lines changed

intro.js

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,32 +510,67 @@
510510
break;
511511
case 'bottom-right-aligned':
512512
arrowLayer.className = 'introjs-arrow top-right';
513-
tooltipLayer.style.right = '0px';
514-
tooltipLayer.style.bottom = '-' + (tooltipOffset.height + 10) + 'px';
513+
514+
var tooltipLayerStyleRight = 0;
515+
_checkLeft(targetOffset, tooltipLayerStyleRight, tooltipOffset, tooltipLayer);
516+
tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
515517
break;
518+
516519
case 'bottom-middle-aligned':
517520
arrowLayer.className = 'introjs-arrow top-middle';
518-
var tooltipLayerStyleLeft = targetOffset.width / 2 - tooltipOffset.width / 2;
519-
// off the right side of the window
520-
if (targetOffset.left + tooltipLayerStyleLeft + tooltipOffset.width > windowSize.width)
521-
tooltipLayer.style.left = (windowSize.width - tooltipOffset.width - targetOffset.left) + 'px';
522-
else
523-
tooltipLayer.style.left = tooltipLayerStyleLeft + 'px';
524-
tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
521+
522+
var tooltipLayerStyleLeftRight = targetOffset.width / 2 - tooltipOffset.width / 2;
523+
if (_checkLeft(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, tooltipLayer)) {
524+
tooltipLayer.style.right = null;
525+
_checkRight(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, windowSize, tooltipLayer);
526+
}
527+
tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
525528
break;
529+
526530
case 'bottom-left-aligned':
527531
// Bottom-left-aligned is the same as the default bottom
528532
case 'bottom':
529533
// Bottom going to follow the default behavior
530534
default:
531-
tooltipLayer.style.bottom = '-' + (tooltipOffset.height + 10) + 'px';
532-
tooltipLayer.style.left = (targetOffset.width / 2 - tooltipOffset.width / 2) + 'px';
533-
534535
arrowLayer.className = 'introjs-arrow top';
536+
537+
var tooltipLayerStyleLeft = 0;
538+
_checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer);
539+
tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
535540
break;
536541
}
537542
}
538543

544+
/**
545+
* Set tooltip left so it doesn't go off the right side of the window
546+
*
547+
* @return boolean true, if tooltipLayerStyleLeft is ok. false, otherwise.
548+
*/
549+
function _checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer) {
550+
if (targetOffset.left + tooltipLayerStyleLeft + tooltipOffset.width > windowSize.width) {
551+
// off the right side of the window
552+
tooltipLayer.style.left = (windowSize.width - tooltipOffset.width - targetOffset.left) + 'px';
553+
return false;
554+
}
555+
tooltipLayer.style.left = tooltipLayerStyleLeft + 'px';
556+
return true;
557+
}
558+
559+
/**
560+
* Set tooltip right so it doesn't go off the left side of the window
561+
*
562+
* @return boolean true, if tooltipLayerStyleRight is ok. false, otherwise.
563+
*/
564+
function _checkLeft(targetOffset, tooltipLayerStyleRight, tooltipOffset, tooltipLayer) {
565+
if (targetOffset.left + targetOffset.width - tooltipLayerStyleRight - tooltipOffset.width < 0) {
566+
// off the left side of the window
567+
tooltipLayer.style.left = (-targetOffset.left) + 'px';
568+
return false;
569+
}
570+
tooltipLayer.style.right = tooltipLayerStyleRight + 'px';
571+
return true;
572+
}
573+
539574
/**
540575
* Determines the position of the tooltip based on the position precedence and availability
541576
* of screen space.

0 commit comments

Comments
 (0)