Skip to content

Commit

Permalink
refactor(tooltip): make tooltip-class more robust
Browse files Browse the repository at this point in the history
- Add tooltip-class support to tooltip-template
- Remove observer for tooltip-class, it’s evaluated once on tooltip
  preparation instead
- Remove interpolation on class attribute
  Interpolation on the class attribute can have undesirable mangling
  effects when use with a directive that has `replace: true`. It also
  doesn’t work properly with ngAnimate.

Relates to angular-ui#3126
  • Loading branch information
chrisirhc committed Apr 9, 2015
1 parent c2ace47 commit f7e4995
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
32 changes: 17 additions & 15 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
}

function prepareTooltip() {
prepPopupClass();
prepPlacement();
prepPopupDelay();
}
Expand Down Expand Up @@ -291,9 +292,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
ttScope.title = val;
});

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

function prepPlacement() {
var val = attrs[ prefix + 'Placement' ];
Expand Down Expand Up @@ -426,27 +427,28 @@ function ($animate , $sce , $compile , $templateRequest) {
};
}])

// Apply animate class without animating itself
.directive('tooltipAnimateClass', function () {
/**
* Note that it's intentional that these classes are *not* applied through $animate.
* They must not be animated as they're expected to be present on the tooltip on
* initialization.
*/
.directive('tooltipClasses', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
if (scope.placement) {
element.addClass(scope.placement);
}
if (scope.popupClass) {
element.addClass(scope.popupClass);
}
if (scope.animation()) {
element.addClass(attrs.tooltipAnimateClass);
element.addClass(attrs.tooltipAnimationClass);
}
}
};
})

.directive('tooltipPlacementClass', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.addClass(scope.placement);
}
};
})

.directive( 'tooltipPopup', function () {
return {
restrict: 'EA',
Expand Down
4 changes: 2 additions & 2 deletions template/popover/popover-template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="popover"
tooltip-placement-class
tooltip-animate-class="fade"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="arrow"></div>

Expand Down
4 changes: 2 additions & 2 deletions template/popover/popover.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="popover"
tooltip-placement-class
tooltip-animate-class="fade"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="arrow"></div>

Expand Down
5 changes: 4 additions & 1 deletion template/tooltip/tooltip-html-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" ng-bind-html="contentExp()"></div>
</div>
5 changes: 4 additions & 1 deletion template/tooltip/tooltip-html-unsafe-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="tooltip {{placement}} {{popupClass}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner" bind-html-unsafe="content"></div>
</div>
5 changes: 4 additions & 1 deletion template/tooltip/tooltip-template-popup.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="tooltip {{placement}}" ng-class="{ in: isOpen(), fade: animation() }">
<div class="tooltip"
tooltip-animation-class="fade"
tooltip-classes
ng-class="{ in: isOpen() }">
<div class="tooltip-arrow"></div>
<div class="tooltip-inner"
tooltip-template-transclude="content"
Expand Down

0 comments on commit f7e4995

Please sign in to comment.