jquery.popupmenu.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. console.log(evt.type);
  20. var previous_popup = popupmenu;
  21. var bMenuClosed = false;
  22. popupmenu = $(this).find('ul');
  23. if ( previous_popup != null)
  24. {
  25. if ( ((evt.type == 'click') && ((previous_popup[0] == popupmenu[0])) || // Comparing the jQuery objects
  26. (evt.type == 'mouseenter') && (previous_popup[0] != popupmenu[0])) )
  27. // The user clicked again in the menu or moved over another menu let's close it
  28. previous_popup.css('display', 'none');
  29. bMenuClosed = true;
  30. }
  31. if ( (previous_popup == null) || (previous_popup[0] != popupmenu[0])) // Comparing the jQuery objects
  32. {
  33. // We really clicked in a different menu, let's open it
  34. popupmenu.bgiframe();
  35. popupmenu.positionBy({ target: $(this),
  36. targetPos: 2,
  37. elementPos: 0,
  38. hideAfterPosition: true
  39. });
  40. popupmenu.css('display', 'block');
  41. }
  42. if (bMenuClosed)
  43. {
  44. popupmenu = null;
  45. }
  46. evt.stopPropagation();
  47. });
  48. $(document).bind('click.popup_menu', function(evt)
  49. {
  50. if (popupmenu)
  51. {
  52. // The user clicked in the document's body, let's close the menu
  53. popupmenu.css('display', 'none');
  54. popupmenu = null;
  55. }
  56. });
  57. });
  58. };