menutip.js 895 B

1234567891011121314151617181920212223242526272829
  1. 
  2. var MenuTip = function (menu) {
  3. var template = '<div class="tooltip right menutip in"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>';
  4. var tip = $(template).appendTo(document.body);
  5. tip.hide();
  6. menu.element.on("mouseenter", ".menu-title", function (event) {
  7. if (!$("body").hasClass("compact")) return;
  8. var jq = $(event.currentTarget);
  9. var offset = jq.offset(),
  10. width = jq.outerWidth(),
  11. height = jq.outerHeight(),
  12. text = jq.text();
  13. tip.find(".tooltip-inner").html(text);
  14. tip.show();
  15. var tipWidth = tip.outerWidth(),
  16. tipHeight = tip.outerHeight();
  17. tip.css({ top: offset.top + height / 2 - tipHeight / 2, left: offset.left + width });
  18. });
  19. menu.element.on("mouseleave", ".menu-title", function (event) {
  20. tip.hide();
  21. });
  22. }