Skip to content

Commit

Permalink
Refresh tooltip after any change in the content, as stated by issue
Browse files Browse the repository at this point in the history
angular-ui#96. Essentially hides the
tooltip and shows it again if it was open.
  • Loading branch information
ventuc committed Dec 9, 2013
1 parent 93cd0df commit 24c0e01
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
* Returns the actual instance of the $tooltip service.
* TODO support multiple triggers
*/
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', '$interpolate', function ( $window, $compile, $timeout, $parse, $document, $position, $interpolate ) {
this.$get = [ '$window', '$compile', '$timeout', '$parse', '$document', '$position', '$interpolate', '$q', function ( $window, $compile, $timeout, $parse, $document, $position, $interpolate, $q ) {
return function $tooltip ( type, prefix, defaultTriggerShow ) {
var options = angular.extend( {}, defaultOptions, globalOptions );

Expand Down Expand Up @@ -225,32 +225,44 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

// Hide the tooltip popup element.
function hide() {
var deferred = $q.defer();

// First things first: we don't show it anymore.
scope.tt_isOpen = false;

//if tooltip is going to be shown after delay, we must cancel this
$timeout.cancel( popupTimeout );

// And now we remove it from the DOM. However, if we have animation, we
// need to wait for it to expire beforehand.
// FIXME: this is a placeholder for a port of the transitions library.
if ( scope.tt_animation ) {
transitionTimeout = $timeout(function () {
tooltip.remove();
deferred.resolve();
}, 500);
} else {
tooltip.remove();
deferred.resolve();
}

return deferred.promise;
}

/**
* Observe the relevant attributes.
*/
attrs.$observe( type, function ( val ) {
scope.tt_content = val;

if (!val && scope.tt_isOpen ) {
hide();
if (scope.tt_isOpen){
hide().then(function(){
scope.tt_content = val;
if (val){
$timeout(show, 0);
}
});
}
else {
scope.tt_content = val;
}
});

Expand Down

0 comments on commit 24c0e01

Please sign in to comment.