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

Commit d3a1aa3

Browse files
committed
refactor(tooltip): remove observers
Lazily evaluate placement and delay
1 parent e199349 commit d3a1aa3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/tooltip/tooltip.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
146146
if(hasEnableExp && !scope.$eval(attrs[prefix+'Enable'])) {
147147
return;
148148
}
149+
150+
prepareTooltip();
151+
149152
if ( scope.tt_popupDelay ) {
150153
popupTimeout = $timeout( show, scope.tt_popupDelay, false );
151154
popupTimeout.then(function(reposition){reposition();});
@@ -163,6 +166,7 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
163166
// Show the tooltip popup element.
164167
function show() {
165168

169+
prepareTooltip();
166170

167171
// Don't show empty tooltips.
168172
if ( ! scope.tt_content ) {
@@ -235,6 +239,11 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
235239
}
236240
}
237241

242+
function prepareTooltip() {
243+
prepPlacement();
244+
prepPopupDelay();
245+
}
246+
238247
/**
239248
* Observe the relevant attributes.
240249
*/
@@ -250,14 +259,16 @@ angular.module( 'ui.bootstrap.tooltip', [ 'ui.bootstrap.position', 'ui.bootstrap
250259
scope.tt_title = val;
251260
});
252261

253-
attrs.$observe( prefix+'Placement', function ( val ) {
262+
function prepPlacement() {
263+
var val = attrs[ prefix + 'Placement' ];
254264
scope.tt_placement = angular.isDefined( val ) ? val : options.placement;
255-
});
265+
}
256266

257-
attrs.$observe( prefix+'PopupDelay', function ( val ) {
267+
function prepPopupDelay() {
268+
var val = attrs[ prefix + 'PopupDelay' ];
258269
var delay = parseInt( val, 10 );
259270
scope.tt_popupDelay = ! isNaN(delay) ? delay : options.popupDelay;
260-
});
271+
}
261272

262273
var unregisterTriggers = function () {
263274
element.unbind(triggers.show, showTooltipBind);

0 commit comments

Comments
 (0)