extend-jquery.js 1.2 KB

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