<commit_before>/* See license.txt for terms of usage */

define([
    "firebug/lib/trace",
    "firebug/lib/locale",
    "firebug/lib/options",
    "firebug/lib/css",
    "firebug/lib/deprecated",
    "firebug/lib/system",
],
function(FBTrace, Locale, Options, Css, Deprecated, System) {

"use strict";

// ********************************************************************************************* //
// Constants

var Menu = {};

// ********************************************************************************************* //

Menu.createMenu = function(popup, item)
{
    if (typeof item == "string")
    {
        return Deprecated.deprecated("The function's header changed to "+
            "createMenu(popup, item)",
            Menu.createMenu, [popup, {label: item}])();
    }

    var elementName = "menu";

    // If a command is associated with the item we need to use 'splitmenu'.
    // xxxHonza: Split menu is not properly styled on Mac,
    // see: https://bugzilla.mozilla.org/show_bug.cgi?id=770316
    if (!System.isMac(window) && (item.command || item.commandID))
        elementName = "splitmenu";

    var menu = popup.ownerDocument.createElement(elementName);
    popup.appendChild(menu);

    Menu.setItemIntoElement(menu, item);

    this.createMenuPopup(menu, item);

    return menu;
};

Menu.createMenuPopup = function(parent, item)
{
    var menuPopup = parent.ownerDocument.createElement("menupopup");
    parent.appendChild(menuPopup);

    if (item.items)
    {
        for (var i = 0, len = item.items.length; i < len; ++i)
            Menu.createMenuItem(menuPopup, item.items[i]);
    }

    return menuPopup;
}

// Menu.createMenuItems(popup, items[, before])
Menu.createMenuItems = function(popup, items, before)
{
    for (var i=0; i<items.length; i++)
    {
        var item = items[i];

        // Override existing items to avoid duplicates.
        var existingItem = popup.querySelector("#" + item.id);
        if (existingItem)
        {
            Menu.createMenuItem(popup, item, existingItem);
            popup.removeChild(existingItem);
            continue;
        }

        Menu.createMenuItem(popup, item, before);
    }
};

Menu.createMenuItem = function(popup, item, before)
{
    if ((typeof(item) == "string" && item == "-") || item.label == "-")
        return Menu.createMenuSeparator(popup, item, before);

    var menuitem;

    if (item.items)
        menuitem = Menu.createMenu(popup, item);
    else
        menuitem = popup.ownerDocument.createElement("menuitem");

    Menu.setItemIntoElement(menuitem, item);

    if (before)
        popup.insertBefore(menuitem, before);
    else
        popup.appendChild(menuitem);

    return menuitem;
};

Menu.setItemIntoElement = function(element, item)
{
    var label = item.nol10n ? item.label : Locale.$STR(item.label);

    element.setAttribute("label", label);

    if (item.id)
        element.setAttribute("id", item.id);

    if (item.type)
        element.setAttribute("type", item.type);

    // Avoid closing the popup menu if a preference has been changed.
    // This allows to quickly change more options.
    if (item.type == "checkbox" && !item.closemenu)
        element.setAttribute("closemenu", "none");

    if (item.disabled)
        element.setAttribute("disabled", "true");

    if (item.image)
    {
        element.setAttribute("class", "menuitem-iconic");
        element.setAttribute("image", item.image);
    }

    if (item.command)
    {
        // xxxHonza: register 'click' event handler since 'command' isn't fired
        // by splitmenu binding from some reason.
        element.addEventListener("click", item.command, false);
    }
<commit_msg>Keep using 'command' event for menu elements and use 'click' only for splitmenu elements (related to issue 6692)<commit_after>/* See license.txt for terms of usage */

define([
    "firebug/lib/trace",
    "firebug/lib/locale",
    "firebug/lib/options",
    "firebug/lib/css",
    "firebug/lib/deprecated",
    "firebug/lib/system",
],
function(FBTrace, Locale, Options, Css, Deprecated, System) {

"use strict";

// ********************************************************************************************* //
// Constants

var Menu = {};

// ********************************************************************************************* //

Menu.createMenu = function(popup, item)
{
    if (typeof item == "string")
    {
        return Deprecated.deprecated("The function's header changed to "+
            "createMenu(popup, item)",
            Menu.createMenu, [popup, {label: item}])();
    }

    var elementName = "menu";

    // If a command is associated with the item we need to use 'splitmenu'.
    // xxxHonza: Split menu is not properly styled on Mac,
    // see: https://bugzilla.mozilla.org/show_bug.cgi?id=770316
    if (!System.isMac(window) && (item.command || item.commandID))
        elementName = "splitmenu";

    var menu = popup.ownerDocument.createElement(elementName);
    popup.appendChild(menu);

    Menu.setItemIntoElement(menu, item);

    this.createMenuPopup(menu, item);

    return menu;
};

Menu.createMenuPopup = function(parent, item)
{
    var menuPopup = parent.ownerDocument.createElement("menupopup");
    parent.appendChild(menuPopup);

    if (item.items)
    {
        for (var i = 0, len = item.items.length; i < len; ++i)
            Menu.createMenuItem(menuPopup, item.items[i]);
    }

    return menuPopup;
}

// Menu.createMenuItems(popup, items[, before])
Menu.createMenuItems = function(popup, items, before)
{
    for (var i=0; i<items.length; i++)
    {
        var item = items[i];

        // Override existing items to avoid duplicates.
        var existingItem = popup.querySelector("#" + item.id);
        if (existingItem)
        {
            Menu.createMenuItem(popup, item, existingItem);
            popup.removeChild(existingItem);
            continue;
        }

        Menu.createMenuItem(popup, item, before);
    }
};

Menu.createMenuItem = function(popup, item, before)
{
    if ((typeof(item) == "string" && item == "-") || item.label == "-")
        return Menu.createMenuSeparator(popup, item, before);

    var menuitem;

    if (item.items)
        menuitem = Menu.createMenu(popup, item);
    else
        menuitem = popup.ownerDocument.createElement("menuitem");

    Menu.setItemIntoElement(menuitem, item);

    if (before)
        popup.insertBefore(menuitem, before);
    else
        popup.appendChild(menuitem);

    return menuitem;
};

Menu.setItemIntoElement = function(element, item)
{
    var label = item.nol10n ? item.label : Locale.$STR(item.label);

    element.setAttribute("label", label);

    if (item.id)
        element.setAttribute("id", item.id);

    if (item.type)
        element.setAttribute("type", item.type);

    // Avoid closing the popup menu if a preference has been changed.
    // This allows to quickly change more options.
    if (item.type == "checkbox" && !item.closemenu)
        element.setAttribute("closemenu", "none");

    if (item.disabled)
        element.setAttribute("disabled", "true");

    if (item.image)
    {
        element.setAttribute("class", "menuitem-iconic");
        element.setAttribute("image", item.image);
    }

    if (item.command)
    {
        // xxxHonza: register 'click' event handler since 'command' isn't fired
        // by splitmenu binding from some reason.
        if (element.tagName == "splitmenu")
            element.addEventListener("click", item.command, false);
        else
            element.addEventListener("command", item.command, false);
    }

{'fraction_non_alphanumeric': 0.18031496062992125, 'fraction_numerical': 0.0031496062992125984, 'mean_word_length': 2.930376482723053, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2387606', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2178, 'n_words': 522}