@@ -18,9 +18,8 @@ import { PositionData } from './Types/PositionData';
1818 * @returns object with a top and left value in the form `{number}px`
1919 */
2020function position ( options : IOptions ) : PositionData {
21- const { _bodyRect, _anchorRect, _targetRect, scrollableParents } = initialisePrivateFields ( ) ;
22-
23- const myPos = Helpers . parse (
21+ const { _bodyRect, _anchorRect, _targetRect } = initialisePrivateFields ( ) ,
22+ myPos = Helpers . parse (
2423 options . my ,
2524 options . defaults
2625 ? Helpers . parse ( options . defaults . my )
@@ -44,7 +43,6 @@ function position(options: IOptions): PositionData {
4443 return {
4544 left : calculateLeft ( myPos , atPos ) . value . toString ( ) + 'px' ,
4645 top : calculateTop ( myPos , atPos ) . value . toString ( ) + 'px' ,
47- scrollableParents,
4846 // @ts -ignore
4947 ...( options . debug === true
5048 ? { _bodyRect, _anchorRect, _targetRect }
@@ -57,7 +55,6 @@ function position(options: IOptions): PositionData {
5755 return {
5856 top : pos . top . toString ( ) + 'px' ,
5957 left : pos . left . toString ( ) + 'px' ,
60- scrollableParents,
6158 // @ts -ignore
6259 ...( options . debug === true
6360 ? { _bodyRect, _anchorRect, _targetRect }
@@ -81,41 +78,33 @@ function position(options: IOptions): PositionData {
8178 return '{}' ;
8279 } ,
8380 }
84- : options . anchor . getBoundingClientRect ( ) ;
81+ : options . anchor . getBoundingClientRect ( ) ,
82+ originalDisplay = options . target . style . display ,
83+ _targetRect = options . target . getBoundingClientRect ( ) ;
8584
86- const originalDisplay = options . target . style . display ;
8785 options . target . style . display = 'block' ;
88-
89- const _targetRect = options . target . getBoundingClientRect ( ) ,
90- scrollableParents : HTMLElement [ ] = [ ] ;
91-
9286 options . target . style . display = originalDisplay ;
9387
9488 // Adjust to scrollable regions
9589 if ( options . anchor instanceof HTMLElement ) {
96- let parent = options . anchor . parentElement ;
97-
98- while ( parent !== null && parent . tagName !== 'HTML' ) {
99- // Check if scrollable
100- if ( parent . scrollHeight > parent . clientHeight )
101- scrollableParents . push ( parent )
102-
103- parent = parent . parentElement ;
104- }
105-
10690 // Finally, adjust for window scroll position
10791 const doc = document . documentElement ;
10892 _anchorRect . y +=
109- ( window . scrollY || doc . scrollTop ) - ( doc . clientTop || 0 ) ;
93+ ( window . scrollY ||
94+ document . documentElement . scrollTop ||
95+ document . body . scrollTop ||
96+ 0 ) - ( doc . clientTop || 0 ) ;
11097 _anchorRect . x +=
111- ( window . scrollX || doc . scrollLeft ) - ( doc . clientLeft || 0 ) ;
98+ ( window . scrollX ||
99+ document . documentElement . scrollLeft ||
100+ document . body . scrollLeft ||
101+ 0 ) - ( doc . clientLeft || 0 ) ;
112102 }
113103
114104 return {
115105 _bodyRect,
116106 _anchorRect,
117107 _targetRect,
118- scrollableParents
119108 } ;
120109 }
121110
0 commit comments