Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Commit dab10a6

Browse files
committed
tooltipTemplateUrlCache thanks to @kmoroder
1 parent f9635c2 commit dab10a6

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ tooltip-side="" | String('left','right','top','bottom') | 'top' | Set your toolt
8686
tooltip-template="" | String() | '' | Set your tooltip template (HTML or just Text)
8787
| | | **to know**: don't use it together with `tooltip-template-url` attribute, use only one of them
8888
tooltip-template-url="" | String() | '' | Set your external tooltip template PATH
89-
| | | **to know**: don't use it together with `tooltip-template` attribute, use only one of them
89+
| | | **to know**: don't use it together with `tooltip-template` attribute, use only one of them
9090
tooltip-template-url-cache="" | String(Boolean) | false | This attribute stores and retrieves the template from the cache
9191
tooltip-controller="" | String() | '' | Set a controller to your external tooltip template
9292
tooltip-smart="" | String(Boolean) | false | Set the tooltip to automatically search the best position on the screen
@@ -109,6 +109,7 @@ Sometimes you may need to set all of your tooltips options in one place, you can
109109
'smart':true,
110110
'size':'large',
111111
'speed': 'slow',
112+
'tooltipTemplateUrlCache': true
112113
//etc...
113114
});
114115
}])

lib/angular-tooltips.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
element.removeAttr('tooltip-template-url');
7070
}
7171

72+
if (element.attr('tooltip-template-url-cache') !== undefined) {
73+
74+
attributesToAdd['tooltip-template-url-cache'] = element.attr('tooltip-template-url-cache');
75+
element.removeAttr('tooltip-template-url-cache');
76+
}
77+
7278
if (element.attr('tooltip-controller') !== undefined) {
7379

7480
attributesToAdd['tooltip-controller'] = element.attr('tooltip-controller');
@@ -202,7 +208,8 @@
202208
'smart': false,
203209
'closeButton': false,
204210
'size': '',
205-
'speed': 'steady'
211+
'speed': 'steady',
212+
'tooltipTemplateUrlCache': false
206213
};
207214

208215
return {
@@ -230,7 +237,7 @@
230237
}
231238
};
232239
}
233-
, tooltipDirective = /*@ngInject*/ function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf) {
240+
, tooltipDirective = /*@ngInject*/ ["$log", "$http", "$compile", "$timeout", "$controller", "$injector", "tooltipsConf", "$templateCache", function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf) {
234241

235242
var linkingFunction = function linkingFunction($scope, $element, $attrs, $controllerDirective, $transcludeFunc) {
236243

@@ -547,7 +554,6 @@
547554
}
548555
}
549556
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
550-
551557
if (newValue) {
552558
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
553559
tipTipElement.empty();
@@ -564,7 +570,6 @@
564570
}
565571
}
566572
, onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
567-
568573
if (newValue) {
569574

570575
$http.get(newValue).then(function onResponse(response) {
@@ -588,6 +593,28 @@
588593
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
589594
}
590595
}
596+
, onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
597+
if (newValue && $attrs.tooltipTemplateUrl) {
598+
599+
var template = $templateCache.get($attrs.tooltipTemplateUrl);
600+
601+
if (typeof template !== 'undefined') {
602+
603+
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
604+
tipTipElement.empty();
605+
tipTipElement.append(closeButtonElement);
606+
tipTipElement.append($compile(response.data)(scope));
607+
$timeout(function doLater() {
608+
609+
onTooltipShow();
610+
});
611+
}
612+
} else {
613+
//hide tooltip because is empty
614+
tipTipElement.empty();
615+
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
616+
}
617+
}
591618
, onTooltipSideChange = function onTooltipSideChange(newValue) {
592619

593620
if (newValue) {
@@ -708,6 +735,7 @@
708735
}
709736
, unregisterOnTooltipTemplateChange = $attrs.$observe('tooltipTemplate', onTooltipTemplateChange)
710737
, unregisterOnTooltipTemplateUrlChange = $attrs.$observe('tooltipTemplateUrl', onTooltipTemplateUrlChange)
738+
, unregisterOnTooltipTemplateUrlCacheChange = $attrs.$observe('tooltipTemplateUrlCache', onTooltipTemplateUrlCacheChange)
711739
, unregisterOnTooltipSideChangeObserver = $attrs.$observe('tooltipSide', onTooltipSideChange)
712740
, unregisterOnTooltipShowTrigger = $attrs.$observe('tooltipShowTrigger', onTooltipShowTrigger)
713741
, unregisterOnTooltipHideTrigger = $attrs.$observe('tooltipHideTrigger', onTooltipHideTrigger)
@@ -767,6 +795,7 @@
767795

768796
unregisterOnTooltipTemplateChange();
769797
unregisterOnTooltipTemplateUrlChange();
798+
unregisterOnTooltipTemplateUrlCacheChange();
770799
unregisterOnTooltipSideChangeObserver();
771800
unregisterOnTooltipShowTrigger();
772801
unregisterOnTooltipHideTrigger();
@@ -789,7 +818,7 @@
789818
'terminal': true,
790819
'link': linkingFunction
791820
};
792-
};
821+
}];
793822

794823
angular.module('720kb.tooltips', [])
795824
.provider(directiveName + 'Conf', tooltipConfigurationProvider)

0 commit comments

Comments
 (0)