not really known
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.

80 lines
2.5 KiB

  1. /**
  2. _onyx.Tooltip_ is a kind of <a href="#onyx.Popup">onyx.Popup</a> that works
  3. with an <a href="#onyx.TooltipDecorator">onyx.TooltipDecorator</a>. It
  4. automatically displays a tooltip when the user hovers over the decorator.
  5. The tooltip is positioned around the decorator where there is available
  6. window space.
  7. {kind: "onyx.TooltipDecorator", components: [
  8. {kind: "onyx.Button", content: "Tooltip"},
  9. {kind: "onyx.Tooltip", content: "I'm a tooltip for a button."}
  10. ]}
  11. You may manually display the tooltip by calling its _show_ method.
  12. */
  13. enyo.kind({
  14. name: "onyx.Tooltip",
  15. kind: "onyx.Popup",
  16. classes: "onyx-tooltip below left-arrow",
  17. autoDismiss: false,
  18. showDelay: 500,
  19. defaultLeft: -6, //default margin-left value
  20. handlers: {
  21. onRequestShowTooltip: "requestShow",
  22. onRequestHideTooltip: "requestHide"
  23. },
  24. requestShow: function() {
  25. this.showJob = setTimeout(enyo.bind(this, "show"), this.showDelay);
  26. return true;
  27. },
  28. cancelShow: function() {
  29. clearTimeout(this.showJob);
  30. },
  31. requestHide: function() {
  32. this.cancelShow();
  33. return this.inherited(arguments);
  34. },
  35. showingChanged: function() {
  36. this.cancelShow();
  37. this.adjustPosition(true);
  38. this.inherited(arguments);
  39. },
  40. applyPosition: function(inRect) {
  41. var s = ""
  42. for (n in inRect) {
  43. s += (n + ":" + inRect[n] + (isNaN(inRect[n]) ? "; " : "px; "));
  44. }
  45. this.addStyles(s);
  46. },
  47. adjustPosition: function(belowActivator) {
  48. if (this.showing && this.hasNode()) {
  49. var b = this.node.getBoundingClientRect();
  50. //when the tooltip bottom goes below the window height move it above the decorator
  51. if (b.top + b.height > window.innerHeight) {
  52. this.addRemoveClass("below", false);
  53. this.addRemoveClass("above", true);
  54. } else {
  55. this.addRemoveClass("above", false);
  56. this.addRemoveClass("below", true);
  57. }
  58. //when the tooltip's right edge is out of the window, align it's right edge with the decorator left edge (approx)
  59. if (b.left + b.width > window.innerWidth){
  60. this.applyPosition({'margin-left': -b.width, bottom: "auto"});
  61. //use the right-arrow
  62. this.addRemoveClass("left-arrow", false);
  63. this.addRemoveClass("right-arrow", true);
  64. }
  65. }
  66. },
  67. resizeHandler: function() {
  68. //reset the tooltip to align it's left edge with the decorator
  69. this.applyPosition({'margin-left': this.defaultLeft, bottom: "auto"});
  70. this.addRemoveClass("left-arrow", true);
  71. this.addRemoveClass("right-arrow", false);
  72. this.adjustPosition(true);
  73. this.inherited(arguments);
  74. }
  75. });