动态添加弹出窗口后 XUL MenuItem 消失

发布于 2024-12-10 17:09:12 字数 2059 浏览 0 评论 0原文

我正在尝试将子菜单添加到动态构建的弹出菜单中,该菜单在您右键单击浏览器窗口中的任意位置时出现。第一级构建得很好,但是当我尝试向这些条目添加弹出窗口时,菜单项消失了。

这是我正在构建的对象:

var snpshot = {
    'Head':'', 
    'Subhead':'',
    'Date':'',
    'Url':'',
};

这是存储在 onLoad 事件中的代码,因此在浏览器启动时构建菜单:

似乎不起作用的部分是 rclickItem.appendChild(mPopup) - 它正在做“某事”,但弹出的菜单项被添加为空白并缩小,尽管将光标滚动到它上面似乎表明它们仍然存在。

  onLoad: function() {
    var mainPop = document.createElementNS(XUL_NS, "menupopup");
    mainPop.setAttribute('id', 'rclickMenu_MenuPopupContainer');

    //attach it to main rclick object
    var mainRclick = document.getElementById("rclickMenu_Main");
    mainRclick.appendChild(mainPop);

    mainOverlay.createMainRclick(); //THIS WORKS
    //add popups -- AS SOON AS THE POPUPS ARE ADDED THE ENTRIES DISAPPEAR!
    mainOverlay.createPopUpMenus();
},

createMenuItem: function(lblToUse){
    //create the XUL menuitem
    var itemToAdd = document.createElementNS(XUL_NS, "menuitem");
    itemToAdd.setAttribute('label',lblToUse);
    itemToAdd.setAttribute('id','rclickMenu_'+lblToUse);
    return itemToAdd;
},

createMenuPopup: function(idToUse){
    var mPopup = document.createElementNS(XUL_NS, "menupopup");
    mPopup.setAttribute('id','rclickMenuPopup_' + idToUse );
    return mPopup;
},

createMainRclick: function(){
    for (var property in snpshot){
        var mItem = mainOverlay.createMenuItem( property );
        var mainPop = document.getElementById("rclickMenu_MenuPopupContainer");
        mainPop.appendChild(mItem);
    }
},

createPopUpMenus: function(){
    for (var property in snpshot){
        var mPopup = mainOverlay.createMenuPopup( property );

        var rclickItem = document.getElementById("rclickMenu_"+property);
        rclickItem.appendChild(mPopup);
    }
},

和 XUL(这是右键单击时出现的主要弹出窗口,添加了我的菜单项(我在 js 中动态添加到该菜单项)

<menupopup id="contentAreaContextMenu">

    <menu 
     id="rclickMenu_Main" 
     label="Main Section">
    </menu>

</menupopup>

I am trying to add submenus to a dynamically built popup menu that appears when your right click anywhere in the browser window. The first level is built fine, but when I try to add a popup to those entries, the menu items disappear.

this is the object i'm building from:

var snpshot = {
    'Head':'', 
    'Subhead':'',
    'Date':'',
    'Url':'',
};

This is the code stored in my onLoad event so the menu is built when the browser starts:

the part that doesn't seem to work is rclickItem.appendChild(mPopup) -- it is doing 'something' but the menu entries the popup is added to go blank and shrink, though rolling the cursor over it seems to suggest that they are still there.

  onLoad: function() {
    var mainPop = document.createElementNS(XUL_NS, "menupopup");
    mainPop.setAttribute('id', 'rclickMenu_MenuPopupContainer');

    //attach it to main rclick object
    var mainRclick = document.getElementById("rclickMenu_Main");
    mainRclick.appendChild(mainPop);

    mainOverlay.createMainRclick(); //THIS WORKS
    //add popups -- AS SOON AS THE POPUPS ARE ADDED THE ENTRIES DISAPPEAR!
    mainOverlay.createPopUpMenus();
},

createMenuItem: function(lblToUse){
    //create the XUL menuitem
    var itemToAdd = document.createElementNS(XUL_NS, "menuitem");
    itemToAdd.setAttribute('label',lblToUse);
    itemToAdd.setAttribute('id','rclickMenu_'+lblToUse);
    return itemToAdd;
},

createMenuPopup: function(idToUse){
    var mPopup = document.createElementNS(XUL_NS, "menupopup");
    mPopup.setAttribute('id','rclickMenuPopup_' + idToUse );
    return mPopup;
},

createMainRclick: function(){
    for (var property in snpshot){
        var mItem = mainOverlay.createMenuItem( property );
        var mainPop = document.getElementById("rclickMenu_MenuPopupContainer");
        mainPop.appendChild(mItem);
    }
},

createPopUpMenus: function(){
    for (var property in snpshot){
        var mPopup = mainOverlay.createMenuPopup( property );

        var rclickItem = document.getElementById("rclickMenu_"+property);
        rclickItem.appendChild(mPopup);
    }
},

And the XUL (this is the main popup that comes up when you right click, with my menu item added (which I dynamically add to in the js)

<menupopup id="contentAreaContextMenu">

    <menu 
     id="rclickMenu_Main" 
     label="Main Section">
    </menu>

</menupopup>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2024-12-17 17:09:12

来自文档

它可以放置在菜单菜单列表工具栏按钮按钮

。 menuitem> 标签不在该列表中。事实上,您的 标记的父级应该是

标记 - 然后您将获得一个子菜单(请参阅 文档)。 标签始终是单个菜单项。

作为参考,将 添加到 标记时会发生什么:此标记会替换 自动生成的内容。。然而 不是视觉元素,因此您得到的是一个没有任何可见内容的菜单项。

From <menupopup> documentation:

It may be placed inside a menu, menulist, toolbarbutton, or a button

Note that <menuitem> tag is not on that list. In fact, the parents of your <menupopup> tags should be <menu> tags - then you will get a submenu (see documentation). A <menuitem> tag is always a single menu item.

For reference, what happens when you add <menupopup> to a <menuitem> tag: this tag replaces the auto-generated contents of <menuitem>. <menupopup> isn't a visual element however so what you get is a menu item without any visible content whatsoever.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文