tooltip.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. function createTooltip(frameDiv) {
  2. var tooltip = function(frameDiv) {
  3. var div = document.createElement('DIV');
  4. div.className = "twipsy right";
  5. var arrow = document.createElement('DIV');
  6. arrow.className = "twipsy-arrow";
  7. div.appendChild(arrow);
  8. var title = document.createElement('DIV');
  9. title.className = "twipsy-inner";
  10. div.appendChild(title);
  11. this._div = div;
  12. this._title = title;
  13. this.message = '';
  14. // add to frame div and display coordinates
  15. frameDiv.appendChild(div);
  16. var that = this;
  17. div.onmousemove = function(evt){
  18. that.showAt({x : evt.clientX,y : evt.clientY},that.message);
  19. };
  20. };
  21. tooltip.prototype.setVisible = function(visible) {
  22. this._div.style.display = visible ? 'block' : 'none';
  23. };
  24. tooltip.prototype.showAt = function(position, message) {
  25. if(position && message) {
  26. this.setVisible(true);
  27. this._title.innerHTML = message;
  28. this._div.style.left = position.x + 10 + "px";
  29. this._div.style.top = (position.y - this._div.clientHeight / 2) + "px";
  30. this.message = message;
  31. }
  32. };
  33. return new tooltip(frameDiv);
  34. }