Skip to content

Commit

Permalink
Added the geo property to the scroll event to help use cases like #631
Browse files Browse the repository at this point in the history
  • Loading branch information
louisameline committed Mar 24, 2017
1 parent db67d09 commit d501619
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/js/tooltipster.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,8 @@ $.Tooltipster.prototype = {
// take care of it later
if (bodyContains(self._$origin) && bodyContains(self._$tooltip)) {

var geo = null;

// if the scroll happened on the window
if (event.target === env.window.document) {

Expand All @@ -1203,8 +1205,9 @@ $.Tooltipster.prototype = {
// hides its overflow, we'll just hide (not close) the tooltip.
else {

var g = self.__geometry(),
overflows = false;
geo = self.__geometry();

var overflows = false;

// a fixed position origin is not affected by the overflow hiding
// of a parent
Expand All @@ -1222,8 +1225,8 @@ $.Tooltipster.prototype = {

if (overflowX != 'visible') {

if ( g.origin.windowOffset.left < bcr.left
|| g.origin.windowOffset.right > bcr.right
if ( geo.origin.windowOffset.left < bcr.left
|| geo.origin.windowOffset.right > bcr.right
) {
overflows = true;
return false;
Expand All @@ -1232,8 +1235,8 @@ $.Tooltipster.prototype = {

if (overflowY != 'visible') {

if ( g.origin.windowOffset.top < bcr.top
|| g.origin.windowOffset.bottom > bcr.bottom
if ( geo.origin.windowOffset.top < bcr.top
|| geo.origin.windowOffset.bottom > bcr.bottom
) {
overflows = true;
return false;
Expand All @@ -1252,6 +1255,7 @@ $.Tooltipster.prototype = {
self._$tooltip.css('visibility', 'hidden');
}
else {

self._$tooltip.css('visibility', 'visible');

// reposition
Expand All @@ -1265,8 +1269,8 @@ $.Tooltipster.prototype = {
// only the scroll distance of the scrollable areas are taken into
// account (the scrolltop value of the main window must be
// ignored since the tooltip already moves with it)
var offsetLeft = g.origin.offset.left - self.__Geometry.origin.offset.left,
offsetTop = g.origin.offset.top - self.__Geometry.origin.offset.top;
var offsetLeft = geo.origin.offset.left - self.__Geometry.origin.offset.left,
offsetTop = geo.origin.offset.top - self.__Geometry.origin.offset.top;

// add the offset to the position initially computed by the display plugin
self._$tooltip.css({
Expand All @@ -1279,7 +1283,8 @@ $.Tooltipster.prototype = {

self._trigger({
type: 'scroll',
event: event
event: event,
geo: geo
});
}
}
Expand Down

0 comments on commit d501619

Please sign in to comment.