Skip to content

Commit

Permalink
fix(popover): animations with ngAnimate
Browse files Browse the repository at this point in the history
- Animations didn't work because the class attribute was mangled during
  compilation due to the way class attributes are merged on directives with
  `replace: true`

- Rename attribute to popup-class

- Refactor to rename variables named "class" as it's a keyword
  and also looks weird in editors

Fixes angular-ui#3375
  • Loading branch information
chrisirhc committed Apr 8, 2015
1 parent e31fcf0 commit 9573c67
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/popover/test/popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ describe('popover', function() {
elm.click();
expect(scope.clicked).toBeTruthy();
}));

it('should popup with animate class by default', inject(function() {
elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );

expect(elmBody.children().eq(1)).toHaveClass('fade');
}));

it('should popup without animate class when animation disabled', inject(function($compile) {
elmBody = angular.element(
'<div><span popover="popover text" popover-animation="false">Selector Text</span></div>'
);

$compile(elmBody)(scope);
scope.$digest();
elm = elmBody.find('span');
elmScope = elm.scope();
tooltipScope = elmScope.$$childTail;

elm.trigger( 'click' );
expect( tooltipScope.isOpen ).toBe( true );
expect(elmBody.children().eq(1)).not.toHaveClass('fade');
}));

});


10 changes: 5 additions & 5 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
'content="'+startSym+'content'+endSym+'" '+
'content-exp="contentExp()" '+
'placement="'+startSym+'placement'+endSym+'" '+
'class="'+startSym+'class'+endSym+'" '+
'popup-class="'+startSym+'popupClass'+endSym+'" '+
'animation="animation" '+
'is-open="isOpen"'+
'origin-scope="origScope" '+
Expand Down Expand Up @@ -292,7 +292,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
});

attrs.$observe( prefix+'Class', function ( val ) {
ttScope.class = val;
ttScope.popupClass = val;
});

function prepPlacement() {
Expand Down Expand Up @@ -451,7 +451,7 @@ function ($animate , $sce , $compile , $templateRequest) {
return {
restrict: 'EA',
replace: true,
scope: { content: '@', placement: '@', class: '@', animation: '&', isOpen: '&' },
scope: { content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/tooltip/tooltip-popup.html'
};
})
Expand All @@ -478,7 +478,7 @@ function ($animate , $sce , $compile , $templateRequest) {
return {
restrict: 'EA',
replace: true,
scope: { contentExp: '&', placement: '@', class: '@', animation: '&', isOpen: '&' },
scope: { contentExp: '&', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/tooltip/tooltip-html-popup.html'
};
})
Expand All @@ -494,7 +494,7 @@ Deprecated
return {
restrict: 'EA',
replace: true,
scope: { content: '@', placement: '@', class: '@', animation: '&', isOpen: '&' },
scope: { content: '@', placement: '@', popupClass: '@', animation: '&', isOpen: '&' },
templateUrl: 'template/tooltip/tooltip-html-unsafe-popup.html'
};
})
Expand Down
2 changes: 1 addition & 1 deletion template/tooltip/tooltip-html-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="tooltip {{placement}} {{class}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" ng-bind-html="contentExp()"></div>
</div>
2 changes: 1 addition & 1 deletion template/tooltip/tooltip-html-unsafe-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="tooltip {{placement}} {{class}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" bind-html-unsafe="content"></div>
</div>
2 changes: 1 addition & 1 deletion template/tooltip/tooltip-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="tooltip {{placement}} {{class}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" ng-bind="content"></div>
</div>

0 comments on commit 9573c67

Please sign in to comment.