From: Kevin Ball Date: Thu, 25 May 2017 05:06:41 +0000 (-0700) Subject: Change offset behavior in centered case to make it more intuitive, get tooltips behav... X-Git-Tag: v6.4.0-rc1~19^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db3ecbde613e648b607dbd110c558f07a05410a1;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Change offset behavior in centered case to make it more intuitive, get tooltips behaving properly --- diff --git a/js/foundation.positionable.js b/js/foundation.positionable.js index 81dcea57d..4fde158d0 100644 --- a/js/foundation.positionable.js +++ b/js/foundation.positionable.js @@ -101,13 +101,36 @@ class Positionable extends Plugin { } + // When we're trying to center, we don't want to apply offset that's going to + // take us just off center, so wrap around to return 0 for the appropriate + // offset in those alignments. TODO: Figure out if we want to make this + // configurable behavior... it feels more intuitive, especially for tooltips, but + // it's possible someone might actually want to start from center and then nudge + // slightly off. + _getVOffset() { + if(this.alignment === 'center' && (this.position === 'left' || this.position === 'right')) { + return 0; + } else { + return this.options.vOffset; + } + } + + _getHOffset() { + if(this.alignment === 'center' && (this.position === 'top' || this.position === 'bottom')) { + return 0; + } else { + return this.options.hOffset; + } + } + + _setPosition($anchor, $element, $parent) { if($anchor.attr('aria-expanded') === 'false'){ return false; } var $eleDims = Box.GetDimensions($element), $anchorDims = Box.GetDimensions($anchor); - $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this.options.vOffset, this.options.hOffset)); + $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this._getVOffset(), this._getHOffset())); if(!this.options.allowOverlap) { var overlaps = {}; @@ -127,13 +150,13 @@ class Positionable extends Plugin { this._reposition(); - $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this.options.vOffset, this.options.hOffset)); + $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this._getVOffset(), this._getHOffset())); } // If we get through the entire loop, there was no non-overlapping // position available. Pick the version with least overlap. this.position = minCoordinates.position; this.alignment = minCoordinates.alignment; - $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this.options.vOffset, this.options.hOffset)); + $element.offset(Box.GetExplicitOffsets($element, $anchor, this.position, this.alignment, this._getVOffset(), this._getHOffset())); } } diff --git a/test/visual/dropdown/offsets.html b/test/visual/dropdown/offsets.html index 25ec2a8e0..cbc3f0a94 100644 --- a/test/visual/dropdown/offsets.html +++ b/test/visual/dropdown/offsets.html @@ -11,7 +11,7 @@

Dropdown: Explicit Positioning Content - with offsets

-

These dropdowns test various positioning and alignments WITH OFFSETS. +

These dropdowns test various positioning and alignments WITH OFFSETS. Valid positions are left/right/top/bottom. Valid alignments are left/right/top/bottom/center. Left align means left sides should line up. Right align means right sides should line up. Center align means centers should line up. @@ -33,7 +33,7 @@

Bottom Center

@@ -57,7 +57,7 @@

Top Center

@@ -92,14 +92,14 @@

Right Center

Left Center