|
500 | 500 | registerOnScrollFrom(parentElement);
|
501 | 501 | }
|
502 | 502 | }
|
| 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 | + } |
503 | 536 | , onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
|
| 537 | + |
504 | 538 | 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); |
513 | 541 | } else {
|
514 |
| - //hide tooltip because is empty |
515 |
| - tipTipElement.empty(); |
516 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 542 | + |
| 543 | + hideTemplate(); |
517 | 544 | }
|
518 | 545 | }
|
519 | 546 | , onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
|
| 547 | + |
520 | 548 | 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); |
536 | 556 | });
|
537 | 557 | } else {
|
538 |
| - //hide tooltip because is empty |
539 |
| - tipTipElement.empty(); |
540 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 558 | + |
| 559 | + hideTemplate(); |
541 | 560 | }
|
542 | 561 | }
|
543 | 562 | , onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
|
| 563 | + |
544 | 564 | if (newValue && $attrs.tooltipTemplateUrl) {
|
| 565 | + |
| 566 | + getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) { |
| 567 | + |
| 568 | + showTemplate($compile(template)(scope)); |
| 569 | + }).catch(function onGetTemplateFailure(reason) { |
545 | 570 |
|
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 | + }); |
558 | 573 | } else {
|
559 |
| - //hide tooltip because is empty |
560 |
| - tipTipElement.empty(); |
561 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 574 | + |
| 575 | + hideTemplate(); |
562 | 576 | }
|
563 | 577 | }
|
564 | 578 | , onTooltipSideChange = function onTooltipSideChange(newValue) {
|
|
0 commit comments