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

Commit

Permalink
refactor(tooltip): lazily evaluate placement, delay
Browse files Browse the repository at this point in the history
There's no need for an observer here because these values are only used
on initialization of the tooltip.
  • Loading branch information
chrisirhc committed Nov 2, 2014
1 parent eab6daf commit 13b5cd9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
if(hasEnableExp && !scope.$eval(attrs[prefix+'Enable'])) {
return;
}

prepareTooltip();

if ( scope.tt_popupDelay ) {
// Do nothing if the tooltip was already scheduled to pop-up.
// This happens if show is triggered multiple times before any hide is triggered.
Expand Down Expand Up @@ -242,6 +245,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
}
}

function prepareTooltip() {
prepPlacement();
prepPopupDelay();
}

/**
* Observe the relevant attributes.
*/
Expand All @@ -257,14 +265,16 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
scope.tt_title = val;
});

attrs.$observe( prefix+'Placement', function ( val ) {
function prepPlacement() {
var val = attrs[ prefix + 'Placement' ];
scope.tt_placement = angular.isDefined( val ) ? val : options.placement;
});
}

attrs.$observe( prefix+'PopupDelay', function ( val ) {
function prepPopupDelay() {
var val = attrs[ prefix + 'PopupDelay' ];
var delay = parseInt( val, 10 );
scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay;
});
}

var unregisterTriggers = function () {
element.unbind(triggers.show, showTooltipBind);
Expand Down

0 comments on commit 13b5cd9

Please sign in to comment.