Skip to content

Commit

Permalink
* Fixed issue jaz303#145 in jaz303/tipsy - tooltips inside fixed posi…
Browse files Browse the repository at this point in the history
…tioned container don't behave naturally.
  • Loading branch information
nerdo committed Apr 8, 2013
1 parent 3545aa6 commit 926cd11
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/javascripts/jquery.tipsy.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
width: this.$element[0].offsetWidth,
height: this.$element[0].offsetHeight
});

var inFixedContainer = this.$element.css("position") === "fixed"
|| this.$element.parents().filter(function(i) { return $(this).css("position") === "fixed"; }).length ? true : false;
if (inFixedContainer) {
pos.top -= $(window).scrollTop();
pos.left -= $(window).scrollLeft();
$tip.css("position", "fixed");
}

var actualWidth = $tip[0].offsetWidth,
actualHeight = $tip[0].offsetHeight,
Expand Down Expand Up @@ -240,19 +248,19 @@
* component.
*/
$.fn.tipsy.autoBounds = function(margin, prefer) {
return function() {
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
boundTop = $(document).scrollTop() + margin,
boundLeft = $(document).scrollLeft() + margin,
$this = $(this);
return function() {
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)},
boundTop = $(document).scrollTop() + margin,
boundLeft = $(document).scrollLeft() + margin,
$this = $(this);

if ($this.offset().top < boundTop) dir.ns = 'n';
if ($this.offset().left < boundLeft) dir.ew = 'w';
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';
if ($this.offset().top < boundTop) dir.ns = 'n';
if ($this.offset().left < boundLeft) dir.ew = 'w';
if ($(window).width() + $(document).scrollLeft() - $this.offset().left < margin) dir.ew = 'e';
if ($(window).height() + $(document).scrollTop() - $this.offset().top < margin) dir.ns = 's';

return dir.ns + (dir.ew ? dir.ew : '');
}
};
return dir.ns + (dir.ew ? dir.ew : '');
}
};

})(jQuery);

0 comments on commit 926cd11

Please sign in to comment.