* @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)
| 4250 | */ |
| 4251 | |
| 4252 | function computeStyle(data, options) { |
| 4253 | var x = options.x, |
| 4254 | y = options.y; |
| 4255 | var popper = data.offsets.popper; // Remove this legacy support in Popper.js v2 |
| 4256 | |
| 4257 | var legacyGpuAccelerationOption = find(data.instance.modifiers, function (modifier) { |
| 4258 | return modifier.name === 'applyStyle'; |
| 4259 | }).gpuAcceleration; |
| 4260 | |
| 4261 | if (legacyGpuAccelerationOption !== undefined) { |
| 4262 | console.warn('WARNING: `gpuAcceleration` option moved to `computeStyle` modifier and will not be supported in future versions of Popper.js!'); |
| 4263 | } |
| 4264 | |
| 4265 | var gpuAcceleration = legacyGpuAccelerationOption !== undefined ? legacyGpuAccelerationOption : options.gpuAcceleration; |
| 4266 | var offsetParent = getOffsetParent(data.instance.popper); |
| 4267 | var offsetParentRect = getBoundingClientRect(offsetParent); // Styles |
| 4268 | |
| 4269 | var styles = { |
| 4270 | position: popper.position |
| 4271 | }; |
| 4272 | var offsets = getRoundedOffsets(data, window.devicePixelRatio < 2 || !isFirefox); |
| 4273 | var sideA = x === 'bottom' ? 'top' : 'bottom'; |
| 4274 | var sideB = y === 'right' ? 'left' : 'right'; // if gpuAcceleration is set to `true` and transform is supported, |
| 4275 | // we use `translate3d` to apply the position to the popper we |
| 4276 | // automatically use the supported prefixed version if needed |
| 4277 | |
| 4278 | var prefixedProperty = getSupportedPropertyName('transform'); // now, let's make a step back and look at this code closely (wtf?) |
| 4279 | // If the content of the popper grows once it's been positioned, it |
| 4280 | // may happen that the popper gets misplaced because of the new content |
| 4281 | // overflowing its reference element |
| 4282 | // To avoid this problem, we provide two options (x and y), which allow |
| 4283 | // the consumer to define the offset origin. |
| 4284 | // If we position a popper on top of a reference element, we can set |
| 4285 | // `x` to `top` to make the popper grow towards its top instead of |
| 4286 | // its bottom. |
| 4287 | |
| 4288 | var left = void 0, |
| 4289 | top = void 0; |
| 4290 | |
| 4291 | if (sideA === 'bottom') { |
| 4292 | // when offsetParent is <html> the positioning is relative to the bottom of the screen (excluding the scrollbar) |
| 4293 | // and not the bottom of the html element |
| 4294 | if (offsetParent.nodeName === 'HTML') { |
| 4295 | top = -offsetParent.clientHeight + offsets.bottom; |
| 4296 | } else { |
| 4297 | top = -offsetParentRect.height + offsets.bottom; |
| 4298 | } |
| 4299 | } else { |
| 4300 | top = offsets.top; |
| 4301 | } |
| 4302 | |
| 4303 | if (sideB === 'right') { |
| 4304 | if (offsetParent.nodeName === 'HTML') { |
| 4305 | left = -offsetParent.clientWidth + offsets.right; |
| 4306 | } else { |
| 4307 | left = -offsetParentRect.width + offsets.right; |
| 4308 | } |
| 4309 | } else { |
nothing calls this directly
no test coverage detected
searching dependent graphs…