@@ -130,19 +130,38 @@ textAngular.directive("textAngular", [
130
130
$animate . addClass ( scope . displayElements . popover , 'in' ) ;
131
131
oneEvent ( $document . find ( 'body' ) , 'click keyup' , function ( ) { scope . hidePopover ( ) ; } ) ;
132
132
} ;
133
+ var getScrollTop = function ( _el ) {
134
+ var scrollTop = _el . scrollTop ;
135
+ if ( scrollTop !== 0 ) {
136
+ return { node :_el . nodeName , top :scrollTop } ;
137
+ }
138
+ /* istanbul ignore else: catches only if no scroll */
139
+ if ( _el . parentNode ) {
140
+ return getScrollTop ( _el . parentNode ) ;
141
+ } else {
142
+ return { node :'<none>' , top :0 } ;
143
+ }
144
+ } ;
133
145
scope . reflowPopover = function ( _el ) {
146
+ var scrollTop = getScrollTop ( scope . displayElements . scrollWindow [ 0 ] ) ;
147
+ var spaceAboveImage = _el [ 0 ] . offsetTop - scrollTop . top ;
148
+
134
149
/* istanbul ignore if: catches only if near bottom of editor */
135
- if ( scope . displayElements . text [ 0 ] . offsetHeight - 51 > _el [ 0 ] . offsetTop ) {
150
+ if ( spaceAboveImage < 51 ) {
136
151
scope . displayElements . popover . css ( 'top' , _el [ 0 ] . offsetTop + _el [ 0 ] . offsetHeight + scope . displayElements . scrollWindow [ 0 ] . scrollTop + 'px' ) ;
137
152
scope . displayElements . popover . removeClass ( 'top' ) . addClass ( 'bottom' ) ;
138
- } else {
153
+ } else {
139
154
scope . displayElements . popover . css ( 'top' , _el [ 0 ] . offsetTop - 54 + scope . displayElements . scrollWindow [ 0 ] . scrollTop + 'px' ) ;
140
155
scope . displayElements . popover . removeClass ( 'bottom' ) . addClass ( 'top' ) ;
141
156
}
142
157
var _maxLeft = scope . displayElements . text [ 0 ] . offsetWidth - scope . displayElements . popover [ 0 ] . offsetWidth ;
143
158
var _targetLeft = _el [ 0 ] . offsetLeft + ( _el [ 0 ] . offsetWidth / 2.0 ) - ( scope . displayElements . popover [ 0 ] . offsetWidth / 2.0 ) ;
144
- scope . displayElements . popover . css ( 'left' , Math . max ( 0 , Math . min ( _maxLeft , _targetLeft ) ) + 'px' ) ;
145
- scope . displayElements . popoverArrow . css ( 'margin-left' , ( Math . min ( _targetLeft , ( Math . max ( 0 , _targetLeft - _maxLeft ) ) ) - 11 ) + 'px' ) ;
159
+ var _rleft = Math . max ( 0 , Math . min ( _maxLeft , _targetLeft ) ) ;
160
+ var _marginLeft = ( Math . min ( _targetLeft , ( Math . max ( 0 , _targetLeft - _maxLeft ) ) ) - 11 ) ;
161
+ _rleft += window . scrollX ;
162
+ _marginLeft -= window . scrollX ;
163
+ scope . displayElements . popover . css ( 'left' , _rleft + 'px' ) ;
164
+ scope . displayElements . popoverArrow . css ( 'margin-left' , _marginLeft + 'px' ) ;
146
165
} ;
147
166
scope . hidePopover = function ( ) {
148
167
scope . displayElements . popover . css ( 'display' , 'none' ) ;
0 commit comments