Created
December 14, 2011 16:01
-
-
Save voxpelli/1477163 to your computer and use it in GitHub Desktop.
Improved autoBounds function for Tipsy.js that takes the size of the tooltip into account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var autoBoundsImproved = function (margin, prefer) { | |
return function () { | |
var dir = {ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false)}, | |
$document = $(document), | |
$window = $(window), | |
$this = $(this), | |
$tip = $this.tipsy(true).$tip, | |
options = $this.tipsy(true).options, | |
marginTop, marginLeft, boundTop, boundLeft; | |
marginTop = $tip.outerHeight() + margin; | |
marginLeft = $tip.outerWidth() + margin; | |
boundTop = $document.scrollTop() + marginTop; | |
boundLeft = $document.scrollLeft() + marginLeft; | |
if ($this.offset().top < boundTop) dir.ns = 'n'; | |
if ($this.offset().left < boundLeft) dir.ew = 'w'; | |
if ($window.width() + $document.scrollLeft() - $this.offset().left < marginLeft) dir.ew = 'e'; | |
if ($window.height() + $document.scrollTop() - $this.offset().top < marginTop) dir.ns = 's'; | |
return dir.ns + (dir.ew ? dir.ew : ''); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I needed. I consider the old function really a bug!
P.S. You don't need the options here, so why include them?