popoverSrv.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. define([
  2. 'angular',
  3. 'lodash',
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.services');
  8. module.service('popoverSrv', function($templateCache, $timeout, $q, $http, $compile) {
  9. this.getTemplate = function(url) {
  10. return $q.when($templateCache.get(url) || $http.get(url, {cache: true}));
  11. };
  12. this.show = function(options) {
  13. var popover = options.element.data('popover');
  14. if (popover) {
  15. popover.scope.$destroy();
  16. popover.destroy();
  17. return;
  18. }
  19. this.getTemplate(options.templateUrl).then(function(result) {
  20. var template = _.isString(result) ? result : result.data;
  21. options.element.popover({
  22. content: template,
  23. placement: 'bottom',
  24. html: true
  25. });
  26. popover = options.element.data('popover');
  27. popover.hasContent = function () {
  28. return template;
  29. };
  30. popover.toggle();
  31. popover.scope = options.scope;
  32. $compile(popover.$tip)(popover.scope);
  33. });
  34. };
  35. });
  36. });