Guest User

Untitled

a guest
Sep 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. (function() {
  2. var Tooltip,
  3. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  4.  
  5. Tooltip = (function() {
  6.  
  7. Tooltip.el = null;
  8.  
  9. Tooltip.tooltip = null;
  10.  
  11. Tooltip.open = false;
  12.  
  13. Tooltip.closeTimer = null;
  14.  
  15. Tooltip.topMargin = null;
  16.  
  17. function Tooltip(el) {
  18. this.findPos = __bind(this.findPos, this);
  19. this.hide = __bind(this.hide, this);
  20. this.show = __bind(this.show, this);
  21. this.createTooltip = __bind(this.createTooltip, this);
  22. this.mouseOut = __bind(this.mouseOut, this);
  23. this.tooltipMouseOver = __bind(this.tooltipMouseOver, this);
  24. this.mouseOver = __bind(this.mouseOver, this);
  25. this.bindEvents = __bind(this.bindEvents, this); this.el = $(el);
  26. this.createTooltip();
  27. this.bindEvents();
  28. }
  29.  
  30. Tooltip.prototype.bindEvents = function() {
  31. this.el.bind('mouseover', this.mouseOver);
  32. return this.el.bind('mouseout', this.mouseOut);
  33. };
  34.  
  35. Tooltip.prototype.mouseOver = function() {
  36. if (this.open) {
  37. return clearTimeout(this.closeTimer);
  38. } else {
  39. return this.show();
  40. }
  41. };
  42.  
  43. Tooltip.prototype.tooltipMouseOver = function() {
  44. return clearTimeout(this.closeTimer);
  45. };
  46.  
  47. Tooltip.prototype.mouseOut = function() {
  48. return this.closeTimer = setTimeout(this.hide, 100);
  49. };
  50.  
  51. Tooltip.prototype.createTooltip = function() {
  52. var el;
  53. el = $('<div></div>').attr('class', 'tooltip').append($('<i>')).append($("<span class='inner'>" + (this.el.data('tooltip')) + "</div>")).bind('mouseover', this.tooltipMouseOver).bind('mouseout', this.mouseOut);
  54. return this.tooltip = el;
  55. };
  56.  
  57. Tooltip.prototype.show = function() {
  58. var pos;
  59. if (this.open) return;
  60. this.open = true;
  61. $('body').append(this.tooltip);
  62. this.topMargin = this.tooltip.css('margin-top');
  63. pos = this.findPos();
  64. this.tooltip.css('top', "" + pos.top + "px").css('left', "" + pos.left + "px");
  65. return this.tooltip.animate({
  66. opacity: 1,
  67. 'margin-top': '0px'
  68. }, 200);
  69. };
  70.  
  71. Tooltip.prototype.hide = function() {
  72. var _this = this;
  73. return this.tooltip.animate({
  74. opacity: 0,
  75. 'margin-top': this.topMargin
  76. }, 200, function() {
  77. _this.tooltip.detach();
  78. return _this.open = false;
  79. });
  80. };
  81.  
  82. Tooltip.prototype.findPos = function() {
  83. var pos;
  84. pos = this.el.offset();
  85. pos.left += this.el.width() / 2;
  86. pos.top -= this.tooltip.outerHeight();
  87. pos.left -= this.tooltip.outerWidth() / 2;
  88. return pos;
  89. };
  90.  
  91. return Tooltip;
  92.  
  93. })();
  94.  
  95. jQuery.fn.extend({
  96. tooltip: function() {
  97. return this.each(function() {
  98. return new Tooltip(this);
  99. });
  100. }
  101. });
  102.  
  103. }).call(this);
Add Comment
Please, Sign In to add comment