* @function * @memberof Modifiers * @argument {Object} data - The data object generated by `update` method * @argument {Object} options - Modifiers configuration and options * @returns {Object} The data object, properly modified
(data, options)
| 2767 | * @returns {Object} The data object, properly modified |
| 2768 | */ |
| 2769 | function computeStyle(data, options) { |
| 2770 | var x = options.x, |
| 2771 | y = options.y; |
| 2772 | var popper = data.offsets.popper; |
| 2773 | |
| 2774 | // Remove this legacy support in Popper.js v2 |
| 2775 | |
| 2776 | var legacyGpuAccelerationOption = find(data.instance.modifiers, function (modifier) { |
| 2777 | return modifier.name === 'applyStyle'; |
| 2778 | }).gpuAcceleration; |
| 2779 | if (legacyGpuAccelerationOption !== undefined) { |
| 2780 | console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!'); |
| 2781 | } |
| 2782 | var gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration; |
| 2783 | |
| 2784 | var offsetParent = getOffsetParent(data.instance.popper); |
| 2785 | var offsetParentRect = getBoundingClientRect(offsetParent); |
| 2786 | |
| 2787 | // Styles |
| 2788 | var styles = { |
| 2789 | position: popper.position |
| 2790 | }; |
| 2791 | |
| 2792 | var offsets = getRoundedOffsets(data, window.devicePixelRatio < 2 || !isFirefox); |
| 2793 | |
| 2794 | var sideA = x === 'bottom' ? 'top' : 'bottom'; |
| 2795 | var sideB = y === 'right' ? 'left' : 'right'; |
| 2796 | |
| 2797 | // if gpuAcceleration is set to `true` and transform is supported, |
| 2798 | // we use `translate3d` to apply the position to the popper we |
| 2799 | // automatically use the supported prefixed version if needed |
| 2800 | var prefixedProperty = getSupportedPropertyName('transform'); |
| 2801 | |
| 2802 | // now, let's make a step back and look at this code closely (wtf?) |
| 2803 | // If the content of the popper grows once it's been positioned, it |
| 2804 | // may happen that the popper gets misplaced because of the new content |
| 2805 | // overflowing its reference element |
| 2806 | // To avoid this problem, we provide two options (x and y), which allow |
| 2807 | // the consumer to define the offset origin. |
| 2808 | // If we position a popper on top of a reference element, we can set |
| 2809 | // `x` to `top` to make the popper grow towards its top instead of |
| 2810 | // its bottom. |
| 2811 | var left = void 0, |
| 2812 | top = void 0; |
| 2813 | if (sideA === 'bottom') { |
| 2814 | // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar) |
| 2815 | // and not the bottom of the html element |
| 2816 | if (offsetParent.nodeName === 'HTML') { |
| 2817 | top = -offsetParent.clientHeight + offsets.bottom; |
| 2818 | } else { |
| 2819 | top = -offsetParentRect.height + offsets.bottom; |
| 2820 | } |
| 2821 | } else { |
| 2822 | top = offsets.top; |
| 2823 | } |
| 2824 | if (sideB === 'right') { |
| 2825 | if (offsetParent.nodeName === 'HTML') { |
| 2826 | left = -offsetParent.clientWidth + offsets.right; |
nothing calls this directly
no test coverage detected