jquery_extended.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. define(['jquery', 'angular', 'lodash'],
  2. function ($, angular, _) {
  3. 'use strict';
  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), width, height;
  13. $tooltip.addClass('grafana-tooltip');
  14. $("#tooltip").remove();
  15. $tooltip.appendTo(document.body);
  16. if (opts.compile) {
  17. angular.element(document).injector().invoke(["$compile", "$rootScope", function($compile, $rootScope) {
  18. var tmpScope = $rootScope.$new(true);
  19. _.extend(tmpScope, opts.scopeData);
  20. $compile($tooltip)(tmpScope);
  21. tmpScope.$digest();
  22. tmpScope.$destroy();
  23. }]);
  24. }
  25. width = $tooltip.outerWidth(true);
  26. height = $tooltip.outerHeight(true);
  27. $tooltip.css('left', x + opts.offset + width > $win.width() ? x - opts.offset - width : x + opts.offset);
  28. $tooltip.css('top', y + opts.offset + height > $win.height() ? y - opts.offset - height : y + opts.offset);
  29. });
  30. };
  31. })();
  32. return $;
  33. });