Skip to content

Commit 6120efd

Browse files
Merge branch 'master' into corner-positions
2 parents ec2328d + 6fb45a3 commit 6120efd

File tree

4 files changed

+77
-46
lines changed

4 files changed

+77
-46
lines changed

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ Sometimes you may need to set all of your tooltips options in one place, you can
106106
```javascript
107107
.config(['tooltipsConfProvider', function configConf(tooltipsConfProvider) {
108108
tooltipsConfProvider.configure({
109-
'smart':true,
110-
'size':'large',
109+
'smart': true,
110+
'size': 'large',
111111
'speed': 'slow',
112112
'tooltipTemplateUrlCache': true
113113
//etc...

demo/views/template-url-cache.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div>I'm a tooltip loaded using templateUrlCache!</div>

index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,22 @@
407407
tooltip-template="A tooltip with text">Tooltip Bottom</button>
408408
</div>
409409

410+
<div>
411+
<span tooltips
412+
tooltip-template-url="demo/views/template-url-cache.html"
413+
tooltip-template-url-cache="true">
414+
Tooltip using templateUrlCache
415+
</span>
416+
</div>
417+
418+
<div>
419+
<span tooltips
420+
tooltip-template-url="demo/views/template-url-cache.html"
421+
tooltip-template-url-cache="true">
422+
Tooltip using templateUrlCache
423+
</span>
424+
</div>
425+
410426
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.0/angular.js"></script>
411427
<script type="text/javascript" src="dist/angular-tooltips.js"></script>
412428
<script type="text/javascript" src="demo/js/index.js"></script>

lib/angular-tooltips.js

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -500,65 +500,79 @@
500500
registerOnScrollFrom(parentElement);
501501
}
502502
}
503+
, showTemplate = function showTemplate(template) {
504+
505+
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
506+
tipTipElement.empty();
507+
tipTipElement.append(closeButtonElement);
508+
tipTipElement.append(template);
509+
$timeout(function doLater() {
510+
511+
onTooltipShow();
512+
});
513+
}
514+
, hideTemplate = function hideTemplate() {
515+
516+
//hide tooltip because is empty
517+
tipTipElement.empty();
518+
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
519+
}
520+
, getTemplate = function getTemplate(tooltipTemplateUrl) {
521+
522+
var template = $templateCache.get(tooltipTemplateUrl);
523+
524+
if (typeof template === 'undefined') {
525+
526+
// How should failing to load the template be handled?
527+
template = $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) {
528+
529+
return response.data;
530+
});
531+
$templateCache.put(tooltipTemplateUrl, template);
532+
}
533+
534+
return template;
535+
}
503536
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
537+
504538
if (newValue) {
505-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
506-
tipTipElement.empty();
507-
tipTipElement.append(closeButtonElement);
508-
tipTipElement.append(newValue);
509-
$timeout(function doLaterShow() {
510-
511-
onTooltipShow();
512-
});
539+
540+
showTemplate(newValue);
513541
} else {
514-
//hide tooltip because is empty
515-
tipTipElement.empty();
516-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
542+
543+
hideTemplate();
517544
}
518545
}
519546
, onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
547+
520548
if (newValue && !$attrs.tooltipTemplateUrlCache) {
521-
522-
$http.get(newValue).then(function onResponse(response) {
523-
524-
if (response &&
525-
response.data) {
526-
527-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
528-
tipTipElement.empty();
529-
tipTipElement.append(closeButtonElement);
530-
tipTipElement.append($compile(response.data)(scope));
531-
$timeout(function doLater() {
532-
533-
onTooltipShow();
534-
});
535-
}
549+
550+
getTemplate(newValue).then(function onGetTemplateSuccess(template) {
551+
552+
showTemplate($compile(template)(scope));
553+
}).catch(function onGetTemplateFailure(reason) {
554+
555+
$log.error(reason);
536556
});
537557
} else {
538-
//hide tooltip because is empty
539-
tipTipElement.empty();
540-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
558+
559+
hideTemplate();
541560
}
542561
}
543562
, onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
563+
544564
if (newValue && $attrs.tooltipTemplateUrl) {
565+
566+
getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) {
567+
568+
showTemplate($compile(template)(scope));
569+
}).catch(function onGetTemplateFailure(reason) {
545570

546-
var template = $templateCache.get($attrs.tooltipTemplateUrl);
547-
548-
if (typeof template !== 'undefined') {
549-
550-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
551-
tipTipElement.empty();
552-
tipTipElement.append(closeButtonElement);
553-
tipTipElement.append($compile(template)(scope));
554-
$timeout(function doLater() {
555-
onTooltipShow();
556-
});
557-
}
571+
$log.error(reason);
572+
});
558573
} else {
559-
//hide tooltip because is empty
560-
tipTipElement.empty();
561-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
574+
575+
hideTemplate();
562576
}
563577
}
564578
, onTooltipSideChange = function onTooltipSideChange(newValue) {

0 commit comments

Comments
 (0)