javascript - 将上下文菜单项分组在一起

标签 javascript firefox firefox-addon firefox-addon-restartless

在 Firefox Bootstrapped Addons 中,必须手动插入/删除、启用/禁用以及隐藏/取消隐藏上下文菜单项。

我想知道是否可以将它们组合成一个元素(作为该元素的子元素),以便该组可以作为一个元素进行处理,即可以删除父节点,从而删除其所有子元素。

例如:

<some parent element for grouping>
    <menuseparator/>
    <menuitem .... />
    <menuitem .... />
    <menuseparator/>
    <menuitem .... />
    <menuseparator/>
</some parent element for grouping>

我尝试将它们放入 <menu> ... </menu>但这缩进了 menuitem

更新:
我注意到 Flashgot 覆盖有一个混合分组 menuitemmenupopup enter image description here

<popup id="contentAreaContextMenu">  
  <menu id="flashgot-submenu" hidden="true" persist="hidden" label="FlashGot" class="menu-iconic flashgot-icon-lnk" accesskey="&flashgotLink.accesskey;" insertbefore="context-sep-selectall,context-sep-stop,context-sep-copylink" >
      <menupopup>
          <menuseparator id="flashgot-submenu-anchor" hidden="true" />
          <menuitem id="flashgot-menuitem-it" label="&flashgotLink;" accesskey="&flashgotLink.accesskey;" oncommand="gFlashGot.downloadPopupLink()" key="flashgot-link-key" class="menuitem-iconic flashgot-icon-lnk" />
          <menuitem id="flashgot-menuitem-sel" label="&flashgotSel;" accesskey="&flashgotSel.accesskey;" oncommand="gFlashGot.delayCmd('Sel')" key="flashgot-sel-key" class="menuitem-iconic flashgot-icon-sel" />
          <menuitem id="flashgot-menuitem-all" label="&flashgotAll;" accesskey="&flashgotAll.accesskey;" oncommand="gFlashGot.delayCmd('All')" key="flashgot-all-key" class="menuitem-iconic flashgot-icon-all" />
          <menuitem id="flashgot-menuitem-tabs" label="&flashgotTabs;" accesskey="&flashgotTabs.accesskey;" oncommand="gFlashGot.delayCmd('Tabs')" key="flashgot-tabs-key" class="menuitem-iconic flashgot-icon-tabs" />
          <menuitem id="flashgot-menuitem-media" label="&flashgotMedia;" oncommand="gFlashGot.downloadMedia()" key="flashgot-media-key" class="menuitem-iconic flashgot-icon-media" />

          <menuitem id="flashgot-menuitem-buildGallery" label="&flashgotBuildGallery;" class="menuitem-iconic flashgot-icon-buildGallery" oncommand="gFlashGot.buildGallery()" />
              <menu id="flashgot-menu-options" class="menu-iconic flashgot-icon-opts" label="&flashgotOptions;" >
                  <menupopup id="flashgot-menupopup-options" onpopupshowing="gFlashGot.prepareOptsMenu(event.target)">
                  <menuitem id="flashgot-ctx-menuitem-nodms" hidden="true" label="&flashgotNoDMS;" oncommand="gFlashGotService.showDMSReference()" />
                  <menuseparator id="flashgot-ctx-sep-nodms" />
                  <menuitem id="flashgot-ctx-menuitem-opt-autoStart" label="&flashgotAutostart;" type="checkbox" oncommand="gFlashGot.switchOption('autoStart')" />
                  <menuitem id="flashgot-ctx-menuitem-opt-includeImages" label="&includeImages.label;" type="checkbox" oncommand="gFlashGot.switchOption('includeImages')" />
                  <menuitem id="flashgot-ctx-menuitem-opts" label="&flashgotMoreOpts;" oncommand="gFlashGot.openOptionsDialog()" />
                  <menuseparator id="flashgot-ctx-sep-about" />
                  <menuitem id="flashgot-ctx-menuitem-about" label="&flashgotAbout;" oncommand="gFlashGot.openAboutDialog()" />
                  <menuitem id="flashgot-ctx-homepage" label="&flashgotVisitHomepage;" oncommand="gFlashGot.browseHomePage()" />
                  </menupopup>
              </menu>
      </menupopup>
  </menu>  

  <menuseparator id="flashgot-context-separator" hidden="true" insertbefore="context-sep-selectall,context-sep-stop,context-sep-copylink" /> 
  <menuseparator id="flashgot-context-separator2" hidden="true" insertbefore="context-sep-selectall,context-sep-stop,context-sep-copylink" />   
</popup> 

第一个是正常的。第二个是插入 menuitem 之后在 <menu class="menu-iconic>

Normal After inserting in a <code><menu class="menu-iconic></code>

最佳答案

一个<menupopup>喜欢 contentAreaContextMenu期望包含单独的项目(元素),因此即使有一个跨平台可靠工作的黑客,它也只是一个黑客,随时可能崩溃。所以不,您无法可靠地将菜单项逻辑地分组在一起,但这些菜单项仍会作为单独的项目显示在 UI 中。

此外,您不应添加其他不相关的内容,例如 <keyset>进入<menupopup> 。同样的原因:可能随时破裂。 (而 <keyset> 是一种至少对 <key> 元素进行逻辑分组的方法...)

关于javascript - 将上下文菜单项分组在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544539/

相关文章:

javascript - 在使用之前检测 window.close() 是否有效(JavaScript)

javascript - 如何使用键盘移动 svg 路径中​​的对象

javascript - NetUtil.asyncCopy 从一个文件附加到 Firefox 扩展中的另一个文件

firefox 扩展中的 jQuery UI 位置实用程序

javascript - 如何在一个php文件上显示数据库中的不同内容?

javascript - 什么是控制台.log?

html - Firefox 上带有固定 header 的 CSS 视差

xml - xsd 架构引用和类型属性值的命名空间如何别名/绑定(bind)?

javascript - CSS/JavaScript : How to draw minimal border around an inline element?

javascript - 将 Chrome 扩展移植到 Firefox