From 5e9535e1f0a041a1fcd923685548c09d2a486253 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 19 Feb 2018 07:52:01 -0800 Subject: [PATCH] Correctly calculate offset when popup is in a different positioning context --- RELEASE-NOTES.md | 3 +++ src/definitions/modules/popup.js | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2193cfd3d..c09e796ed 100755 --- a/RELEASE-NOTES.md +++ b/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` diff --git a/src/definitions/modules/popup.js b/src/definitions/modules/popup.js index f97fa1514..b27e48c85 100644 --- a/src/definitions/modules/popup.js +++ b/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 = {