!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2000
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Charles Manske (cmanske@netscape.com)
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
40 function EditorFillContextMenu(event, contextMenuNode)
41 {
42 if ( event.target != contextMenuNode )
43 return;
44
45 // Setup object property menuitem
46 var objectName = InitObjectPropertiesMenuitem("objectProperties_cm");
47 var isInLink = objectName == "href";
48
49 // Special case of an image inside a link
50 if (objectName == "img")
51 try {
52 isInLink = GetCurrentEditor().getElementOrParentByTagName("href", GetObjectForProperties());
53 } catch (e) {}
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[i]);
71 }
72
73 // The above loop will always show all separators and the next two items
74 // Hide "Create Link" if in a link
75 ShowMenuItem("createLink_cm", !isInLink);
76
77 // Hide "Edit link in new Composer" unless in a link
78 ShowMenuItem("editLink_cm", isInLink);
79
80 // Remove separators if all items in immediate group above are hidden
81 // A bit complicated to account if multiple groups are completely hidden!
82 var haveUndo =
83 IsMenuItemShowing("menu_undo_cm") ||
84 IsMenuItemShowing("menu_redo_cm");
85
86 var haveEdit =
87 IsMenuItemShowing("menu_cut_cm") ||
88 IsMenuItemShowing("menu_copy_cm") ||
89 IsMenuItemShowing("menu_paste_cm") ||
90 IsMenuItemShowing("menu_pasteNoFormatting_cm") ||
91 IsMenuItemShowing("menu_delete_cm");
92
93 var haveStyle =
94 IsMenuItemShowing("removeStylesMenuitem_cm") ||
95 IsMenuItemShowing("createLink_cm") ||
96 IsMenuItemShowing("removeLinksMenuitem_cm") ||
97 IsMenuItemShowing("removeNamedAnchorsMenuitem_cm");
98
99 var haveProps =
100 IsMenuItemShowing("objectProperties_cm");
101
102 ShowMenuItem("undoredo-separator", haveUndo && haveEdit);
103
104 ShowMenuItem("edit-separator", haveEdit || haveUndo);
105
106 // Note: Item "menu_selectAll_cm" and
107 // following separator are ALWAYS enabled,
108 // so there will always be 1 separator here
109
110 var showStyleSep = haveStyle && (haveProps || inCell);
111 ShowMenuItem("styles-separator", showStyleSep);
112
113 var showPropSep = (haveProps && inCell);
114 ShowMenuItem("property-separator", showPropSep);
115
116 // Remove table submenus if not in table
117 ShowMenuItem("tableInsertMenu_cm", inCell);
118 ShowMenuItem("tableSelectMenu_cm", inCell);
119 ShowMenuItem("tableDeleteMenu_cm", inCell);
120
121 // if we have a mispelled word, show spellchecker context
122 // menuitems as well as the usual context menu
123 InlineSpellCheckerUI.clearSuggestionsFromMenu();
124 InlineSpellCheckerUI.initFromEvent(document.popupRangeParent, document.popupRangeOffset);
125 var onMisspelling = InlineSpellCheckerUI.overMisspelling;
126 document.getElementById('spellCheckSuggestionsSeparator').hidden = !onMisspelling;
127 document.getElementById('spellCheckAddToDictionary').hidden = !onMisspelling;
128 document.getElementById('spellCheckIgnoreWord').hidden = !onMisspelling;
129 var separator = document.getElementById('spellCheckAddSep');
130 separator.hidden = !onMisspelling;
131 document.getElementById('spellCheckNoSuggestions').hidden = !onMisspelling ||
132 InlineSpellCheckerUI.addSuggestionsToMenu(contextMenuNode, separator, 5);
133 }
134
IsItemOrCommandEnabled
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
135 function IsItemOrCommandEnabled( item )
136 {
137 var command = item.getAttribute("command");
138 if (command) {
139 // If possible, query the command controller directly
140 var controller = document.commandDispatcher.getControllerForCommand(command);
141 if (controller)
142 return controller.isCommandEnabled(command);
143 }
144
145 // Fall back on the inefficient observed disabled attribute
146 return item.getAttribute("disabled") != "true";
147 }
148
HideDisabledItem
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
149 function HideDisabledItem( item )
150 {
151 item.hidden = !IsItemOrCommandEnabled(item);
152 }
153
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
154 function ShowMenuItem(id, showItem)
155 {
156 var item = document.getElementById(id);
157 if (item && !showItem)
158 {
159 item.hidden = true;
160 }
161 // else HideDisabledItem showed the item anyway
162 }
163
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
164 function IsMenuItemShowing(menuID)
165 {
166 var item = document.getElementById(menuID);
167 if (item)
168 return !item.hidden;
169
170 return false;
171 }