Browse Source

Add arrow centering on small popups

centered-modal
Jack 7 years ago
parent
commit
0f464a6ca1
2 changed files with 30 additions and 4 deletions
  1. 1
      RELEASE-NOTES.md
  2. 33
      src/definitions/modules/popup.js

1
RELEASE-NOTES.md

@ -3,6 +3,7 @@
### Version 2.3.0 - Feb 19, 2018
**Enhancements**
- **Popup** - Popup will now align the center of the arrow (not the edge of the popup) when it would be reasonable (up to 2x arrow's offset from edge). [See this explanation](http://oi66.tinypic.com/2zr2ckk.jpg)
- **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**

33
src/definitions/modules/popup.js

@ -649,14 +649,14 @@ $.fn.popup = function(parameters) {
var
is2D = ($node.css('transform') === 'none'),
isStatic = ($node.css('position') === 'static'),
isHTML = $node.is('html')
isBody = $node.is('body')
;
while(parentNode && !isHTML && isStatic && is2D) {
while(parentNode && !isBody && isStatic && is2D) {
parentNode = parentNode.parentNode;
$node = $(parentNode);
is2D = ($node.css('transform') === 'none');
isStatic = ($node.css('position') === 'static');
isHTML = $node.is('html');
isBody = $node.is('body');
}
}
return ($node && $node.length > 0)
@ -765,6 +765,18 @@ $.fn.popup = function(parameters) {
popup = calculations.popup;
parent = calculations.parent;
if(module.should.centerArrow(calculations)) {
module.verbose('Adjusting offset to center arrow on small target element');
if(position == 'top left' || position == 'bottom left') {
offset += (target.width / 2)
offset -= settings.arrowPixelsFromEdge;
}
if(position == 'top right' || position == 'bottom right') {
offset -= (target.width / 2)
offset += settings.arrowPixelsFromEdge;
}
}
if(target.width === 0 && target.height === 0 && !module.is.svg(target.element)) {
module.debug('Popup target is hidden, no action taken');
return false;
@ -1058,6 +1070,12 @@ $.fn.popup = function(parameters) {
}
},
should: {
centerArrow: function(calculations) {
return !module.is.basic() && calculations.target.width <= (settings.arrowPixelsFromEdge * 2);
}
},
is: {
offstage: function(distanceFromBoundary, position) {
var
@ -1080,6 +1098,9 @@ $.fn.popup = function(parameters) {
svg: function(element) {
return module.supports.svg() && (element instanceof SVGGraphicsElement);
},
basic: function() {
return $module.hasClass(className.basic);
},
active: function() {
return $module.hasClass(className.active);
},
@ -1392,8 +1413,11 @@ $.fn.popup.settings = {
// specify position to appear even if it doesn't fit
lastResort : false,
// number of pixels from edge of popup to pointing arrow center (used from centering)
arrowPixelsFromEdge: 20,
// delay used to prevent accidental refiring of animations due to user error
delay : {
delay : {
show : 50,
hide : 70
},
@ -1437,6 +1461,7 @@ $.fn.popup.settings = {
className : {
active : 'active',
basic : 'basic',
animating : 'animating',
dropdown : 'dropdown',
fluid : 'fluid',

Loading…
Cancel
Save