bsTooltip.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import angular from 'angular';
  2. import $ from 'jquery';
  3. import coreModule from './core_module';
  4. coreModule.directive('bsTooltip', [
  5. '$parse',
  6. '$compile',
  7. function ($parse: any, $compile: any) {
  8. return {
  9. restrict: 'A',
  10. scope: true,
  11. link: function postLink(scope: any, element: any, attrs: any) {
  12. var getter = $parse(attrs.bsTooltip),
  13. value = getter(scope);
  14. scope.$watch(attrs.bsTooltip, function (newValue: any, oldValue: any) {
  15. if (newValue !== oldValue) {
  16. value = newValue;
  17. }
  18. });
  19. // Grafana change, always hide other tooltips
  20. if (true) {
  21. element.on('show', function (ev: any) {
  22. $('.tooltip.in').each(function () {
  23. var $this = $(this),
  24. tooltip = $this.data('tooltip');
  25. if (tooltip && !tooltip.$element.is(element)) {
  26. $this.tooltip('hide');
  27. }
  28. });
  29. });
  30. }
  31. element.tooltip({
  32. title: function () {
  33. return angular.isFunction(value) ? value.apply(null, arguments) : value;
  34. },
  35. html: true,
  36. container: 'body', // Grafana change
  37. });
  38. var tooltip = element.data('tooltip');
  39. tooltip.show = function () {
  40. var r = $.fn.tooltip.Constructor.prototype.show.apply(this, arguments);
  41. this.tip().data('tooltip', this);
  42. return r;
  43. };
  44. scope._tooltip = function (event: any) {
  45. element.tooltip(event);
  46. };
  47. scope.hide = function () {
  48. element.tooltip('hide');
  49. };
  50. scope.show = function () {
  51. element.tooltip('show');
  52. };
  53. scope.dismiss = scope.hide;
  54. },
  55. };
  56. },
  57. ]);