jquery_extended.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import $ from 'jquery';
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. var $win = $(window);
  5. $.fn.place_tt = (function() {
  6. var defaults = {
  7. offset: 5,
  8. };
  9. return function(x, y, opts) {
  10. opts = $.extend(true, {}, defaults, opts);
  11. return this.each(function() {
  12. var $tooltip = $(this),
  13. width,
  14. height;
  15. $tooltip.addClass('grafana-tooltip');
  16. $('#tooltip').remove();
  17. $tooltip.appendTo(document.body);
  18. if (opts.compile) {
  19. angular
  20. .element(document)
  21. .injector()
  22. .invoke([
  23. '$compile',
  24. '$rootScope',
  25. function($compile, $rootScope) {
  26. var tmpScope = $rootScope.$new(true);
  27. _.extend(tmpScope, opts.scopeData);
  28. $compile($tooltip)(tmpScope);
  29. tmpScope.$digest();
  30. tmpScope.$destroy();
  31. },
  32. ]);
  33. }
  34. width = $tooltip.outerWidth(true);
  35. height = $tooltip.outerHeight(true);
  36. $tooltip.css('left', x + opts.offset + width > $win.width() ? x - opts.offset - width : x + opts.offset);
  37. $tooltip.css('top', y + opts.offset + height > $win.height() ? y - opts.offset - height : y + opts.offset);
  38. });
  39. };
  40. })();