Skip to content

Commit

Permalink
Added viewable region bounds checking to tipsy
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Gibbons committed Nov 21, 2010
1 parent fa497c1 commit 5a8253f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/javascripts/jquery.tipsy.js
Expand Up @@ -198,5 +198,30 @@
$.fn.tipsy.autoWE = function() {
return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
};

$.fn.tipsy.autoBounds = function(margin, prefer) {
return function()
{
var dir = { ns: prefer[0], ew: (prefer.length > 1 ? prefer[1] : false) }

bound_top = $(document).scrollTop() + margin;
bound_left = $(document).scrollLeft() + margin;

if ( $(this).offset().top < bound_top) {
dir.ns = 'n';
}
if ( $(this).offset().left < bound_left ) {
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 : '');
}
};

})(jQuery);

0 comments on commit 5a8253f

Please sign in to comment.