jquery.popupmenu.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 (modified) 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('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. // The user clicked while a menu is open, close the currently opened menu
  25. previous_popup.css('display', 'none');
  26. }
  27. if ( (previous_popup == null) || (previous_popup.get(0) != popupmenu.get(0))) // Comparing the DOM objects
  28. {
  29. // The user clicked in a different menu, let's open it
  30. popupmenu.bgiframe();
  31. popupmenu.positionBy({ target: $(this),
  32. targetPos: 4,
  33. elementPos: 0,
  34. hideAfterPosition: true
  35. });
  36. popupmenu.css('display', 'block');
  37. }
  38. else
  39. {
  40. // The user clicked in the opened menu, it is closed now
  41. popupmenu = null;
  42. }
  43. evt.stopPropagation();
  44. });
  45. $(document).bind('click.popup_menu', function(evt)
  46. {
  47. if (popupmenu)
  48. {
  49. // The user clicked in the document's body, let's close the menu
  50. popupmenu.css('display', 'none');
  51. popupmenu = null;
  52. }
  53. });
  54. });
  55. };