|
510 | 510 | break;
|
511 | 511 | case 'bottom-right-aligned':
|
512 | 512 | 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'; |
515 | 517 | break;
|
| 518 | + |
516 | 519 | case 'bottom-middle-aligned':
|
517 | 520 | 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'; |
525 | 528 | break;
|
| 529 | + |
526 | 530 | case 'bottom-left-aligned':
|
527 | 531 | // Bottom-left-aligned is the same as the default bottom
|
528 | 532 | case 'bottom':
|
529 | 533 | // Bottom going to follow the default behavior
|
530 | 534 | default:
|
531 |
| - tooltipLayer.style.bottom = '-' + (tooltipOffset.height + 10) + 'px'; |
532 |
| - tooltipLayer.style.left = (targetOffset.width / 2 - tooltipOffset.width / 2) + 'px'; |
533 |
| - |
534 | 535 | 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'; |
535 | 540 | break;
|
536 | 541 | }
|
537 | 542 | }
|
538 | 543 |
|
| 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 | + |
539 | 574 | /**
|
540 | 575 | * Determines the position of the tooltip based on the position precedence and availability
|
541 | 576 | * of screen space.
|
|
0 commit comments