@@ -1172,106 +1172,111 @@ $.Tooltipster.prototype = {
11721172 }
11731173 else {
11741174
1175- // if the scroll happened on the window
1176- if ( event . target === env . window . document ) {
1175+ // if the origin or tooltip have been removed: do nothing, the tracker will
1176+ // take care of it later
1177+ if ( bodyContains ( self . _$origin ) && bodyContains ( self . _$tooltip ) ) {
11771178
1178- // if the origin has a fixed lineage, window scroll will have no
1179- // effect on its position nor on the position of the tooltip
1180- if ( ! self . __Geometry . origin . fixedLineage ) {
1179+ // if the scroll happened on the window
1180+ if ( event . target === env . window . document ) {
11811181
1182- // we don't need to do anything unless repositionOnScroll is true
1183- // because the tooltip will already have moved with the window
1184- // (and of course with the origin)
1185- if ( self . __options . repositionOnScroll ) {
1186- self . reposition ( event ) ;
1182+ // if the origin has a fixed lineage, window scroll will have no
1183+ // effect on its position nor on the position of the tooltip
1184+ if ( ! self . __Geometry . origin . fixedLineage ) {
1185+
1186+ // we don't need to do anything unless repositionOnScroll is true
1187+ // because the tooltip will already have moved with the window
1188+ // (and of course with the origin)
1189+ if ( self . __options . repositionOnScroll ) {
1190+ self . reposition ( event ) ;
1191+ }
11871192 }
11881193 }
1189- }
1190- // if the scroll happened on another parent of the tooltip, it means
1191- // that it's in a scrollable area and now needs to have its position
1192- // adjusted or recomputed, depending ont the repositionOnScroll
1193- // option. Also, if the origin is partly hidden due to a parent that
1194- // hides its overflow, we'll just hide (not close) the tooltip.
1195- else {
1196-
1197- var g = self . __geometry ( ) ,
1198- overflows = false ;
1199-
1200- // a fixed position origin is not affected by the overflow hiding
1201- // of a parent
1202- if ( self . _$origin . css ( 'position' ) != 'fixed' ) {
1194+ // if the scroll happened on another parent of the tooltip, it means
1195+ // that it's in a scrollable area and now needs to have its position
1196+ // adjusted or recomputed, depending ont the repositionOnScroll
1197+ // option. Also, if the origin is partly hidden due to a parent that
1198+ // hides its overflow, we'll just hide (not close) the tooltip.
1199+ else {
12031200
1204- self . __$originParents . each ( function ( i , el ) {
1205-
1206- var $el = $ ( el ) ,
1207- overflowX = $el . css ( 'overflow-x' ) ,
1208- overflowY = $el . css ( 'overflow-y' ) ;
1201+ var g = self . __geometry ( ) ,
1202+ overflows = false ;
1203+
1204+ // a fixed position origin is not affected by the overflow hiding
1205+ // of a parent
1206+ if ( self . _$origin . css ( 'position' ) != 'fixed' ) {
12091207
1210- if ( overflowX != 'visible' || overflowY != 'visible' ) {
1208+ self . __$originParents . each ( function ( i , el ) {
12111209
1212- var bcr = el . getBoundingClientRect ( ) ;
1210+ var $el = $ ( el ) ,
1211+ overflowX = $el . css ( 'overflow-x' ) ,
1212+ overflowY = $el . css ( 'overflow-y' ) ;
12131213
1214- if ( overflowX != 'visible' ) {
1214+ if ( overflowX != 'visible' || overflowY != 'visible' ) {
1215+
1216+ var bcr = el . getBoundingClientRect ( ) ;
12151217
1216- if ( g . origin . windowOffset . left < bcr . left
1217- || g . origin . windowOffset . right > bcr . right
1218- ) {
1219- overflows = true ;
1220- return false ;
1218+ if ( overflowX != 'visible' ) {
1219+
1220+ if ( g . origin . windowOffset . left < bcr . left
1221+ || g . origin . windowOffset . right > bcr . right
1222+ ) {
1223+ overflows = true ;
1224+ return false ;
1225+ }
12211226 }
1222- }
1223-
1224- if ( overflowY != 'visible' ) {
12251227
1226- if ( g . origin . windowOffset . top < bcr . top
1227- || g . origin . windowOffset . bottom > bcr . bottom
1228- ) {
1229- overflows = true ;
1230- return false ;
1228+ if ( overflowY != 'visible' ) {
1229+
1230+ if ( g . origin . windowOffset . top < bcr . top
1231+ || g . origin . windowOffset . bottom > bcr . bottom
1232+ ) {
1233+ overflows = true ;
1234+ return false ;
1235+ }
12311236 }
12321237 }
1233- }
1234-
1235- // no need to go further if fixed, for the same reason as above
1236- if ( $el . css ( 'position' ) == 'fixed' ) {
1237- return false ;
1238- }
1239- } ) ;
1240- }
1241-
1242- if ( overflows ) {
1243- self . _$tooltip . css ( 'visibility' , 'hidden' ) ;
1244- }
1245- else {
1246- self . _$tooltip . css ( 'visibility' , 'visible' ) ;
1238+
1239+ // no need to go further if fixed, for the same reason as above
1240+ if ( $el . css ( 'position' ) == 'fixed' ) {
1241+ return false ;
1242+ }
1243+ } ) ;
1244+ }
12471245
1248- // reposition
1249- if ( self . __options . repositionOnScroll ) {
1250- self . reposition ( event ) ;
1246+ if ( overflows ) {
1247+ self . _$tooltip . css ( 'visibility' , 'hidden' ) ;
12511248 }
1252- // or just adjust offset
12531249 else {
1250+ self . _$tooltip . css ( 'visibility' , 'visible' ) ;
12541251
1255- // we have to use offset and not windowOffset because this way,
1256- // only the scroll distance of the scrollable areas are taken into
1257- // account (the scrolltop value of the main window must be
1258- // ignored since the tooltip already moves with it)
1259- var offsetLeft = g . origin . offset . left - self . __Geometry . origin . offset . left ,
1260- offsetTop = g . origin . offset . top - self . __Geometry . origin . offset . top ;
1261-
1262- // add the offset to the position initially computed by the display plugin
1263- self . _$tooltip . css ( {
1264- left : self . __lastPosition . coord . left + offsetLeft ,
1265- top : self . __lastPosition . coord . top + offsetTop
1266- } ) ;
1252+ // reposition
1253+ if ( self . __options . repositionOnScroll ) {
1254+ self . reposition ( event ) ;
1255+ }
1256+ // or just adjust offset
1257+ else {
1258+
1259+ // we have to use offset and not windowOffset because this way,
1260+ // only the scroll distance of the scrollable areas are taken into
1261+ // account (the scrolltop value of the main window must be
1262+ // ignored since the tooltip already moves with it)
1263+ var offsetLeft = g . origin . offset . left - self . __Geometry . origin . offset . left ,
1264+ offsetTop = g . origin . offset . top - self . __Geometry . origin . offset . top ;
1265+
1266+ // add the offset to the position initially computed by the display plugin
1267+ self . _$tooltip . css ( {
1268+ left : self . __lastPosition . coord . left + offsetLeft ,
1269+ top : self . __lastPosition . coord . top + offsetTop
1270+ } ) ;
1271+ }
12671272 }
12681273 }
1274+
1275+ self . _trigger ( {
1276+ type : 'scroll' ,
1277+ event : event
1278+ } ) ;
12691279 }
1270-
1271- self . _trigger ( {
1272- type : 'scroll' ,
1273- event : event
1274- } ) ;
12751280 }
12761281
12771282 return self ;
0 commit comments