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

Tooltip :: Enable ngModel to use parent scope #2151

Closed
wants to merge 5 commits 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
2 changes: 1 addition & 1 deletion src/popover/test/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('popover', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();
}));

it('should not be open initially', inject(function() {
Expand Down
42 changes: 21 additions & 21 deletions src/tooltip/test/tooltip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('tooltip', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();
}));

it('should not be open initially', inject(function() {
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('tooltip', function() {
'<span tooltip="tooltip text" tooltip-placement="bottom">Selector Text</span>'
) )( scope );
scope.$apply();
elmScope = elm.scope();
elmScope = elm.isolateScope();

elm.trigger( 'mouseenter' );
expect( elmScope.tt_placement ).toBe( 'bottom' );
Expand All @@ -86,7 +86,7 @@ describe('tooltip', function() {
tt.trigger( 'mouseenter' );

expect( tt.text() ).toBe( scope.items[0].name );
expect( tt.scope().tt_content ).toBe( scope.items[0].tooltip );
expect( tt.isolateScope().tt_content ).toBe( scope.items[0].tooltip );

tt.trigger( 'mouseleave' );
}));
Expand All @@ -104,7 +104,7 @@ describe('tooltip', function() {
$compile( elmBody )( scope );
scope.$digest();
elm = elmBody.find( 'span' );
elmScope = elm.scope();
elmScope = elm.isolateScope();

elm.trigger( 'mouseenter' );
expect( elm.attr( 'alt' ) ).toBe( scope.alt );
Expand Down Expand Up @@ -166,11 +166,11 @@ describe('tooltip', function() {
beforeEach(inject(function ($compile) {
scope.enable = false;
elmBody = $compile(angular.element(
'<div><span tooltip="tooltip text" tooltip-enable="enable">Selector Text</span></div>'
'<div><span tooltip="tooltip text" tooltip-enable="{{enable}}">Selector Text</span></div>'
))(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();

}));

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('tooltip', function() {
elm = $compile(angular.element(
'<span tooltip="tooltip text" tooltip-popup-delay="{{delay}}">Selector Text</span>'
))(scope);
elmScope = elm.scope();
elmScope = elm.isolateScope();
scope.$digest();
}));

Expand Down Expand Up @@ -246,7 +246,7 @@ describe('tooltip', function() {
$compile(elmBody)(scope);
scope.$apply();
elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('focus');
Expand All @@ -262,7 +262,7 @@ describe('tooltip', function() {
$compile(elmBody)(scope);
scope.$apply();
elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('fakeTriggerAttr');
Expand All @@ -285,8 +285,8 @@ describe('tooltip', function() {
scope.$apply();
var elm1 = elmBody.find('input').eq(0);
var elm2 = elmBody.find('input').eq(1);
var elmScope1 = elm1.scope();
var elmScope2 = elm2.scope();
var elmScope1 = elm1.isolateScope();
var elmScope2 = elm2.isolateScope();

scope.$apply('test = false');

Expand Down Expand Up @@ -318,7 +318,7 @@ describe('tooltip', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();

var bodyLength = $body.children().length;
elm.trigger( 'mouseenter' );
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('tooltip', function() {
$rootScope.$apply();

elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();
elm.trigger('fooTrigger');
tooltipScope = elmScope.$$childTail;
}));
Expand Down Expand Up @@ -415,7 +415,7 @@ describe( 'tooltipHtmlUnsafe', function() {
))( scope );
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();
}));

it( 'should render html properly', inject( function () {
Expand Down Expand Up @@ -461,7 +461,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();
}));

it('should open after timeout', inject(function($timeout) {
Expand Down Expand Up @@ -500,7 +500,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();

var bodyLength = $body.children().length;
elm.trigger( 'mouseenter' );
Expand All @@ -520,7 +520,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();

elm.trigger( 'mouseenter' );
expect( elmScope.tt_isOpen ).toBe( true );
Expand Down Expand Up @@ -549,7 +549,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('focus');
Expand All @@ -567,7 +567,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('mouseenter');
Expand Down Expand Up @@ -595,7 +595,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('input');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('customOpenTrigger');
Expand All @@ -622,7 +622,7 @@ describe( '$tooltipProvider', function() {
$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
elmScope = elm.isolateScope();

expect( elmScope.tt_isOpen ).toBeFalsy();
elm.trigger('fakeTrigger');
Expand Down
23 changes: 18 additions & 5 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap

return {
restrict: 'EA',
scope: true,
scope: {
// These should be passed into the isolate scope.
// example: tooltip-enable="enable"
// instead of tooltip-enable="{{enable}}"
// but this would be a breaking change.
// tt_enable: '=' + prefix + 'Enable',
// tt_animation: '=' + prefix + 'Animation'
},
compile: function (tElem, tAttrs) {
var tooltipLinker = $compile( template );

Expand All @@ -117,7 +124,6 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
var popupTimeout;
var appendToBody = angular.isDefined( options.appendToBody ) ? options.appendToBody : false;
var triggers = getTriggers( undefined );
var hasEnableExp = angular.isDefined(attrs[prefix+'Enable']);

var positionTooltip = function () {

Expand All @@ -143,7 +149,7 @@ 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'])) {
if(!scope.tt_enable) {
return;
}
if ( scope.tt_popupDelay ) {
Expand Down Expand Up @@ -264,6 +270,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
scope.tt_placement = angular.isDefined( val ) ? val : options.placement;
});

attrs.$observe( prefix+'Enable', function ( val ) {
// using eval so "0" or "false" get evaluated as false
scope.tt_enable = angular.isDefined( val ) ? scope.$eval(val) : true;
});

attrs.$observe( prefix+'PopupDelay', function ( val ) {
var delay = parseInt( val, 10 );
scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay;
Expand All @@ -287,8 +298,10 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
}
});

var animation = scope.$eval(attrs[prefix + 'Animation']);
scope.tt_animation = angular.isDefined(animation) ? !!animation : options.animation;
attrs.$observe( prefix+'Animation', function ( val ) {
// using eval so "0" or "false" get evaluated as false
scope.tt_animation = angular.isDefined(val) ? scope.$eval(val) : options.animation;
});

attrs.$observe( prefix+'AppendToBody', function ( val ) {
appendToBody = angular.isDefined( val ) ? $parse( val )( scope ) : appendToBody;
Expand Down