| @@ 5031-5096 (lines=66) @@ | ||
| 5028 | // This is mostly ngInclude code but with a custom scope |
|
| 5029 | .directive('uibTooltipTemplateTransclude', [ |
|
| 5030 | '$animate', '$sce', '$compile', '$templateRequest', |
|
| 5031 | function ($animate, $sce, $compile, $templateRequest) { |
|
| 5032 | return { |
|
| 5033 | link: function(scope, elem, attrs) { |
|
| 5034 | var origScope = scope.$eval(attrs.tooltipTemplateTranscludeScope); |
|
| 5035 | ||
| 5036 | var changeCounter = 0, |
|
| 5037 | currentScope, |
|
| 5038 | previousElement, |
|
| 5039 | currentElement; |
|
| 5040 | ||
| 5041 | var cleanupLastIncludeContent = function() { |
|
| 5042 | if (previousElement) { |
|
| 5043 | previousElement.remove(); |
|
| 5044 | previousElement = null; |
|
| 5045 | } |
|
| 5046 | ||
| 5047 | if (currentScope) { |
|
| 5048 | currentScope.$destroy(); |
|
| 5049 | currentScope = null; |
|
| 5050 | } |
|
| 5051 | ||
| 5052 | if (currentElement) { |
|
| 5053 | $animate.leave(currentElement).then(function() { |
|
| 5054 | previousElement = null; |
|
| 5055 | }); |
|
| 5056 | previousElement = currentElement; |
|
| 5057 | currentElement = null; |
|
| 5058 | } |
|
| 5059 | }; |
|
| 5060 | ||
| 5061 | scope.$watch($sce.parseAsResourceUrl(attrs.uibTooltipTemplateTransclude), function(src) { |
|
| 5062 | var thisChangeId = ++changeCounter; |
|
| 5063 | ||
| 5064 | if (src) { |
|
| 5065 | //set the 2nd param to true to ignore the template request error so that the inner |
|
| 5066 | //contents and scope can be cleaned up. |
|
| 5067 | $templateRequest(src, true).then(function(response) { |
|
| 5068 | if (thisChangeId !== changeCounter) { return; } |
|
| 5069 | var newScope = origScope.$new(); |
|
| 5070 | var template = response; |
|
| 5071 | ||
| 5072 | var clone = $compile(template)(newScope, function(clone) { |
|
| 5073 | cleanupLastIncludeContent(); |
|
| 5074 | $animate.enter(clone, elem); |
|
| 5075 | }); |
|
| 5076 | ||
| 5077 | currentScope = newScope; |
|
| 5078 | currentElement = clone; |
|
| 5079 | ||
| 5080 | currentScope.$emit('$includeContentLoaded', src); |
|
| 5081 | }, function() { |
|
| 5082 | if (thisChangeId === changeCounter) { |
|
| 5083 | cleanupLastIncludeContent(); |
|
| 5084 | scope.$emit('$includeContentError', src); |
|
| 5085 | } |
|
| 5086 | }); |
|
| 5087 | scope.$emit('$includeContentRequested', src); |
|
| 5088 | } else { |
|
| 5089 | cleanupLastIncludeContent(); |
|
| 5090 | } |
|
| 5091 | }); |
|
| 5092 | ||
| 5093 | scope.$on('$destroy', cleanupLastIncludeContent); |
|
| 5094 | } |
|
| 5095 | }; |
|
| 5096 | }]) |
|
| 5097 | ||
| 5098 | /** |
|
| 5099 | * Note that it's intentional that these classes are *not* applied through $animate. |
|
| @@ 5030-5095 (lines=66) @@ | ||
| 5027 | // This is mostly ngInclude code but with a custom scope |
|
| 5028 | .directive('uibTooltipTemplateTransclude', [ |
|
| 5029 | '$animate', '$sce', '$compile', '$templateRequest', |
|
| 5030 | function ($animate, $sce, $compile, $templateRequest) { |
|
| 5031 | return { |
|
| 5032 | link: function(scope, elem, attrs) { |
|
| 5033 | var origScope = scope.$eval(attrs.tooltipTemplateTranscludeScope); |
|
| 5034 | ||
| 5035 | var changeCounter = 0, |
|
| 5036 | currentScope, |
|
| 5037 | previousElement, |
|
| 5038 | currentElement; |
|
| 5039 | ||
| 5040 | var cleanupLastIncludeContent = function() { |
|
| 5041 | if (previousElement) { |
|
| 5042 | previousElement.remove(); |
|
| 5043 | previousElement = null; |
|
| 5044 | } |
|
| 5045 | ||
| 5046 | if (currentScope) { |
|
| 5047 | currentScope.$destroy(); |
|
| 5048 | currentScope = null; |
|
| 5049 | } |
|
| 5050 | ||
| 5051 | if (currentElement) { |
|
| 5052 | $animate.leave(currentElement).then(function() { |
|
| 5053 | previousElement = null; |
|
| 5054 | }); |
|
| 5055 | previousElement = currentElement; |
|
| 5056 | currentElement = null; |
|
| 5057 | } |
|
| 5058 | }; |
|
| 5059 | ||
| 5060 | scope.$watch($sce.parseAsResourceUrl(attrs.uibTooltipTemplateTransclude), function(src) { |
|
| 5061 | var thisChangeId = ++changeCounter; |
|
| 5062 | ||
| 5063 | if (src) { |
|
| 5064 | //set the 2nd param to true to ignore the template request error so that the inner |
|
| 5065 | //contents and scope can be cleaned up. |
|
| 5066 | $templateRequest(src, true).then(function(response) { |
|
| 5067 | if (thisChangeId !== changeCounter) { return; } |
|
| 5068 | var newScope = origScope.$new(); |
|
| 5069 | var template = response; |
|
| 5070 | ||
| 5071 | var clone = $compile(template)(newScope, function(clone) { |
|
| 5072 | cleanupLastIncludeContent(); |
|
| 5073 | $animate.enter(clone, elem); |
|
| 5074 | }); |
|
| 5075 | ||
| 5076 | currentScope = newScope; |
|
| 5077 | currentElement = clone; |
|
| 5078 | ||
| 5079 | currentScope.$emit('$includeContentLoaded', src); |
|
| 5080 | }, function() { |
|
| 5081 | if (thisChangeId === changeCounter) { |
|
| 5082 | cleanupLastIncludeContent(); |
|
| 5083 | scope.$emit('$includeContentError', src); |
|
| 5084 | } |
|
| 5085 | }); |
|
| 5086 | scope.$emit('$includeContentRequested', src); |
|
| 5087 | } else { |
|
| 5088 | cleanupLastIncludeContent(); |
|
| 5089 | } |
|
| 5090 | }); |
|
| 5091 | ||
| 5092 | scope.$on('$destroy', cleanupLastIncludeContent); |
|
| 5093 | } |
|
| 5094 | }; |
|
| 5095 | }]) |
|
| 5096 | ||
| 5097 | /** |
|
| 5098 | * Note that it's intentional that these classes are *not* applied through $animate. |
|