Skip to content

Commit 5e7cc33

Browse files
committed
fix for template-url-cache thanks to @leonard-thieu #204
1 parent 6fb45a3 commit 5e7cc33

7 files changed

+70
-56
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-tooltips",
3-
"version": "1.1.11",
3+
"version": "1.1.12",
44
"description": "Angular.js tooltips module.",
55
"authors": [
66
"Filippo Oretti <[email protected]",

dist/angular-tooltips.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* angular-tooltips
3-
* 1.1.11
3+
* 1.1.12
44
*
55
* Angular.js tooltips module.
66
* http://720kb.github.io/angular-tooltips
77
*
88
* MIT license
9-
* Thu May 18 2017
9+
* Sat May 20 2017
1010
*/
1111
@-webkit-keyframes animate-tooltip {
1212
0% {

dist/angular-tooltips.js

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* angular-tooltips
3-
* 1.1.11
3+
* 1.1.12
44
*
55
* Angular.js tooltips module.
66
* http://720kb.github.io/angular-tooltips
77
*
88
* MIT license
9-
* Thu May 18 2017
9+
* Sat May 20 2017
1010
*/
1111
/*global angular,window*/
1212
(function withAngular(angular, window) {
@@ -571,65 +571,79 @@
571571
registerOnScrollFrom(parentElement);
572572
}
573573
}
574+
, showTemplate = function showTemplate(template) {
575+
576+
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
577+
tipTipElement.empty();
578+
tipTipElement.append(closeButtonElement);
579+
tipTipElement.append(template);
580+
$timeout(function doLater() {
581+
582+
onTooltipShow();
583+
});
584+
}
585+
, hideTemplate = function hideTemplate() {
586+
587+
//hide tooltip because is empty
588+
tipTipElement.empty();
589+
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
590+
}
591+
, getTemplate = function getTemplate(tooltipTemplateUrl) {
592+
593+
var template = $templateCache.get(tooltipTemplateUrl);
594+
595+
if (typeof template === 'undefined') {
596+
597+
// How should failing to load the template be handled?
598+
template = $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) {
599+
600+
return response.data;
601+
});
602+
$templateCache.put(tooltipTemplateUrl, template);
603+
}
604+
605+
return template;
606+
}
574607
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
608+
575609
if (newValue) {
576-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
577-
tipTipElement.empty();
578-
tipTipElement.append(closeButtonElement);
579-
tipTipElement.append(newValue);
580-
$timeout(function doLaterShow() {
581-
582-
onTooltipShow();
583-
});
610+
611+
showTemplate(newValue);
584612
} else {
585-
//hide tooltip because is empty
586-
tipTipElement.empty();
587-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
613+
614+
hideTemplate();
588615
}
589616
}
590617
, onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
618+
591619
if (newValue && !$attrs.tooltipTemplateUrlCache) {
592-
593-
$http.get(newValue).then(function onResponse(response) {
594-
595-
if (response &&
596-
response.data) {
597-
598-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
599-
tipTipElement.empty();
600-
tipTipElement.append(closeButtonElement);
601-
tipTipElement.append($compile(response.data)(scope));
602-
$timeout(function doLater() {
603-
604-
onTooltipShow();
605-
});
606-
}
620+
621+
getTemplate(newValue).then(function onGetTemplateSuccess(template) {
622+
623+
showTemplate($compile(template)(scope));
624+
}).catch(function onGetTemplateFailure(reason) {
625+
626+
$log.error(reason);
607627
});
608628
} else {
609-
//hide tooltip because is empty
610-
tipTipElement.empty();
611-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
629+
630+
hideTemplate();
612631
}
613632
}
614633
, onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
634+
615635
if (newValue && $attrs.tooltipTemplateUrl) {
636+
637+
getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) {
638+
639+
showTemplate($compile(template)(scope));
640+
}).catch(function onGetTemplateFailure(reason) {
616641

617-
var template = $templateCache.get($attrs.tooltipTemplateUrl);
618-
619-
if (typeof template !== 'undefined') {
620-
621-
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
622-
tipTipElement.empty();
623-
tipTipElement.append(closeButtonElement);
624-
tipTipElement.append($compile(template)(scope));
625-
$timeout(function doLater() {
626-
onTooltipShow();
627-
});
628-
}
642+
$log.error(reason);
643+
});
629644
} else {
630-
//hide tooltip because is empty
631-
tipTipElement.empty();
632-
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
645+
646+
hideTemplate();
633647
}
634648
}
635649
, onTooltipSideChange = function onTooltipSideChange(newValue) {

dist/angular-tooltips.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-tooltips.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-tooltips.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-tooltips",
3-
"version": "1.1.11",
3+
"version": "1.1.12",
44
"description": "Angular.js tooltips module.",
55
"homepage": "http://720kb.github.io/angular-tooltips",
66
"main": "index.js",

0 commit comments

Comments
 (0)