You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.2 KiB

  1. define([
  2. 'js/system/events',
  3. 'css!ui/templates/tooltips/styles',
  4. 'html!ui/templates/tooltips/template',
  5. 'html!ui/templates/tooltips/templateTooltip'
  6. ], function (
  7. events,
  8. styles,
  9. template,
  10. tplTooltip
  11. ) {
  12. return {
  13. tpl: template,
  14. type: 'tooltips',
  15. tooltip: null,
  16. el: null,
  17. hoverEl: null,
  18. postRender: function () {
  19. this.tooltip = this.el.find('.tooltip');
  20. this.onEvent('onShowTooltip', this.onShowTooltip.bind(this));
  21. this.onEvent('onHideTooltip', this.onHideTooltip.bind(this));
  22. },
  23. onHideTooltip: function (el) {
  24. if (this.hoverEl != el)
  25. return;
  26. this.hoverEl = null;
  27. this.tooltip.hide();
  28. },
  29. onShowTooltip: function (text, el, pos, width, bottomAlign, rightAlign, zIndex) {
  30. this.hoverEl = el;
  31. this.tooltip
  32. .html(text)
  33. .attr('class', 'tooltip');
  34. this.tooltip
  35. .show();
  36. if (width)
  37. this.tooltip.width(width);
  38. if (pos) {
  39. if (bottomAlign)
  40. pos.y -= this.tooltip.height();
  41. if (rightAlign)
  42. pos.x -= this.tooltip.width();
  43. this.tooltip.css({
  44. left: pos.x,
  45. top: pos.y
  46. });
  47. }
  48. if ((zIndex) && (zIndex != 'auto'))
  49. this.tooltip.css('zIndex', zIndex);
  50. else
  51. this.tooltip.css('zIndex', '');
  52. }
  53. };
  54. });