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

Commit f9635c2

Browse files
authored
Merge pull request #174 from kmoroder/feature/template-url-cache
Adds template URL caching as attribute option
2 parents 9447892 + 4e40410 commit f9635c2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ tooltip-template="" | String() | '' | Set your tooltip template (HTML or just Te
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
8989
| | | **to know**: don't use it together with `tooltip-template` attribute, use only one of them
90+
tooltip-template-url-cache="" | String(Boolean) | false | This attribute stores and retrieves the template from the cache
9091
tooltip-controller="" | String() | '' | Set a controller to your external tooltip template
9192
tooltip-smart="" | String(Boolean) | false | Set the tooltip to automatically search the best position on the screen
9293
tooltip-show-trigger="" | String('event1 event2') | 'mouseover' | Show the tooltip on specific event/events

dist/angular-tooltips.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@
7979
element.removeAttr('tooltip-template-url');
8080
}
8181

82+
if (element.attr('tooltip-template-url-cache') !== undefined) {
83+
84+
attributesToAdd['tooltip-template-url-cache'] = element.attr('tooltip-template-url-cache');
85+
element.removeAttr('tooltip-template-url-cache');
86+
}
87+
8288
if (element.attr('tooltip-controller') !== undefined) {
8389

8490
attributesToAdd['tooltip-controller'] = element.attr('tooltip-controller');
@@ -212,7 +218,8 @@
212218
'smart': false,
213219
'closeButton': false,
214220
'size': '',
215-
'speed': 'steady'
221+
'speed': 'steady',
222+
'tooltipTemplateUrlCache': false
216223
};
217224

218225
return {
@@ -240,7 +247,7 @@
240247
}
241248
};
242249
}
243-
, tooltipDirective = /*@ngInject*/ ["$log", "$http", "$compile", "$timeout", "$controller", "$injector", "tooltipsConf", function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf) {
250+
, tooltipDirective = /*@ngInject*/ ["$log", "$http", "$compile", "$timeout", "$controller", "$injector", "tooltipsConf", "$templateCache", function tooltipDirective($log, $http, $compile, $timeout, $controller, $injector, tooltipsConf) {
244251

245252
var linkingFunction = function linkingFunction($scope, $element, $attrs, $controllerDirective, $transcludeFunc) {
246253

@@ -557,7 +564,6 @@
557564
}
558565
}
559566
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
560-
561567
if (newValue) {
562568
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
563569
tipTipElement.empty();
@@ -574,7 +580,6 @@
574580
}
575581
}
576582
, onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
577-
578583
if (newValue) {
579584

580585
$http.get(newValue).then(function onResponse(response) {
@@ -598,6 +603,28 @@
598603
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
599604
}
600605
}
606+
, onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
607+
if (newValue && $attrs.tooltipTemplateUrl) {
608+
609+
var template = $templateCache.get($attrs.tooltipTemplateUrl);
610+
611+
if (typeof template !== 'undefined') {
612+
613+
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
614+
tipTipElement.empty();
615+
tipTipElement.append(closeButtonElement);
616+
tipTipElement.append($compile(response.data)(scope));
617+
$timeout(function doLater() {
618+
619+
onTooltipShow();
620+
});
621+
}
622+
} else {
623+
//hide tooltip because is empty
624+
tipTipElement.empty();
625+
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
626+
}
627+
}
601628
, onTooltipSideChange = function onTooltipSideChange(newValue) {
602629

603630
if (newValue) {
@@ -718,6 +745,7 @@
718745
}
719746
, unregisterOnTooltipTemplateChange = $attrs.$observe('tooltipTemplate', onTooltipTemplateChange)
720747
, unregisterOnTooltipTemplateUrlChange = $attrs.$observe('tooltipTemplateUrl', onTooltipTemplateUrlChange)
748+
, unregisterOnTooltipTemplateUrlCacheChange = $attrs.$observe('tooltipTemplateUrlCache', onTooltipTemplateUrlCacheChange)
721749
, unregisterOnTooltipSideChangeObserver = $attrs.$observe('tooltipSide', onTooltipSideChange)
722750
, unregisterOnTooltipShowTrigger = $attrs.$observe('tooltipShowTrigger', onTooltipShowTrigger)
723751
, unregisterOnTooltipHideTrigger = $attrs.$observe('tooltipHideTrigger', onTooltipHideTrigger)
@@ -777,6 +805,7 @@
777805

778806
unregisterOnTooltipTemplateChange();
779807
unregisterOnTooltipTemplateUrlChange();
808+
unregisterOnTooltipTemplateUrlCacheChange();
780809
unregisterOnTooltipSideChangeObserver();
781810
unregisterOnTooltipShowTrigger();
782811
unregisterOnTooltipHideTrigger();

0 commit comments

Comments
 (0)