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

Commit

Permalink
feat(tooltip): add ability to enable / disable tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
sohai authored and pkozlowski-opensource committed Oct 11, 2013
1 parent cf5c27a commit 5d9bd05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,38 @@ describe('tooltip', function() {
expect( elmBody.children().length ).toBe( 0 );
}));

describe('with specified enable expression', function() {

beforeEach(inject(function ($compile) {
scope.enable = false;
elmBody = $compile(angular.element(
'<div><span tooltip="tooltip text" tooltip-enable="enable">Selector Text</span></div>'
))(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();

}));

it('should not open ', inject(function () {

elm.trigger('mouseenter');
expect(elmScope.tt_isOpen).toBeFalsy();
expect(elmBody.children().length).toBe(1);

}));

it('should open', inject(function () {

scope.enable = true;
scope.$digest();
elm.trigger('mouseenter');
expect(elmScope.tt_isOpen).toBeTruthy();
expect(elmBody.children().length).toBe(2);

}));
});

describe('with specified popup delay', function () {

beforeEach(inject(function ($compile) {
Expand Down
4 changes: 4 additions & 0 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
var triggers = getTriggers( undefined );
var hasRegisteredTriggers = false;
var hasEnableExp = angular.isDefined(attrs[prefix+'Enable']);

// By default, the tooltip is not open.
// TODO add ability to start tooltip opened
Expand All @@ -131,6 +132,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

// Show the tooltip with delay if specified, otherwise show it immediately
function showTooltipBind() {
if(hasEnableExp && !scope.$eval(attrs[prefix+'Enable'])) {
return;
}
if ( scope.tt_popupDelay ) {
popupTimeout = $timeout( show, scope.tt_popupDelay );
} else {
Expand Down

0 comments on commit 5d9bd05

Please sign in to comment.