Guest User

Untitled

a guest
Sep 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. var HoveredTooltip = new Class({
  2.  
  3. Implements: [Events, Options],
  4.  
  5. options: {
  6. altClass: '',
  7. type: 'top',
  8. position: 'topRight',
  9. egde: 'bottomRight',
  10. timneout: 0,
  11. rollover: true
  12. },
  13.  
  14. initialize: function(options){
  15. this.setOptions(options);
  16. this.showTimeout;
  17. this.hideTimeout;
  18.  
  19. this.container = new Element('div', {
  20. 'class': 'hovered-tooltip ' + this.options.altClass,
  21. html: '<div class="arrow"></div>'
  22. });
  23.  
  24. this.content = new Element('div', {
  25. 'class': 'tooltip-content'
  26. }).inject(this.container);
  27.  
  28. this.container.hide().inject(document.body);
  29. },
  30.  
  31. show: function(content, elem){
  32. this.hide();
  33.  
  34. elem.addEvents({
  35. 'mouseenter': function(e){
  36. clearTimeout(this.hideTimeout);
  37. e.stop();
  38.  
  39. this.showTimeout = setTimeout(function(){
  40. // Insert Element or string
  41. if (typeOf(content) === 'element') {
  42. this.content.empty().adopt(content);
  43. } else {
  44. this.content.set('html', content);
  45. }
  46.  
  47. this.container.show();
  48. this.container.position({
  49. relativeTo: elem,
  50. position: this.options.position,
  51. edge: this.options.edge
  52. });
  53. }.bind(this), this.options.timeout);
  54. }.bind(this),
  55.  
  56. 'mouseleave': function(e){
  57. e.stop();
  58.  
  59. if(this.options.rollover){
  60. clearTimeout(this.showTimeout);
  61. } else {
  62. this.hide();
  63. }
  64. }.bind(this),
  65.  
  66. 'mouseover': function(e){
  67. e.stop();
  68. }
  69. });
  70.  
  71. this.container.addEvents({
  72. 'mouseenter': function(e){
  73. e.stop();
  74. }.bind(this),
  75.  
  76. 'mouseleave': function(e){
  77. e.stop()
  78. }.bind(this),
  79.  
  80. 'mouseover': function(e){
  81. e.stop();
  82. }
  83. });
  84.  
  85. document.addEvent('mouseover', function(){
  86. clearTimeout(this.showTimeout);
  87. this.hideTimeout = setTimeout(function(){
  88. this.hide();
  89. }.bind(this), this.options.timeout);
  90. }.bind(this));
  91. },
  92.  
  93. hide: function(){
  94. this.container.hide();
  95. }
  96.  
  97. });
Add Comment
Please, Sign In to add comment