Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

setEntry with a hash to set the title and uiIcon breaks the menu item. #110

Closed
@ekangas1

Description

@ekangas1

This is using jQuery UI v1.12.1 and jQuery v1.12.4; context menu v 1.13.0

Expected

   x.contextmenu("setEntry", "toggle_html", {
               title: "Display HTML Content - Shift-H",
               uiIcon: is_on ? "ui-icon-check" : "ui-icon-blank"
               });

On a menu that has an item whose cmd is "toggle_html" ... this should update the title and change the menu icon. This worked before (I am upgrading from contextmenu 1.3 -> contextmenu 1.13 and from jQuery 1.11).

The bug is that the menu item is replaced but with the incorrect/missing attibutes in the <div ...> ... so that the displayed menu looks broken. I.e. the inspected HTML after execution of this command should look like:

<div id="ui-id-4" class="ui-menu-item-wrapper" tabindex="-1" role="menuitem">
Display HTML Content - Shift-H
<span class="ui-icon ui-icon-check"></span>
</div>

But instead it looks like:

<div>
Display HTML Content - Shift-H
<span class="ui-icon ui-icon-check"></span>
</div>

I have worked around the problem for now by re-writing setEntry to set the title and icon explicitly rather than using the full hash reset option in there.

   /** Redefine menu entry (title or all of it). */
   setEntry: function(cmd, entry) {
      var $ul,
         $entryLi = this._getMenuEntry(cmd);

      if (typeof entry === "string") {
         $.moogle.contextmenu.updateTitle($entryLi, entry);
         }

      // LuxSci: The "else" below breaks things...
      else if (entry.title && entry.uiIcon && ! entry.cmd) {
         $.moogle.contextmenu.updateTitle($entryLi, entry.title);
         $.moogle.contextmenu.updateIcon($entryLi, entry.uiIcon);
         }

      else {
         $entryLi.empty();
         entry.cmd = entry.cmd || cmd;
         $.moogle.contextmenu.createEntryMarkup(entry, $entryLi);
         if ($.isArray(entry.children)) {
            $ul = $("<ul/>").appendTo($entryLi);
            $.moogle.contextmenu.createMenuMarkup(entry.children, $ul);
         }
         this.getMenu().menu("refresh");
      }	 
   },

   /** Updates the menu item's icon */
   /* LuxSci Addition */
   updateIcon: function(item, icon) {
      // jQ 1.12 only
      $("span", item).attr("class","ui-icon " + icon);
      }

This works and restores full normal behavior. I would guess that something is broken in

      else {
         $entryLi.empty();
         entry.cmd = entry.cmd || cmd;
         $.moogle.contextmenu.createEntryMarkup(entry, $entryLi);
        // ...
        }

combined with the createEntryMarkup function that is leaving all oft he internal attributes off of the <div /> when it is re-created. I didn't dig further into it than this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions