|
792 | 792 | // Take a clone of position precedence. These will be the available
|
793 | 793 | var possiblePositions = this._options.positionPrecedence.slice();
|
794 | 794 |
|
795 |
| - var scrollTop = window.pageYOffset || document.documentElement.scrollTop; |
796 |
| - var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft; |
797 |
| - |
798 | 795 | var windowSize = _getWinSize();
|
799 | 796 | var tooltipHeight = _getOffset(tooltipLayer).height + 10;
|
800 | 797 | var tooltipWidth = _getOffset(tooltipLayer).width + 20;
|
801 |
| - var targetOffset = _getOffset(targetElement); |
802 |
| - |
803 |
| - // adjust for scroll position |
804 |
| - targetOffset.top -= scrollTop; |
805 |
| - targetOffset.left -= scrollLeft; |
| 798 | + var targetElementRect = targetElement.getBoundingClientRect(); |
806 | 799 |
|
807 | 800 | // If we check all the possible areas, and there are no valid places for the tooltip, the element
|
808 | 801 | // must take up most of the screen real estate. Show the tooltip floating in the middle of the screen.
|
|
813 | 806 | */
|
814 | 807 |
|
815 | 808 | // Check for space below
|
816 |
| - if ((targetOffset.height + targetOffset.top + tooltipHeight) > windowSize.height) { |
| 809 | + if (targetElementRect.bottom + tooltipHeight + tooltipHeight > windowSize.height) { |
817 | 810 | _removeEntry(possiblePositions, "bottom");
|
818 | 811 | }
|
819 | 812 |
|
820 | 813 | // Check for space above
|
821 |
| - if (targetOffset.top - tooltipHeight < 0) { |
| 814 | + if (targetElementRect.top - tooltipHeight < 0) { |
822 | 815 | _removeEntry(possiblePositions, "top");
|
823 | 816 | }
|
824 | 817 |
|
825 | 818 | // Check for space to the right
|
826 |
| - if (targetOffset.width + targetOffset.left + tooltipWidth > windowSize.width) { |
| 819 | + if (targetElementRect.right + tooltipWidth > windowSize.width) { |
827 | 820 | _removeEntry(possiblePositions, "right");
|
828 | 821 | }
|
829 | 822 |
|
830 | 823 | // Check for space to the left
|
831 |
| - if (targetOffset.left - tooltipWidth < 0) { |
| 824 | + if (targetElementRect.left - tooltipWidth < 0) { |
832 | 825 | _removeEntry(possiblePositions, "left");
|
833 | 826 | }
|
834 | 827 |
|
|
862 | 855 |
|
863 | 856 | // only top and bottom positions have optional alignments
|
864 | 857 | if (['top', 'bottom'].indexOf(calculatedPosition) !== -1) {
|
865 |
| - calculatedPosition += _determineAutoAlignment(targetOffset.left, tooltipWidth, windowSize, desiredAlignment); |
| 858 | + calculatedPosition += _determineAutoAlignment(targetElementRect.left, tooltipWidth, windowSize, desiredAlignment); |
866 | 859 | }
|
867 | 860 |
|
868 | 861 | return calculatedPosition;
|
|
1362 | 1355 | * @param {Object} tooltipLayer
|
1363 | 1356 | */
|
1364 | 1357 | function _scrollTo(scrollTo, targetElement, tooltipLayer) {
|
| 1358 | + if (scrollTo === 'off') return; |
1365 | 1359 | var rect;
|
1366 | 1360 |
|
1367 | 1361 | if (!this._options.scrollToElement) return;
|
|
0 commit comments