local menu = LibStub('LibMenuAssist-1.0'):New()
menu:SetAnchor(0, 0, 'TOP', myAddon.button, 'BOTTOM')
menu[0] = function(self, level)
-- Called first each time menu.initialize is called
end
menu[1] = function(self, level)
-- Called when menu.initialize is called and level == 1 (*)
end
menu[2] = function(self, level)
-- Called when menu.initialize is called and level == 2 (*)
end
myAddon.button:SetScript('OnClick', function()
menu:Open()
end)

(*) - menu[1+] can be assigned a table instead, which will be processed via EasyMenu_Initialize.

API

menu = lib:New()

Create a new menu object.

Returns:

menu - (table) The menu object to be used by the calling code (see Menu Objects below).

Menu Objects

Any menu created by lib:New() is a normal table that emulates certain frame behaviors to allow it to work with the Blizzard's UIDropDownMenu code. A metatable provides the following frame-like methods: GetScript, HasScript, Hide, IsShown, IsVisible, SetScript, and Show. The only scripts supported by a menu are OnHide and OnShow. The metatable also defaults the field displayMode to 'MENU', set it to false to override. Menus also have the following additional methods:

menu:AddFocusFrame(frame)

Add a frame that is to be considered a part of the menu when calling the methods HasMouseFocus and UpdateAutoHide.

Arguments:

frame - (table) The frame to be added.

wasOpen = menu:Close()

Close the menu.

Returns:

wasOpen - (boolean or nil) True if the menu was open, nil otherwise.

hasFocus = menu:HasMouseFocus()

Determines if GetMouseFocus() returns any portion of the menu or a frame added with the method AddFocusFrame.

Returns:

hasFocus - (boolean or nil) True if the mouse focus is part of the menu, nil otherwise.

isOpen = menu:IsOpen()

Determines if the menu is open.

Returns:

isOpen - (boolean or nil) True if the menu is open, nil otherwise.

level = menu:Open([...])

Open the menu to level 1 and attempt to open additional menu levels with any values passed as arguements.

Similar to UIDropDownMenu_SetAnchor, it updates the menu values but also automatically updates the menu's position if any values have changed.

Arguments:

xOffset - (number or nil) The new value for menu.xOffset.
yOffset - (number or nil) The new value for menu.yOffset.
point - (string or nil) The new value for menu.point.
relativeTo - (string, table, or nil) The new value for menu.relativeTo.
relativePoint - (string or nil) The new value for menu.relativePoint.

Returns:

updated - (boolean or nil) True if the menu was updated, nil otherwise.

isOpen = menu:Toggle()

Close the menu if it is open, otherwise opens it.

Returns:

isOpen - (boolean or nil) True if the menu is open, nil otherwise.

isOpen = menu:UpdateAutoHide()

Starts, stops, or resets the menu's countdown to auto-hide based on the return value of the method HasMouseFocus.

Returns:

isOpen - (boolean or nil) True if the menu is open, nil otherwise.

Version 1.0.4 (12/25/2013)
- Menus opened at the cursor will now stay put when refreshed

Version 1.0.3 (10/06/2012)
- Rewrote the menu method Refresh to better handle major changes to a menu
- Added the ability to open directly to a sub-menu with the menu method Open

Version 1.0.2 (10/01/2012)
- Added the menu method RemoveAllFocusFrames
- The menu methods AddFocusFrame, RemoveAllFocusFrames, and RemovFocusFrame now all call UpdateAutoHide if menu is open