Skip to content
Browse files

Fixed mouse positioning

  • Loading branch information...
1 parent a899678 commit 5920d4a6dd4058dfa8f0fd54327dc917f3d4b23d Brian Cray committed May 13, 2011
Showing with 9 additions and 3 deletions.
  1. +2 −1 tooltipsy.min.js
  2. +7 −2 tooltipsy.source.js
View
3 tooltipsy.min.js
@@ -13,7 +13,8 @@
(function($){$.tooltipsy=function(el,options){var base=this;base.$el=$(el);base.el=el;base.random=parseInt(Math.random()*10000);base.shown=false;base.width=0;base.height=0;base.$el.data("tooltipsy",base);base.init=function(){base.settings=$.extend({},$.tooltipsy.defaults,options);base.$el.bind('mouseenter',function(e){if(base.shown==false){base.shown=true;base.title=base.$el.attr('title')||'';base.$el.attr('title','');base.$tipsy=$('<div id="tooltipsy'+base.random+'">').appendTo('body').css({position:'absolute',zIndex:'999'}).hide();base.$tip=$('<div class="'+base.settings.className+'">').appendTo(base.$tipsy).html(base.settings.content!=''?base.settings.content:base.title);if((function(o){var s=0,k;for(k in o){if(o.hasOwnProperty(k)){s++;}}
return s;})(base.settings.css)>0){base.$tip.css(base.settings.css);}
base.width=base.$tipsy.outerWidth();base.height=base.$tipsy.outerHeight();}
-if(base.settings.alignTo=='cursor'){var tip_position=[e.pageX-window.pageXOffset+base.settings.offset[0],e.pageY-window.pageYOffset+base.settings.offset[1]];var tip_css={top:tip_position[1]+'px',right:$(window).width()-tip_position[0]+'px',left:'auto'};}
+if(base.settings.alignTo=='cursor'){var tip_position=[e.pageX+base.settings.offset[0],e.pageY+base.settings.offset[1]];if(tip_position[0]+base.width>$(window).width())){var tip_css={top:tip_position[1]+'px',right:tip_position[0]+'px',left:'auto'};}
+else{var tip_css={top:tip_position[1]+'px',left:tip_position[0]+'px',right:'auto'};}}
else{var tip_position=[(function(pos){if(base.settings.offset[0]<0){return pos.left-Math.abs(base.settings.offset[0])-base.width;}
else if(base.settings.offset[0]==0){return pos.left-((base.width-base.$el.outerWidth())/2);}
else{return pos.left+base.$el.outerWidth()+base.settings.offset[0];}})(base.$el.offset()),(function(pos){if(base.settings.offset[1]<0){return pos.top-Math.abs(base.settings.offset[1])-base.height;}
View
9 tooltipsy.source.js
@@ -50,8 +50,13 @@
}
if (base.settings.alignTo == 'cursor') {
- var tip_position = [e.pageX - window.pageXOffset + base.settings.offset[0], e.pageY - window.pageYOffset + base.settings.offset[1]];
- var tip_css = {top: tip_position[1] + 'px', right: $(window).width() - tip_position[0] + 'px', left: 'auto'};
+ var tip_position = [e.pageX + base.settings.offset[0], e.pageY + base.settings.offset[1]];
+ if(tip_position[0] + base.width > $(window).width())) {
+ var tip_css = {top: tip_position[1] + 'px', right: tip_position[0] + 'px', left: 'auto'};
+ }
+ else {
+ var tip_css = {top: tip_position[1] + 'px', left: tip_position[0] + 'px', right: 'auto'};
+ }
}
else {
var tip_position = [

0 comments on commit 5920d4a

Please sign in to comment.
Something went wrong with that request. Please try again.