Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
* $tooltipProvider.options( { placement: 'left' } );
* });
*/
this.options = function( value ) {
angular.extend( globalOptions, value );
};
this.options = function( value ) {
angular.extend( globalOptions, value );
};

/**
* This allows you to extend the set of trigger mappings available. E.g.:
Expand Down Expand Up @@ -104,20 +104,22 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
var startSym = $interpolate.startSymbol();
var endSym = $interpolate.endSymbol();
var template =
'<'+ directiveName +'-popup '+
'title="'+startSym+'tt_title'+endSym+'" '+
'content="'+startSym+'tt_content'+endSym+'" '+
'placement="'+startSym+'tt_placement'+endSym+'" '+
'animation="tt_animation()" '+
'is-open="tt_isOpen"'+
'>'+
'</'+ directiveName +'-popup>';
'<div ' + directiveName + '-popup ' +
'title="' + startSym + 'tt_title' + endSym + '" ' +
'content="' + startSym + 'tt_content' + endSym + '" ' +
'placement="' + startSym + 'tt_placement' + endSym + '" ' +
'animation="tt_animation()" ' +
'is-open="tt_isOpen" ' +
'manual-hide="Hide()" ' +
'>' +
'</div>';

return {
restrict: 'EA',
scope: true,
link: function link ( scope, element, attrs ) {
var tooltip = $compile( template )( scope );
var isTooltipExist = false;
var transitionTimeout;
var popupTimeout;
var $body;
Expand Down Expand Up @@ -173,11 +175,16 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )

// Now we add it to the DOM because need some info about it. But it's not
// visible yet anyway.
if ( appendToBody ) {
$body = $body || $document.find( 'body' );
$body.append( tooltip );
// if tooltip is created, just show the old instance
if (!isTooltipExist) {
if ( appendToBody ) {
$body = $body || $document.find( 'body' );
$body.append( tooltip );
} else {
element.after( tooltip );
}
} else {
element.after( tooltip );
tooltip.show();
}

// Get the position of the directive element.
Expand Down Expand Up @@ -245,12 +252,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
// need to wait for it to expire beforehand.
// FIXME: this is a placeholder for a port of the transitions library.
if ( angular.isDefined( scope.tt_animation ) && scope.tt_animation() ) {
transitionTimeout = $timeout( function () { tooltip.remove(); }, 500 );
transitionTimeout = $timeout( function () { tooltip.hide(); }, 500 );
} else {
tooltip.remove();
//just hide the tooltip instead of remove it, otherwise tooltip need to compile again
tooltip.hide();
}
}

//expose the function to scope
scope.Hide = hide;
/**
* Observe the relevant attributes.
*/
Expand Down Expand Up @@ -309,7 +318,8 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position' ] )
if ( scope.tt_isOpen ) {
hide();
} else {
tooltip.remove();
// Not sure if we should use hide or remove here. if we use remove, tooltip need to recompile
tooltip.hide();
}
});
}
Expand Down