* @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)
| 4524 | */ |
| 4525 | |
| 4526 | function flip(data, options) { |
| 4527 | // if `inner` modifier is enabled, we can't use the `flip` modifier |
| 4528 | if (isModifierEnabled(data.instance.modifiers, 'inner')) { |
| 4529 | return data; |
| 4530 | } |
| 4531 | |
| 4532 | if (data.flipped && data.placement === data.originalPlacement) { |
| 4533 | // seems like flip is trying to loop, probably there's not enough space on any of the flippable sides |
| 4534 | return data; |
| 4535 | } |
| 4536 | |
| 4537 | var boundaries = getBoundaries(data.instance.popper, data.instance.reference, options.padding, options.boundariesElement, data.positionFixed); |
| 4538 | var placement = data.placement.split('-')[0]; |
| 4539 | var placementOpposite = getOppositePlacement(placement); |
| 4540 | var variation = data.placement.split('-')[1] || ''; |
| 4541 | var flipOrder = []; |
| 4542 | |
| 4543 | switch (options.behavior) { |
| 4544 | case BEHAVIORS.FLIP: |
| 4545 | flipOrder = [placement, placementOpposite]; |
| 4546 | break; |
| 4547 | |
| 4548 | case BEHAVIORS.CLOCKWISE: |
| 4549 | flipOrder = clockwise(placement); |
| 4550 | break; |
| 4551 | |
| 4552 | case BEHAVIORS.COUNTERCLOCKWISE: |
| 4553 | flipOrder = clockwise(placement, true); |
| 4554 | break; |
| 4555 | |
| 4556 | default: |
| 4557 | flipOrder = options.behavior; |
| 4558 | } |
| 4559 | |
| 4560 | flipOrder.forEach(function (step, index) { |
| 4561 | if (placement !== step || flipOrder.length === index + 1) { |
| 4562 | return data; |
| 4563 | } |
| 4564 | |
| 4565 | placement = data.placement.split('-')[0]; |
| 4566 | placementOpposite = getOppositePlacement(placement); |
| 4567 | var popperOffsets = data.offsets.popper; |
| 4568 | var refOffsets = data.offsets.reference; // using floor because the reference offsets may contain decimals we are not going to consider here |
| 4569 | |
| 4570 | var floor = Math.floor; |
| 4571 | var overlapsRef = placement === 'left' && floor(popperOffsets.right) > floor(refOffsets.left) || placement === 'right' && floor(popperOffsets.left) < floor(refOffsets.right) || placement === 'top' && floor(popperOffsets.bottom) > floor(refOffsets.top) || placement === 'bottom' && floor(popperOffsets.top) < floor(refOffsets.bottom); |
| 4572 | var overflowsLeft = floor(popperOffsets.left) < floor(boundaries.left); |
| 4573 | var overflowsRight = floor(popperOffsets.right) > floor(boundaries.right); |
| 4574 | var overflowsTop = floor(popperOffsets.top) < floor(boundaries.top); |
| 4575 | var overflowsBottom = floor(popperOffsets.bottom) > floor(boundaries.bottom); |
| 4576 | var overflowsBoundaries = placement === 'left' && overflowsLeft || placement === 'right' && overflowsRight || placement === 'top' && overflowsTop || placement === 'bottom' && overflowsBottom; // flip the variation if required |
| 4577 | |
| 4578 | var isVertical = ['top', 'bottom'].indexOf(placement) !== -1; // flips variation if reference element overflows boundaries |
| 4579 | |
| 4580 | var flippedVariationByRef = !!options.flipVariations && (isVertical && variation === 'start' && overflowsLeft || isVertical && variation === 'end' && overflowsRight || !isVertical && variation === 'start' && overflowsTop || !isVertical && variation === 'end' && overflowsBottom); // flips variation if popper content overflows boundaries |
| 4581 | |
| 4582 | var flippedVariationByContent = !!options.flipVariationsByContent && (isVertical && variation === 'start' && overflowsRight || isVertical && variation === 'end' && overflowsLeft || !isVertical && variation === 'start' && overflowsBottom || !isVertical && variation === 'end' && overflowsTop); |
| 4583 | var flippedVariation = flippedVariationByRef || flippedVariationByContent; |
nothing calls this directly
no test coverage detected
searching dependent graphs…