Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(tooltip): re-position tooltip after draw
Browse files Browse the repository at this point in the history
Closes #944
  • Loading branch information
kkruit authored and pkozlowski-opensource committed Dec 26, 2013
1 parent 53f3e67 commit bead840
Showing 1 changed file with 58 additions and 47 deletions.
105 changes: 58 additions & 47 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
var hasRegisteredTriggers = false;
var hasEnableExp = angular.isDefined(attrs[prefix+'Enable']);

var positionTooltip = function (){
var position,
ttWidth,
ttHeight,
ttPosition;
// Get the position of the directive element.
position = appendToBody ? $position.offset( element ) : $position.position( element );

// Get the height and width of the tooltip so we can center it.
ttWidth = tooltip.prop( 'offsetWidth' );
ttHeight = tooltip.prop( 'offsetHeight' );

// Calculate the tooltip's top and left coordinates to center it with
// this directive.
switch ( scope.tt_placement ) {
case 'right':
ttPosition = {
top: position.top + position.height / 2 - ttHeight / 2,
left: position.left + position.width
};
break;
case 'bottom':
ttPosition = {
top: position.top + position.height,
left: position.left + position.width / 2 - ttWidth / 2
};
break;
case 'left':
ttPosition = {
top: position.top + position.height / 2 - ttHeight / 2,
left: position.left - ttWidth
};
break;
default:
ttPosition = {
top: position.top - ttHeight,
left: position.left + position.width / 2 - ttWidth / 2
};
break;
}

ttPosition.top += 'px';
ttPosition.left += 'px';

// Now set the calculated positioning.
tooltip.css( ttPosition );

};

// By default, the tooltip is not open.
// TODO add ability to start tooltip opened
scope.tt_isOpen = false;
Expand All @@ -136,8 +185,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
}
if ( scope.tt_popupDelay ) {
popupTimeout = $timeout( show, scope.tt_popupDelay );
popupTimeout.then(function(reposition){reposition();});
} else {
scope.$apply( show );
scope.$apply( show )();
}
}

Expand All @@ -149,14 +199,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

// Show the tooltip popup element.
function show() {
var position,
ttWidth,
ttHeight,
ttPosition;


// Don't show empty tooltips.
if ( ! scope.tt_content ) {
return;
return angular.noop;
}

// If there is a pending remove transition, we must cancel it, lest the
Expand All @@ -176,50 +223,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
element.after( tooltip );
}

// Get the position of the directive element.
position = appendToBody ? $position.offset( element ) : $position.position( element );

// Get the height and width of the tooltip so we can center it.
ttWidth = tooltip.prop( 'offsetWidth' );
ttHeight = tooltip.prop( 'offsetHeight' );

// Calculate the tooltip's top and left coordinates to center it with
// this directive.
switch ( scope.tt_placement ) {
case 'right':
ttPosition = {
top: position.top + position.height / 2 - ttHeight / 2,
left: position.left + position.width
};
break;
case 'bottom':
ttPosition = {
top: position.top + position.height,
left: position.left + position.width / 2 - ttWidth / 2
};
break;
case 'left':
ttPosition = {
top: position.top + position.height / 2 - ttHeight / 2,
left: position.left - ttWidth
};
break;
default:
ttPosition = {
top: position.top - ttHeight,
left: position.left + position.width / 2 - ttWidth / 2
};
break;
}

ttPosition.top += 'px';
ttPosition.left += 'px';
positionTooltip();

// Now set the calculated positioning.
tooltip.css( ttPosition );

// And show the tooltip.
scope.tt_isOpen = true;

// Return positioning function as promise callback for correct
// positioning after draw.
return positionTooltip;
}

// Hide the tooltip popup element.
Expand Down

0 comments on commit bead840

Please sign in to comment.