Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Simple viewport edge detection #52

Open
wants to merge 1 commit into from

1 participant

@jeffplang

I've added another gravity parameter, 'a' (for 'auto'), to be used along with 'n' or 's'. Since there is no clean way to grab the width of the tooltip div, I've implemented this as a gravity parameter rather than using the gravity callback. If either the left or right edge of the tooltip falls out of the viewport, the 'e' or 'w' param replaces the 'a', otherwise the 'a' is removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/javascripts/jquery.tipsy.js
View
12 src/javascripts/jquery.tipsy.js
@@ -52,9 +52,19 @@
}
if (gravity.length == 2) {
+ if (gravity.charAt(1) == 'a') {
+ var autoDir = '';
+ if (tp.left < 0) {
+ autoDir = 'w';
+ } else if ( tp.left + actualWidth > $(window).width() + $(document).scrollLeft() ) {
+ autoDir = 'e';
+ }
+ gravity = gravity.charAt(0) + autoDir;
+ }
+
if (gravity.charAt(1) == 'w') {
tp.left = pos.left + pos.width / 2 - 15;
- } else {
+ } else if (gravity.charAt(1) == 'e') {
tp.left = pos.left + pos.width / 2 - actualWidth + 15;
}
}
Something went wrong with that request. Please try again.