home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / editor / EditorContextMenu.js < prev    next >
Text File  |  2003-06-08  |  5KB  |  174 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code,
  14.  * released March 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation.  Portions created by Netscape are
  18.  * Copyright (C) 2000 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *    Charles Manske (cmanske@netscape.com)
  23.  */
  24.  
  25. function EditorFillContextMenu(event, contextMenuNode)
  26. {
  27.   if ( event.target != contextMenuNode )
  28.     return;
  29.  
  30.   goUpdateCommand("cmd_undo");
  31.   goUpdateCommand("cmd_redo");
  32.   goUpdateCommand("cmd_cut");
  33.   goUpdateCommand("cmd_copy");
  34.   goUpdateCommand("cmd_paste");
  35.   goUpdateCommand("cmd_pasteNoFormatting");
  36.   goUpdateCommand("cmd_delete");
  37.   goUpdateCommand("cmd_link");
  38.  
  39.   // Setup object property menuitem
  40.   var objectName = InitObjectPropertiesMenuitem("objectProperties_cm");
  41.   var isInLink = objectName == "href";
  42.  
  43.   // Special case of an image inside a link
  44.   if (objectName == "img")
  45.   try {
  46.     isInLink = GetCurrentEditor().getElementOrParentByTagName("href", GetObjectForProperties());
  47.   } catch (e) {}
  48.  
  49.   // Disable "Create Link" if in a link
  50.   SetElementEnabledById("createLink_cm", !isInLink);
  51.  
  52.   // Enable "Edit link in new Composer" if in a link
  53.   SetElementEnabledById("editLink_cm", isInLink);
  54.  
  55.   InitRemoveStylesMenuitems("removeStylesMenuitem_cm", "removeLinksMenuitem_cm", "removeNamedAnchorsMenuitem_cm");
  56.  
  57.   var inCell = IsInTableCell();
  58.   // Set appropriate text for join cells command
  59.   InitJoinCellMenuitem("joinTableCells_cm");
  60.  
  61.   // Update enable states for all table commands
  62.   goUpdateTableMenuItems(document.getElementById("composerTableMenuItems"));
  63.  
  64.   // Loop through all children to hide disabled items
  65.   var children = contextMenuNode.childNodes;
  66.   if (children)
  67.   {
  68.     var count = children.length;
  69.     for (var i = 0; i < count; i++)
  70.       HideDisabledItem(children.item(i));
  71.   }
  72.  
  73.   // Remove separators if all items in immediate group above are hidden
  74.   // A bit complicated to account if multiple groups are completely hidden!
  75.   var haveUndo =
  76.     IsMenuItemShowing("menu_undo_cm") ||
  77.     IsMenuItemShowing("menu_redo_cm");
  78.  
  79.   var haveEdit =
  80.     IsMenuItemShowing("menu_cut_cm")   ||
  81.     IsMenuItemShowing("menu_copy_cm")  ||
  82.     IsMenuItemShowing("menu_paste_cm") ||
  83.     IsMenuItemShowing("menu_pasteNoFormatting_cm") ||
  84.     IsMenuItemShowing("menu_delete_cm");
  85.  
  86.   var haveStyle =
  87.     IsMenuItemShowing("removeStylesMenuitem_cm") ||
  88.     IsMenuItemShowing("createLink_cm") ||
  89.     IsMenuItemShowing("removeLinksMenuitem_cm") ||
  90.     IsMenuItemShowing("removeNamedAnchorsMenuitem_cm");
  91.  
  92.   var haveProps =
  93.     IsMenuItemShowing("objectProperties_cm");
  94.  
  95.   ShowMenuItem("undoredo-separator", haveUndo && haveEdit);
  96.  
  97.   ShowMenuItem("edit-separator", haveEdit || haveUndo);
  98.  
  99.   // Note: Item "menu_selectAll_cm" and
  100.   // following separator are ALWAYS enabled,
  101.   // so there will always be 1 separator here
  102.  
  103.   var showStyleSep = haveStyle && (haveProps || inCell);
  104.   ShowMenuItem("styles-separator", showStyleSep);
  105.  
  106.   var showPropSep = (haveProps && inCell);
  107.   ShowMenuItem("property-separator", showPropSep);
  108.  
  109.   // Remove table submenus if not in table
  110.   ShowMenuItem("tableInsertMenu_cm",  inCell);
  111.   ShowMenuItem("tableSelectMenu_cm",  inCell);
  112.   ShowMenuItem("tableDeleteMenu_cm",  inCell);
  113. }
  114.  
  115. function EditorCleanupContextMenu( event, contextMenuNode )
  116. {
  117.   if ( event.target != contextMenuNode )
  118.     return;
  119.  
  120.   var children = contextMenuNode.childNodes;
  121.   if (children)
  122.   {
  123.     var count = children.length;
  124.     for (var i = 0; i < count; i++)
  125.     ShowHiddenItemOnCleanup(children.item(i));
  126.   }
  127. }
  128.  
  129. function HideDisabledItem( item )
  130. {
  131.   if (!item) return false;
  132.  
  133.   var enabled = (item.getAttribute('disabled') !="true");
  134.   item.setAttribute("hidden", enabled ? "" : "true");
  135.   item.setAttribute("contexthidden", enabled ? "" : "true");
  136.   return enabled;
  137. }
  138.  
  139. function ShowHiddenItemOnCleanup( item )
  140. {
  141.   if (!item) return false;
  142.  
  143.   var isHidden = (item.getAttribute("contexthidden") == "true");
  144.   if (isHidden)
  145.   {
  146.     item.removeAttribute("hidden");
  147.     item.removeAttribute("contexthidden");
  148.     return true;
  149.   }
  150.   return false;
  151. }
  152.  
  153. function ShowMenuItem(id, showItem)
  154. {
  155.   var item = document.getElementById(id);
  156.   if (item)
  157.   {
  158.     item.setAttribute("hidden", showItem ? "" : "true");
  159.     item.setAttribute("contexthidden", showItem ? "" : "true");
  160.   }
  161.   else
  162.     dump("ShowMenuItem: item id="+id+" not found\n");
  163. }
  164.  
  165. function IsMenuItemShowing(menuID)
  166. {
  167.   var item = document.getElementById(menuID);
  168.   if(item)
  169.     return(item.getAttribute("contexthidden") != "true");
  170.  
  171.   return false;
  172. }
  173.  
  174.