1 | /*
|
---|
2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
---|
3 | * Copyright (C) 2003-2009 Frederico Caldeira Knabben
|
---|
4 | *
|
---|
5 | * == BEGIN LICENSE ==
|
---|
6 | *
|
---|
7 | * Licensed under the terms of any of the following licenses at your
|
---|
8 | * choice:
|
---|
9 | *
|
---|
10 | * - GNU General Public License Version 2 or later (the "GPL")
|
---|
11 | * http://www.gnu.org/licenses/gpl.html
|
---|
12 | *
|
---|
13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
---|
14 | * http://www.gnu.org/licenses/lgpl.html
|
---|
15 | *
|
---|
16 | * - Mozilla Public License Version 1.1 or later (the "MPL")
|
---|
17 | * http://www.mozilla.org/MPL/MPL-1.1.html
|
---|
18 | *
|
---|
19 | * == END LICENSE ==
|
---|
20 | *
|
---|
21 | * Defines the FCK.ContextMenu object that is responsible for all
|
---|
22 | * Context Menu operations in the editing area.
|
---|
23 | */
|
---|
24 |
|
---|
25 | FCK.ContextMenu = new Object() ;
|
---|
26 | FCK.ContextMenu.Listeners = new Array() ;
|
---|
27 |
|
---|
28 | FCK.ContextMenu.RegisterListener = function( listener )
|
---|
29 | {
|
---|
30 | if ( listener )
|
---|
31 | this.Listeners.push( listener ) ;
|
---|
32 | }
|
---|
33 |
|
---|
34 | function FCK_ContextMenu_Init()
|
---|
35 | {
|
---|
36 | var oInnerContextMenu = FCK.ContextMenu._InnerContextMenu = new FCKContextMenu( FCKBrowserInfo.IsIE ? window : window.parent, FCKLang.Dir ) ;
|
---|
37 | oInnerContextMenu.CtrlDisable = FCKConfig.BrowserContextMenuOnCtrl ;
|
---|
38 | oInnerContextMenu.OnBeforeOpen = FCK_ContextMenu_OnBeforeOpen ;
|
---|
39 | oInnerContextMenu.OnItemClick = FCK_ContextMenu_OnItemClick ;
|
---|
40 |
|
---|
41 | // Get the registering function.
|
---|
42 | var oMenu = FCK.ContextMenu ;
|
---|
43 |
|
---|
44 | // Register all configured context menu listeners.
|
---|
45 | for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ )
|
---|
46 | oMenu.RegisterListener( FCK_ContextMenu_GetListener( FCKConfig.ContextMenu[i] ) ) ;
|
---|
47 | }
|
---|
48 |
|
---|
49 | function FCK_ContextMenu_GetListener( listenerName )
|
---|
50 | {
|
---|
51 | switch ( listenerName )
|
---|
52 | {
|
---|
53 | case 'Generic' :
|
---|
54 | return {
|
---|
55 | AddItems : function( menu, tag, tagName )
|
---|
56 | {
|
---|
57 | menu.AddItem( 'Cut' , FCKLang.Cut , 7, FCKCommands.GetCommand( 'Cut' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
58 | menu.AddItem( 'Copy' , FCKLang.Copy , 8, FCKCommands.GetCommand( 'Copy' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
59 | menu.AddItem( 'Paste' , FCKLang.Paste , 9, FCKCommands.GetCommand( 'Paste' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
60 | }} ;
|
---|
61 |
|
---|
62 | case 'Table' :
|
---|
63 | return {
|
---|
64 | AddItems : function( menu, tag, tagName )
|
---|
65 | {
|
---|
66 | var bIsTable = ( tagName == 'TABLE' ) ;
|
---|
67 | var bIsCell = ( !bIsTable && FCKSelection.HasAncestorNode( 'TABLE' ) ) ;
|
---|
68 |
|
---|
69 | if ( bIsCell )
|
---|
70 | {
|
---|
71 | menu.AddSeparator() ;
|
---|
72 | var oItem = menu.AddItem( 'Cell' , FCKLang.CellCM ) ;
|
---|
73 | oItem.AddItem( 'TableInsertCellBefore' , FCKLang.InsertCellBefore, 69 ) ;
|
---|
74 | oItem.AddItem( 'TableInsertCellAfter' , FCKLang.InsertCellAfter, 58 ) ;
|
---|
75 | oItem.AddItem( 'TableDeleteCells' , FCKLang.DeleteCells, 59 ) ;
|
---|
76 | if ( FCKBrowserInfo.IsGecko )
|
---|
77 | oItem.AddItem( 'TableMergeCells' , FCKLang.MergeCells, 60,
|
---|
78 | FCKCommands.GetCommand( 'TableMergeCells' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
79 | else
|
---|
80 | {
|
---|
81 | oItem.AddItem( 'TableMergeRight' , FCKLang.MergeRight, 60,
|
---|
82 | FCKCommands.GetCommand( 'TableMergeRight' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
83 | oItem.AddItem( 'TableMergeDown' , FCKLang.MergeDown, 60,
|
---|
84 | FCKCommands.GetCommand( 'TableMergeDown' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
85 | }
|
---|
86 | oItem.AddItem( 'TableHorizontalSplitCell' , FCKLang.HorizontalSplitCell, 61,
|
---|
87 | FCKCommands.GetCommand( 'TableHorizontalSplitCell' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
88 | oItem.AddItem( 'TableVerticalSplitCell' , FCKLang.VerticalSplitCell, 61,
|
---|
89 | FCKCommands.GetCommand( 'TableVerticalSplitCell' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
90 | oItem.AddSeparator() ;
|
---|
91 | oItem.AddItem( 'TableCellProp' , FCKLang.CellProperties, 57,
|
---|
92 | FCKCommands.GetCommand( 'TableCellProp' ).GetState() == FCK_TRISTATE_DISABLED ) ;
|
---|
93 |
|
---|
94 | menu.AddSeparator() ;
|
---|
95 | oItem = menu.AddItem( 'Row' , FCKLang.RowCM ) ;
|
---|
96 | oItem.AddItem( 'TableInsertRowBefore' , FCKLang.InsertRowBefore, 70 ) ;
|
---|
97 | oItem.AddItem( 'TableInsertRowAfter' , FCKLang.InsertRowAfter, 62 ) ;
|
---|
98 | oItem.AddItem( 'TableDeleteRows' , FCKLang.DeleteRows, 63 ) ;
|
---|
99 |
|
---|
100 | menu.AddSeparator() ;
|
---|
101 | oItem = menu.AddItem( 'Column' , FCKLang.ColumnCM ) ;
|
---|
102 | oItem.AddItem( 'TableInsertColumnBefore', FCKLang.InsertColumnBefore, 71 ) ;
|
---|
103 | oItem.AddItem( 'TableInsertColumnAfter' , FCKLang.InsertColumnAfter, 64 ) ;
|
---|
104 | oItem.AddItem( 'TableDeleteColumns' , FCKLang.DeleteColumns, 65 ) ;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if ( bIsTable || bIsCell )
|
---|
108 | {
|
---|
109 | menu.AddSeparator() ;
|
---|
110 | menu.AddItem( 'TableDelete' , FCKLang.TableDelete ) ;
|
---|
111 | menu.AddItem( 'TableProp' , FCKLang.TableProperties, 39 ) ;
|
---|
112 | }
|
---|
113 | }} ;
|
---|
114 |
|
---|
115 | case 'Link' :
|
---|
116 | return {
|
---|
117 | AddItems : function( menu, tag, tagName )
|
---|
118 | {
|
---|
119 | var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
|
---|
120 |
|
---|
121 | if ( bInsideLink || FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED )
|
---|
122 | {
|
---|
123 | // Go up to the anchor to test its properties
|
---|
124 | var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
|
---|
125 | var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
|
---|
126 | // If it isn't a link then don't add the Link context menu
|
---|
127 | if ( bIsAnchor )
|
---|
128 | return ;
|
---|
129 |
|
---|
130 | menu.AddSeparator() ;
|
---|
131 | menu.AddItem( 'VisitLink', FCKLang.VisitLink ) ;
|
---|
132 | menu.AddSeparator() ;
|
---|
133 | if ( bInsideLink )
|
---|
134 | menu.AddItem( 'Link', FCKLang.EditLink , 34 ) ;
|
---|
135 | menu.AddItem( 'Unlink' , FCKLang.RemoveLink , 35 ) ;
|
---|
136 | }
|
---|
137 | }} ;
|
---|
138 |
|
---|
139 | case 'Image' :
|
---|
140 | return {
|
---|
141 | AddItems : function( menu, tag, tagName )
|
---|
142 | {
|
---|
143 | if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) )
|
---|
144 | {
|
---|
145 | menu.AddSeparator() ;
|
---|
146 | menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ;
|
---|
147 | }
|
---|
148 | }} ;
|
---|
149 |
|
---|
150 | case 'Anchor' :
|
---|
151 | return {
|
---|
152 | AddItems : function( menu, tag, tagName )
|
---|
153 | {
|
---|
154 | // Go up to the anchor to test its properties
|
---|
155 | var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
|
---|
156 | var bIsAnchor = ( oLink && oLink.name.length > 0 ) ;
|
---|
157 |
|
---|
158 | if ( bIsAnchor || ( tagName == 'IMG' && tag.getAttribute( '_fckanchor' ) ) )
|
---|
159 | {
|
---|
160 | menu.AddSeparator() ;
|
---|
161 | menu.AddItem( 'Anchor', FCKLang.AnchorProp, 36 ) ;
|
---|
162 | menu.AddItem( 'AnchorDelete', FCKLang.AnchorDelete ) ;
|
---|
163 | }
|
---|
164 | }} ;
|
---|
165 |
|
---|
166 | case 'Flash' :
|
---|
167 | return {
|
---|
168 | AddItems : function( menu, tag, tagName )
|
---|
169 | {
|
---|
170 | if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) )
|
---|
171 | {
|
---|
172 | menu.AddSeparator() ;
|
---|
173 | menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ;
|
---|
174 | }
|
---|
175 | }} ;
|
---|
176 |
|
---|
177 | case 'Form' :
|
---|
178 | return {
|
---|
179 | AddItems : function( menu, tag, tagName )
|
---|
180 | {
|
---|
181 | if ( FCKSelection.HasAncestorNode('FORM') )
|
---|
182 | {
|
---|
183 | menu.AddSeparator() ;
|
---|
184 | menu.AddItem( 'Form', FCKLang.FormProp, 48 ) ;
|
---|
185 | }
|
---|
186 | }} ;
|
---|
187 |
|
---|
188 | case 'Checkbox' :
|
---|
189 | return {
|
---|
190 | AddItems : function( menu, tag, tagName )
|
---|
191 | {
|
---|
192 | if ( tagName == 'INPUT' && tag.type == 'checkbox' )
|
---|
193 | {
|
---|
194 | menu.AddSeparator() ;
|
---|
195 | menu.AddItem( 'Checkbox', FCKLang.CheckboxProp, 49 ) ;
|
---|
196 | }
|
---|
197 | }} ;
|
---|
198 |
|
---|
199 | case 'Radio' :
|
---|
200 | return {
|
---|
201 | AddItems : function( menu, tag, tagName )
|
---|
202 | {
|
---|
203 | if ( tagName == 'INPUT' && tag.type == 'radio' )
|
---|
204 | {
|
---|
205 | menu.AddSeparator() ;
|
---|
206 | menu.AddItem( 'Radio', FCKLang.RadioButtonProp, 50 ) ;
|
---|
207 | }
|
---|
208 | }} ;
|
---|
209 |
|
---|
210 | case 'TextField' :
|
---|
211 | return {
|
---|
212 | AddItems : function( menu, tag, tagName )
|
---|
213 | {
|
---|
214 | if ( tagName == 'INPUT' && ( tag.type == 'text' || tag.type == 'password' ) )
|
---|
215 | {
|
---|
216 | menu.AddSeparator() ;
|
---|
217 | menu.AddItem( 'TextField', FCKLang.TextFieldProp, 51 ) ;
|
---|
218 | }
|
---|
219 | }} ;
|
---|
220 |
|
---|
221 | case 'HiddenField' :
|
---|
222 | return {
|
---|
223 | AddItems : function( menu, tag, tagName )
|
---|
224 | {
|
---|
225 | if ( tagName == 'IMG' && tag.getAttribute( '_fckinputhidden' ) )
|
---|
226 | {
|
---|
227 | menu.AddSeparator() ;
|
---|
228 | menu.AddItem( 'HiddenField', FCKLang.HiddenFieldProp, 56 ) ;
|
---|
229 | }
|
---|
230 | }} ;
|
---|
231 |
|
---|
232 | case 'ImageButton' :
|
---|
233 | return {
|
---|
234 | AddItems : function( menu, tag, tagName )
|
---|
235 | {
|
---|
236 | if ( tagName == 'INPUT' && tag.type == 'image' )
|
---|
237 | {
|
---|
238 | menu.AddSeparator() ;
|
---|
239 | menu.AddItem( 'ImageButton', FCKLang.ImageButtonProp, 55 ) ;
|
---|
240 | }
|
---|
241 | }} ;
|
---|
242 |
|
---|
243 | case 'Button' :
|
---|
244 | return {
|
---|
245 | AddItems : function( menu, tag, tagName )
|
---|
246 | {
|
---|
247 | if ( tagName == 'INPUT' && ( tag.type == 'button' || tag.type == 'submit' || tag.type == 'reset' ) )
|
---|
248 | {
|
---|
249 | menu.AddSeparator() ;
|
---|
250 | menu.AddItem( 'Button', FCKLang.ButtonProp, 54 ) ;
|
---|
251 | }
|
---|
252 | }} ;
|
---|
253 |
|
---|
254 | case 'Select' :
|
---|
255 | return {
|
---|
256 | AddItems : function( menu, tag, tagName )
|
---|
257 | {
|
---|
258 | if ( tagName == 'SELECT' )
|
---|
259 | {
|
---|
260 | menu.AddSeparator() ;
|
---|
261 | menu.AddItem( 'Select', FCKLang.SelectionFieldProp, 53 ) ;
|
---|
262 | }
|
---|
263 | }} ;
|
---|
264 |
|
---|
265 | case 'Textarea' :
|
---|
266 | return {
|
---|
267 | AddItems : function( menu, tag, tagName )
|
---|
268 | {
|
---|
269 | if ( tagName == 'TEXTAREA' )
|
---|
270 | {
|
---|
271 | menu.AddSeparator() ;
|
---|
272 | menu.AddItem( 'Textarea', FCKLang.TextareaProp, 52 ) ;
|
---|
273 | }
|
---|
274 | }} ;
|
---|
275 |
|
---|
276 | case 'BulletedList' :
|
---|
277 | return {
|
---|
278 | AddItems : function( menu, tag, tagName )
|
---|
279 | {
|
---|
280 | if ( FCKSelection.HasAncestorNode('UL') )
|
---|
281 | {
|
---|
282 | menu.AddSeparator() ;
|
---|
283 | menu.AddItem( 'BulletedList', FCKLang.BulletedListProp, 27 ) ;
|
---|
284 | }
|
---|
285 | }} ;
|
---|
286 |
|
---|
287 | case 'NumberedList' :
|
---|
288 | return {
|
---|
289 | AddItems : function( menu, tag, tagName )
|
---|
290 | {
|
---|
291 | if ( FCKSelection.HasAncestorNode('OL') )
|
---|
292 | {
|
---|
293 | menu.AddSeparator() ;
|
---|
294 | menu.AddItem( 'NumberedList', FCKLang.NumberedListProp, 26 ) ;
|
---|
295 | }
|
---|
296 | }} ;
|
---|
297 |
|
---|
298 | case 'DivContainer':
|
---|
299 | return {
|
---|
300 | AddItems : function( menu, tag, tagName )
|
---|
301 | {
|
---|
302 | var currentBlocks = FCKDomTools.GetSelectedDivContainers() ;
|
---|
303 |
|
---|
304 | if ( currentBlocks.length > 0 )
|
---|
305 | {
|
---|
306 | menu.AddSeparator() ;
|
---|
307 | menu.AddItem( 'EditDiv', FCKLang.EditDiv, 75 ) ;
|
---|
308 | menu.AddItem( 'DeleteDiv', FCKLang.DeleteDiv, 76 ) ;
|
---|
309 | }
|
---|
310 | }} ;
|
---|
311 |
|
---|
312 | }
|
---|
313 | return null ;
|
---|
314 | }
|
---|
315 |
|
---|
316 | function FCK_ContextMenu_OnBeforeOpen()
|
---|
317 | {
|
---|
318 | // Update the UI.
|
---|
319 | FCK.Events.FireEvent( 'OnSelectionChange' ) ;
|
---|
320 |
|
---|
321 | // Get the actual selected tag (if any).
|
---|
322 | var oTag, sTagName ;
|
---|
323 |
|
---|
324 | // The extra () is to avoid a warning with strict error checking. This is ok.
|
---|
325 | if ( (oTag = FCKSelection.GetSelectedElement()) )
|
---|
326 | sTagName = oTag.tagName ;
|
---|
327 |
|
---|
328 | // Cleanup the current menu items.
|
---|
329 | var oMenu = FCK.ContextMenu._InnerContextMenu ;
|
---|
330 | oMenu.RemoveAllItems() ;
|
---|
331 |
|
---|
332 | // Loop through the listeners.
|
---|
333 | var aListeners = FCK.ContextMenu.Listeners ;
|
---|
334 | for ( var i = 0 ; i < aListeners.length ; i++ )
|
---|
335 | aListeners[i].AddItems( oMenu, oTag, sTagName ) ;
|
---|
336 | }
|
---|
337 |
|
---|
338 | function FCK_ContextMenu_OnItemClick( item )
|
---|
339 | {
|
---|
340 | // IE might work incorrectly if we refocus the editor #798
|
---|
341 | if ( !FCKBrowserInfo.IsIE )
|
---|
342 | FCK.Focus() ;
|
---|
343 |
|
---|
344 | FCKCommands.GetCommand( item.Name ).Execute( item.CustomData ) ;
|
---|
345 | }
|
---|