Skip to content

Commit

Permalink
fix for template-url-cache thanks to @leonard-thieu #204
Browse files Browse the repository at this point in the history
  • Loading branch information
45kb committed May 20, 2017
1 parent 6fb45a3 commit 5e7cc33
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 56 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-tooltips",
"version": "1.1.11",
"version": "1.1.12",
"description": "Angular.js tooltips module.",
"authors": [
"Filippo Oretti <[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-tooltips.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* angular-tooltips
* 1.1.11
* 1.1.12
*
* Angular.js tooltips module.
* http://720kb.github.io/angular-tooltips
*
* MIT license
* Thu May 18 2017
* Sat May 20 2017
*/
@-webkit-keyframes animate-tooltip {
0% {
Expand Down
106 changes: 60 additions & 46 deletions dist/angular-tooltips.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* angular-tooltips
* 1.1.11
* 1.1.12
*
* Angular.js tooltips module.
* http://720kb.github.io/angular-tooltips
*
* MIT license
* Thu May 18 2017
* Sat May 20 2017
*/
/*global angular,window*/
(function withAngular(angular, window) {
Expand Down Expand Up @@ -571,65 +571,79 @@
registerOnScrollFrom(parentElement);
}
}
, showTemplate = function showTemplate(template) {

tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
tipTipElement.empty();
tipTipElement.append(closeButtonElement);
tipTipElement.append(template);
$timeout(function doLater() {

onTooltipShow();
});
}
, hideTemplate = function hideTemplate() {

//hide tooltip because is empty
tipTipElement.empty();
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty
}
, getTemplate = function getTemplate(tooltipTemplateUrl) {

var template = $templateCache.get(tooltipTemplateUrl);

if (typeof template === 'undefined') {

// How should failing to load the template be handled?
template = $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) {

return response.data;
});
$templateCache.put(tooltipTemplateUrl, template);
}

return template;
}
, onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {

if (newValue) {
tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
tipTipElement.empty();
tipTipElement.append(closeButtonElement);
tipTipElement.append(newValue);
$timeout(function doLaterShow() {

onTooltipShow();
});

showTemplate(newValue);
} else {
//hide tooltip because is empty
tipTipElement.empty();
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty

hideTemplate();
}
}
, onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {

if (newValue && !$attrs.tooltipTemplateUrlCache) {

$http.get(newValue).then(function onResponse(response) {

if (response &&
response.data) {

tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
tipTipElement.empty();
tipTipElement.append(closeButtonElement);
tipTipElement.append($compile(response.data)(scope));
$timeout(function doLater() {

onTooltipShow();
});
}

getTemplate(newValue).then(function onGetTemplateSuccess(template) {

showTemplate($compile(template)(scope));
}).catch(function onGetTemplateFailure(reason) {

$log.error(reason);
});
} else {
//hide tooltip because is empty
tipTipElement.empty();
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty

hideTemplate();
}
}
, onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {

if (newValue && $attrs.tooltipTemplateUrl) {

getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) {

showTemplate($compile(template)(scope));
}).catch(function onGetTemplateFailure(reason) {

var template = $templateCache.get($attrs.tooltipTemplateUrl);

if (typeof template !== 'undefined') {

tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty
tipTipElement.empty();
tipTipElement.append(closeButtonElement);
tipTipElement.append($compile(template)(scope));
$timeout(function doLater() {
onTooltipShow();
});
}
$log.error(reason);
});
} else {
//hide tooltip because is empty
tipTipElement.empty();
tooltipElement.addClass('_force-hidden'); //force to be hidden if empty

hideTemplate();
}
}
, onTooltipSideChange = function onTooltipSideChange(newValue) {
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-tooltips.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/angular-tooltips.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/angular-tooltips.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-tooltips",
"version": "1.1.11",
"version": "1.1.12",
"description": "Angular.js tooltips module.",
"homepage": "http://720kb.github.io/angular-tooltips",
"main": "index.js",
Expand Down

0 comments on commit 5e7cc33

Please sign in to comment.