diff --git a/mailnews/base/resources/content/mailContextMenus.js b/mailnews/base/resources/content/mailContextMenus.js index 84bc6a61b620..3961b6071a25 100644 --- a/mailnews/base/resources/content/mailContextMenus.js +++ b/mailnews/base/resources/content/mailContextMenus.js @@ -443,8 +443,19 @@ function ShowSeparator(aSeparatorID) { var separator = document.getElementById(aSeparatorID); var sibling = separator.previousSibling; + var siblingID; + var siblingNextHiddenAttrib = separator.nextSibling.getAttribute("hidden"); + while (sibling && sibling.localName != "menuseparator") { - if (sibling.getAttribute("hidden") != "true") + siblingID = sibling.getAttribute("id"); + // for some reason, context-blockimage and context-unblockimage is not + // hidden on the very first time the context menu is invoked. It's only + // hidden on subsequent triggers of the context menu. Since we're not + // using these two menuitems in mailnews, we can ignore it if encountered. + if ((sibling.getAttribute("hidden") != "true") && + (siblingNextHiddenAttrib != "true") && + (siblingID != "context-blockimage") && + (siblingID != "context-unblockimage")) return true; sibling = sibling.previousSibling; } diff --git a/xpfe/communicator/resources/content/nsContextMenu.js b/xpfe/communicator/resources/content/nsContextMenu.js index 1c42f65464ca..7bde392502d3 100644 --- a/xpfe/communicator/resources/content/nsContextMenu.js +++ b/xpfe/communicator/resources/content/nsContextMenu.js @@ -129,17 +129,9 @@ nsContextMenu.prototype = { this.showItem( "context-sep-image", this.onImage ); - if( isWin && this.onImage ) { - var wallpaperItem = document.getElementById("context-setWallpaper"); + if( isWin && this.onImage ) // Disable the Set As Wallpaper menu item if we're still trying to load the image - if (wallpaperItem) { - if( !("complete" in this.target) || this.target.complete ) { - wallpaperItem.removeAttribute("disabled"); - } else { - wallpaperItem.setAttribute("disabled", "true"); - } - } - } + this.setItemAttr( "context-setWallpaper", "disabled", (("complete" in this.target) && !this.target.complete) ? "true" : null ); // View Image depends on whether an image was clicked on. this.showItem( "context-viewimage", this.onImage ); @@ -147,14 +139,7 @@ nsContextMenu.prototype = { // View background image depends on whether there is one. this.showItem( "context-viewbgimage", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) ); this.showItem( "context-sep-viewbgimage", !( this.inDirList || this.onImage || this.isTextSelected || this.onLink || this.onTextInput ) ); - var menuitem = document.getElementById("context-viewbgimage"); - - if ( menuitem ) { - if ( this.hasBGImage ) - menuitem.removeAttribute("disabled"); - else - menuitem.setAttribute("disabled", "true"); - } + this.setItemAttr( "context-viewbgimage", "disabled", this.hasBGImage ? null : "true"); }, initMiscItems : function () { // Use "Bookmark This Link" if on a link. @@ -690,7 +675,6 @@ nsContextMenu.prototype = { isTextSelection : function() { var result = false; var selection = this.searchSelected(); - var searchSelect = document.getElementById('context-searchselect'); var bundle = srGetStrBundle("chrome://communicator/locale/contentAreaCommands.properties"); @@ -704,7 +688,7 @@ nsContextMenu.prototype = { // format "Search for " string to show in menu searchSelectText = bundle.formatStringFromName("searchText", [searchSelectText], 1); - searchSelect.setAttribute("label", searchSelectText); + this.setItemAttr("context-searchselect", "label", searchSelectText); } return result; },