jquery.popupmenu.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Simple popup menu 1.0 (2010-05-15)
  3. *
  4. * Copyright (c) 2010 Combodo SARL (www.combodo.com)
  5. * Licenced under the GPL licence.
  6. *
  7. * http://www.combodo.com/
  8. *
  9. * Built upon jQuery jQuery 1.2.3a (http://jquery.com)
  10. * Requires the jQuery positionBy plugin by Jonathan Sharp (http://jdsharp.us)
  11. */
  12. jQuery.fn.popupmenu = function ()
  13. {
  14. var popupmenu = null;
  15. return this.each(function()
  16. {
  17. $(this).bind('mouseenter.popup_menu click.popup_menu', function (evt)
  18. {
  19. var previous_popup = popupmenu;
  20. var bMenuClosed = false;
  21. popupmenu = $(this).find('ul');
  22. if ( previous_popup != null)
  23. {
  24. if ( ((evt.type == 'click') && ((previous_popup[0] == popupmenu[0])) || // Comparing the jQuery objects
  25. (evt.type == 'mouseenter') && (previous_popup[0] != popupmenu[0])) )
  26. // The user clicked again in the menu or moved over another menu let's close it
  27. previous_popup.css('display', 'none');
  28. bMenuClosed = true;
  29. }
  30. if ( (previous_popup == null) || (previous_popup[0] != popupmenu[0])) // Comparing the jQuery objects
  31. {
  32. // We really clicked in a different menu, let's open it
  33. popupmenu.bgiframe();
  34. popupmenu.positionBy({ target: $(this),
  35. targetPos: 2,
  36. elementPos: 0,
  37. hideAfterPosition: true
  38. });
  39. popupmenu.css('display', 'block');
  40. }
  41. if (bMenuClosed)
  42. {
  43. popupmenu = null;
  44. }
  45. evt.stopPropagation();
  46. });
  47. $(document).bind('click.popup_menu', function(evt)
  48. {
  49. if (popupmenu)
  50. {
  51. // The user clicked in the document's body, let's close the menu
  52. popupmenu.css('display', 'none');
  53. popupmenu = null;
  54. }
  55. });
  56. });
  57. };