|
1 | 1 | /*
|
2 | 2 | * angular-tooltips
|
3 |
| - * 1.1.11 |
| 3 | + * 1.1.12 |
4 | 4 | *
|
5 | 5 | * Angular.js tooltips module.
|
6 | 6 | * http://720kb.github.io/angular-tooltips
|
7 | 7 | *
|
8 | 8 | * MIT license
|
9 |
| - * Thu May 18 2017 |
| 9 | + * Sat May 20 2017 |
10 | 10 | */
|
11 | 11 | /*global angular,window*/
|
12 | 12 | (function withAngular(angular, window) {
|
|
571 | 571 | registerOnScrollFrom(parentElement);
|
572 | 572 | }
|
573 | 573 | }
|
| 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 | + } |
574 | 607 | , onTooltipTemplateChange = function onTooltipTemplateChange(newValue) {
|
| 608 | + |
575 | 609 | 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); |
584 | 612 | } else {
|
585 |
| - //hide tooltip because is empty |
586 |
| - tipTipElement.empty(); |
587 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 613 | + |
| 614 | + hideTemplate(); |
588 | 615 | }
|
589 | 616 | }
|
590 | 617 | , onTooltipTemplateUrlChange = function onTooltipTemplateUrlChange(newValue) {
|
| 618 | + |
591 | 619 | 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); |
607 | 627 | });
|
608 | 628 | } else {
|
609 |
| - //hide tooltip because is empty |
610 |
| - tipTipElement.empty(); |
611 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 629 | + |
| 630 | + hideTemplate(); |
612 | 631 | }
|
613 | 632 | }
|
614 | 633 | , onTooltipTemplateUrlCacheChange = function onTooltipTemplateUrlCacheChange(newValue) {
|
| 634 | + |
615 | 635 | if (newValue && $attrs.tooltipTemplateUrl) {
|
| 636 | + |
| 637 | + getTemplate($attrs.tooltipTemplateUrl).then(function onGetTemplateSuccess(template) { |
| 638 | + |
| 639 | + showTemplate($compile(template)(scope)); |
| 640 | + }).catch(function onGetTemplateFailure(reason) { |
616 | 641 |
|
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 | + }); |
629 | 644 | } else {
|
630 |
| - //hide tooltip because is empty |
631 |
| - tipTipElement.empty(); |
632 |
| - tooltipElement.addClass('_force-hidden'); //force to be hidden if empty |
| 645 | + |
| 646 | + hideTemplate(); |
633 | 647 | }
|
634 | 648 | }
|
635 | 649 | , onTooltipSideChange = function onTooltipSideChange(newValue) {
|
|
0 commit comments