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

feat(tooltip): Add isOpen to tooltip level for toggle of tooltip #2148

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions src/popover/test/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ describe('popover', function() {
expect( elmScope.tt_isOpen ).toBe( false );
}));

it('should open on isOpen change', inject(function($compile, $timeout) {
scope.popIsOpen = false;

// Localize our tests to a specific element
var elmBody = $compile( angular.element(
'<div><span popover="popover text" popover-is-open="{{ popIsOpen }}">Selector Text</span></div>'
) )( scope );
scope.$apply();

var elm = elmBody.find('span');
var elmScope = elm.scope();

expect( elmScope.tt_isOpen ).toBe( false );

scope.popIsOpen = true;
scope.$apply();

expect( elmScope.tt_isOpen ).toBe( true );

}));

it('should not unbind event handlers created by other directives - issue 456', inject( function( $compile ) {

scope.click = function() {
Expand Down
23 changes: 21 additions & 2 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

// And show the tooltip.
scope.tt_isOpen = true;
scope.$digest(); // digest required as $apply is not called

// Check to see if we're being called from an $observe call
if (!scope.$$phase) {

// digest required as $apply is not called
scope.$digest();
}

// Return positioning function as promise callback for correct
// positioning after draw.
Expand Down Expand Up @@ -234,7 +240,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
tooltip = tooltipLinker(scope, function () {});

// Get contents rendered into the tooltip
scope.$digest();
if (!scope.$$phase) {
scope.$digest();
}
}

function removeTooltip() {
Expand Down Expand Up @@ -305,6 +313,17 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
});
}

attrs.$observe( prefix+'IsOpen', function ( val ) {
var isOpen = angular.isDefined( val ) ? $parse( val )( scope ) : false;

// show and hide will set tt_isOpen for us
if (isOpen) {
show();
} else {
hide();
}
});

// Make sure tooltip is destroyed and removed.
scope.$on('$destroy', function onDestroyTooltip() {
$timeout.cancel( transitionTimeout );
Expand Down