Browse Source

Correctly calculate offset when popup is in a different positioning context

centered-modal
Jack 7 years ago
parent
commit
5e9535e1f0
2 changed files with 18 additions and 3 deletions
  1. 3
      RELEASE-NOTES.md
  2. 18
      src/definitions/modules/popup.js

3
RELEASE-NOTES.md

@ -2,6 +2,9 @@
### Version 2.3.0 - Feb 19, 2018
**Enhancements**
- **Popup** - Popup can now position elements correctly even when they have a different offset context than their activating element. Like in [this example](https://jsfiddle.net/g853mc03/)
**Bugs**
- **Modal** - Modal `autofocus` setting now checks to see if currently focused element is in modal, avoiding issues where focus could be set in `onVisible` or `onShow`

18
src/definitions/modules/popup.js

@ -502,9 +502,10 @@ $.fn.popup = function(parameters) {
},
calculations: function() {
var
targetElement = $target[0],
isWindow = ($boundary[0] == window),
targetPosition = (settings.inline || (settings.popup && settings.movePopup))
$popupOffsetParent = module.get.offsetParent($popup),
targetElement = $target[0],
isWindow = ($boundary[0] == window),
targetPosition = (settings.inline || (settings.popup && settings.movePopup))
? $target.position()
: $target.offset(),
screenPosition = (isWindow)
@ -549,6 +550,17 @@ $.fn.popup = function(parameters) {
}
};
// if popup offset context is not same as target, then adjust calculations
if($popupOffsetParent.get(0) !== $offsetParent.get(0)) {
var
popupOffset = $popupOffsetParent.offset()
;
calculations.target.top -= popupOffset.top;
calculations.target.left -= popupOffset.left;
calculations.parent.width = $popupOffsetParent.outerWidth();
calculations.parent.height = $popupOffsetParent.outerHeight();
}
// add in container calcs if fluid
if( settings.setFluidWidth && module.is.fluid() ) {
calculations.container = {

Loading…
Cancel
Save