* @function * @memberof Popper.Utils * @argument {Object} data - The data object generated by `update` method * @argument {Boolean} shouldRound - If the offsets should be rounded at all * @returns {Object} The popper's position offsets rounded * * The tale of pixel-perfect position
(data, shouldRound)
| 2728 | * Only horizontal placement and left/right values need to be considered. |
| 2729 | */ |
| 2730 | function getRoundedOffsets(data, shouldRound) { |
| 2731 | var _data$offsets = data.offsets, |
| 2732 | popper = _data$offsets.popper, |
| 2733 | reference = _data$offsets.reference; |
| 2734 | var round = Math.round, |
| 2735 | floor = Math.floor; |
| 2736 | |
| 2737 | var noRound = function noRound(v) { |
| 2738 | return v; |
| 2739 | }; |
| 2740 | |
| 2741 | var referenceWidth = round(reference.width); |
| 2742 | var popperWidth = round(popper.width); |
| 2743 | |
| 2744 | var isVertical = ['left', 'right'].indexOf(data.placement) !== -1; |
| 2745 | var isVariation = data.placement.indexOf('-') !== -1; |
| 2746 | var sameWidthParity = referenceWidth % 2 === popperWidth % 2; |
| 2747 | var bothOddWidth = referenceWidth % 2 === 1 && popperWidth % 2 === 1; |
| 2748 | |
| 2749 | var horizontalToInteger = !shouldRound ? noRound : isVertical || isVariation || sameWidthParity ? round : floor; |
| 2750 | var verticalToInteger = !shouldRound ? noRound : round; |
| 2751 | |
| 2752 | return { |
| 2753 | left: horizontalToInteger(bothOddWidth && !isVariation && shouldRound ? popper.left - 1 : popper.left), |
| 2754 | top: verticalToInteger(popper.top), |
| 2755 | bottom: verticalToInteger(popper.bottom), |
| 2756 | right: horizontalToInteger(popper.right) |
| 2757 | }; |
| 2758 | } |
| 2759 | |
| 2760 | var isFirefox = isBrowser && /Firefox/i.test(navigator.userAgent); |
| 2761 |