MenuManager.appendMenuItem Member
Appends a menuitem to an existing menu or popup.
Syntax
object.appendMenuItem(parentNode, beforeNode, commandName, attribs);
Arguments
Argument | Summary |
---|---|
parentNode | DOM Node to insert into |
beforeNode | DOM Node already contained by parentNode, to insert before |
commandName | |
attribs | Object containing CSS attributes to set on the element. |
Returns
Remarks
See Also
Source Code
function mmgr_addmenu (parentNode, beforeNode, commandName, attribs)
{
var menuManager = this;
var document = parentNode.ownerDocument;
if (commandName == "-")
return this.appendMenuSeparator(parentNode, beforeNode, attribs);
var parentId = parentNode.getAttribute("id");
if (!ASSERT(commandName in this.commandManager.commands,
"unknown command " + commandName + " targeted for " +
parentId))
{
return null;
}
var command = this.commandManager.commands[commandName];
var menuitem = document.createElement ("menuitem");
menuitem.setAttribute ("id", parentId + ":" + commandName);
menuitem.setAttribute ("commandname", command.name);
// Add keys if this isn't a context menu:
if (parentId.indexOf("context") != 0)
menuitem.setAttribute("key", "key:" + command.name);
menuitem.setAttribute("accesskey", command.accesskey);
var label = command.label.replace("&", "");
menuitem.setAttribute ("label", label);
if (command.format)
{
menuitem.setAttribute("format", command.format);
menuitem.setAttribute("backupLabel", label);
}
if ((typeof attribs == "object") && attribs)
{
for (var p in attribs)
menuitem.setAttribute (p, attribs[p]);
if ("repeatfor" in attribs)
menuitem.setAttribute("repeatid", this.repeatId++);
}
command.uiElements.push(menuitem);
parentNode.insertBefore (menuitem, beforeNode);
/* It seems, bob only knows why, that this must be done AFTER the node is
* added to the document.
*/
menuitem.addEventListener("command", this.onMenuCommand, false);
return menuitem;
}