From 9d857d222f068ed573bcb8dd2615f1f5d8eca266 Mon Sep 17 00:00:00 2001 From: Slava Fomin II Date: Tue, 19 Apr 2016 13:25:33 +0300 Subject: [PATCH] Angular Template cache is now supported. --- .gitignore | 1 + lib/angular-tooltips.js | 39 ++++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 5842bf7..f46322f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.idea/ node_modules/ bower_components/ npm-debug.log diff --git a/lib/angular-tooltips.js b/lib/angular-tooltips.js index ba13efc..4f8edc9 100644 --- a/lib/angular-tooltips.js +++ b/lib/angular-tooltips.js @@ -221,7 +221,7 @@ } }; } - , tooltipDirective = /*@ngInject*/ function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf) { + , tooltipDirective = /*@ngInject*/ function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf, $templateCache) { var linkingFunction = function linkingFunction($scope, $element, $attrs, $controllerDirective, $transcludeFunc) { @@ -549,25 +549,34 @@ }); } } - , onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) { + , onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(templateUrl) { - if (newValue) { + if (!templateUrl) { + return; + } - $http.get(newValue).then(function onResponse(response) { + // Trying to load template from the template cache first. + var template = $templateCache.get(templateUrl); - if (response && - response.data) { + if ('undefined' === typeof template) { + $http + .get(templateUrl) + .then(function onResponse(response) { + if (response && response.data) { + template = response.data; + $templateCache.put(templateUrl, template); + } + }) + ; + } - tipTipElement.empty(); - tipTipElement.append(closeButtonElement); - tipTipElement.append($compile(response.data)(scope)); - $timeout(function doLater() { + tipTipElement.empty(); + tipTipElement.append(closeButtonElement); + tipTipElement.append($compile(template)(scope)); + $timeout(function doLater() { + onTooltipShow(); + }); - onTooltipShow(); - }); - } - }); - } } , onTooltipSideChange = function onTooltipSideChange(newValue) {