| 1 |
/** |
| 2 |
* @function |
| 3 |
* @memberof Modifiers |
| 4 |
* @argument {Object} data - The data object generated by update method |
| 5 |
* @argument {Object} options - Modifiers configuration and options |
| 6 |
* @returns {Object} The data object, properly modified |
| 7 |
*/ |
| 8 |
export default function keepTogether(data) { |
| 9 |
const { popper, reference } = data.offsets; |
| 10 |
const placement = data.placement.split('-')[0]; |
| 11 |
const floor = Math.floor; |
| 12 |
const isVertical = ['top', 'bottom'].indexOf(placement) !== -1; |
| 13 |
const side = isVertical ? 'right' : 'bottom'; |
| 14 |
const opSide = isVertical ? 'left' : 'top'; |
| 15 |
const measurement = isVertical ? 'width' : 'height'; |
| 16 |
|
| 17 |
if (popper[side] < floor(reference[opSide])) { |
| 18 |
data.offsets.popper[opSide] = |
| 19 |
floor(reference[opSide]) - popper[measurement]; |
| 20 |
} |
| 21 |
if (popper[opSide] > floor(reference[side])) { |
| 22 |
data.offsets.popper[opSide] = floor(reference[side]); |
| 23 |
} |
| 24 |
|
| 25 |
return data; |
| 26 |
} |