From d9cf0e56e206bcebabcd8753727601101b3ee043 Mon Sep 17 00:00:00 2001 From: forceuser Date: Thu, 17 Sep 2015 11:40:50 +0300 Subject: [PATCH 1/5] change contentExp to evaluate using $parse instead of scope.$eval change contentExp to evaluate using $parse instead of scope.$eval to make possible usage of filters inside expression --- src/tooltip/tooltip.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 9501f50051..1700e89804 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -143,7 +143,16 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s var ttScope = scope.$new(true); var repositionScheduled = false; var isOpenExp = angular.isDefined(attrs[prefix + 'IsOpen']) ? $parse(attrs[prefix + 'IsOpen']) : false; + var contentExpVal; + var contentExpGetter; + if(options.useContentExp){ + contentExpGetter = $parse(attrs[type]) + scope.$watch(contentExpGetter,function(val){ + contentExpVal = val; + }); + } + var positionTooltip = function() { // check if tooltip exists and is not empty if (!tooltip || !tooltip.html()) { return; } @@ -231,7 +240,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } // Don't show empty tooltips. - if (!(options.useContentExp ? ttScope.contentExp() : ttScope.content)) { + if (!(options.useContentExp ? contentExpGetter(scope) : ttScope.content)) { return angular.noop; } @@ -336,7 +345,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } ttScope.contentExp = function() { - return scope.$eval(attrs[type]); + return contentExpVal; }; /** From b342d19928e0d2af848096632ede20f95fd62a8f Mon Sep 17 00:00:00 2001 From: forceuser Date: Thu, 17 Sep 2015 12:15:43 +0300 Subject: [PATCH 2/5] ; --- src/tooltip/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 1700e89804..716e4e7246 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -147,7 +147,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s var contentExpGetter; if(options.useContentExp){ - contentExpGetter = $parse(attrs[type]) + contentExpGetter = $parse(attrs[type]); scope.$watch(contentExpGetter,function(val){ contentExpVal = val; }); From 4ca2e3cff74ce5f3de3fd569aa61afade86145bf Mon Sep 17 00:00:00 2001 From: forceuser Date: Fri, 18 Sep 2015 11:01:09 +0300 Subject: [PATCH 3/5] startWatch contentExp only after creation of tooltip and stop watch on remove --- src/tooltip/tooltip.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index 716e4e7246..b89100efcf 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -145,12 +145,18 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s var isOpenExp = angular.isDefined(attrs[prefix + 'IsOpen']) ? $parse(attrs[prefix + 'IsOpen']) : false; var contentExpVal; var contentExpGetter; - + var contentExpGetterStartWatch; + var contentExpGetterStopWatch; + if(options.useContentExp){ contentExpGetter = $parse(attrs[type]); - scope.$watch(contentExpGetter,function(val){ - contentExpVal = val; - }); + + contentExpGetterStartWatch = function(){ + contentExpGetterStopWatch&&contentExpGetterStopWatch(); + contentExpGetterStopWatch = scope.$watch(contentExpGetter,function(val){ + contentExpVal = val; + }); + }; } var positionTooltip = function() { @@ -305,6 +311,10 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s }); if (options.useContentExp) { + if(!contentExpGetterStopWatch){ + contentExpGetterStartWatch(); + } + tooltipLinkedScope.$watch('contentExp()', function(val) { if (!val && ttScope.isOpen) { hide(); @@ -332,6 +342,10 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s tooltip.remove(); tooltip = null; } + if(contentExpGetterStopWatch){ + contentExpGetterStopWatch(); + contentExpGetterStopWatch = null; + } if (tooltipLinkedScope) { tooltipLinkedScope.$destroy(); tooltipLinkedScope = null; From 5b6e99ed879eb3145105add37e6a913e86cba09e Mon Sep 17 00:00:00 2001 From: forceuser Date: Fri, 18 Sep 2015 11:50:49 +0300 Subject: [PATCH 4/5] just to make more lines of code.. (jshint) --- src/tooltip/tooltip.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index b89100efcf..d68e6cb1c1 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -152,7 +152,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s contentExpGetter = $parse(attrs[type]); contentExpGetterStartWatch = function(){ - contentExpGetterStopWatch&&contentExpGetterStopWatch(); + if(contentExpGetterStopWatch){ + contentExpGetterStopWatch(); + } contentExpGetterStopWatch = scope.$watch(contentExpGetter,function(val){ contentExpVal = val; }); From 0250e34f16f246002fc405080a4cce5591f1179e Mon Sep 17 00:00:00 2001 From: forceuser Date: Fri, 18 Sep 2015 18:13:33 +0300 Subject: [PATCH 5/5] removed tooltipLinkedScope.$watch("contentExp()" --- src/tooltip/tooltip.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/tooltip/tooltip.js b/src/tooltip/tooltip.js index d68e6cb1c1..a30d2d229e 100644 --- a/src/tooltip/tooltip.js +++ b/src/tooltip/tooltip.js @@ -157,6 +157,9 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s } contentExpGetterStopWatch = scope.$watch(contentExpGetter,function(val){ contentExpVal = val; + if (!val && ttScope.isOpen) { + hide(); + } }); }; } @@ -316,12 +319,6 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s if(!contentExpGetterStopWatch){ contentExpGetterStartWatch(); } - - tooltipLinkedScope.$watch('contentExp()', function(val) { - if (!val && ttScope.isOpen) { - hide(); - } - }); tooltipLinkedScope.$watch(function() { if (!repositionScheduled) {