|
561 | 561 | registerOnScrollFrom(parentElement);
|
562 | 562 | }
|
563 | 563 | }
|
| 564 | + , showTemplate = function showTemplate(template) { |
| 565 | + |
| 566 | + tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty |
| 567 | + tipTipElement.empty(); |
| 568 | + tipTipElement.append(closeButtonElement); |
| 569 | + tipTipElement.append(template); |
| 570 | + $timeout(function doLater() { |
| 571 | + |
| 572 | + onTooltipShow(); |
| 573 | + }); |
| 574 | + } |
| 575 | + , hideTemplate = function hideTemplate() { |
| 576 | + |
| 577 | + //hide tooltip because is empty |
| 578 | + tipTipElement.empty(); |
| 579 | + tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 580 | + } |
| 581 | + , getTemplate = function getTemplate(tooltipTemplateUrl) { |
| 582 | + |
| 583 | + var template = $templateCache.get(tooltipTemplateUrl); |
| 584 | + |
| 585 | + if (typeof template === 'undefined') { |
| 586 | + |
| 587 | + // How should failing to load the template be handled? |
| 588 | + template = $http.get(tooltipTemplateUrl).then(function onGetTemplateSuccess(response) { |
| 589 | + |
| 590 | + return response.data; |
| 591 | + }); |
| 592 | + $templateCache.put(tooltipTemplateUrl, template); |
| 593 | + } |
| 594 | + |
| 595 | + return template; |
| 596 | + } |
564 | 597 | , onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
|
| 598 | + |
565 | 599 | if (newValue) {
|
566 |
| - tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty |
567 |
| - tipTipElement.empty(); |
568 |
| - tipTipElement.append(closeButtonElement); |
569 |
| - tipTipElement.append(newValue); |
570 |
| - $timeout(function doLaterShow() { |
571 |
| - |
572 |
| - onTooltipShow(); |
573 |
| - }); |
| 600 | + |
| 601 | + showTemplate(newValue); |
574 | 602 | } else {
|
575 |
| - //hide tooltip because is empty |
576 |
| - tipTipElement.empty(); |
577 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 603 | + |
| 604 | + hideTemplate(); |
578 | 605 | }
|
579 | 606 | }
|
580 | 607 | , onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
|
| 608 | + |
581 | 609 | if (newValue && !$attrs.tooltipTemplateUrlCache) {
|
582 |
| - |
583 |
| - $http.get(newValue).then(function onResponse(response) { |
584 |
| - |
585 |
| - if (response && |
586 |
| - response.data) { |
587 |
| - |
588 |
| - tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty |
589 |
| - tipTipElement.empty(); |
590 |
| - tipTipElement.append(closeButtonElement); |
591 |
| - tipTipElement.append($compile(response.data)(scope)); |
592 |
| - $timeout(function doLater() { |
593 |
| - |
594 |
| - onTooltipShow(); |
595 |
| - }); |
596 |
| - } |
| 610 | + |
| 611 | + getTemplate(newValue).then(function onGetTemplateSuccess(template) { |
| 612 | + |
| 613 | + showTemplate($compile(template)(scope)); |
| 614 | + }).catch(function onGetTemplateFailure(reason) { |
| 615 | + |
| 616 | + $log.error(reason); |
597 | 617 | });
|
598 | 618 | } else {
|
599 |
| - //hide tooltip because is empty |
600 |
| - tipTipElement.empty(); |
601 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 619 | + |
| 620 | + hideTemplate(); |
602 | 621 | }
|
603 | 622 | }
|
604 | 623 | , onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
|
| 624 | + |
605 | 625 | if (newValue && $attrs.tooltipTemplateUrl) {
|
| 626 | + |
| 627 | + getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) { |
| 628 | + |
| 629 | + showTemplate($compile(template)(scope)); |
| 630 | + }).catch(function onGetTemplateFailure(reason) { |
606 | 631 |
|
607 |
| - var template = $templateCache.get($attrs.tooltipTemplateUrl); |
608 |
| - |
609 |
| - if (typeof template !== 'undefined') { |
610 |
| - |
611 |
| - tooltipElement.removeClass('_force-hidden'); //see lines below, this forces to hide tooltip when is empty |
612 |
| - tipTipElement.empty(); |
613 |
| - tipTipElement.append(closeButtonElement); |
614 |
| - tipTipElement.append($compile(template)(scope)); |
615 |
| - $timeout(function doLater() { |
616 |
| - onTooltipShow(); |
617 |
| - }); |
618 |
| - } |
| 632 | + $log.error(reason); |
| 633 | + }); |
619 | 634 | } else {
|
620 |
| - //hide tooltip because is empty |
621 |
| - tipTipElement.empty(); |
622 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 635 | + |
| 636 | + hideTemplate(); |
623 | 637 | }
|
624 | 638 | }
|
625 | 639 | , onTooltipSideChange = function onTooltipSideChange(newValue) {
|
|
0 commit comments