source: branches/1.2/workflow/js/fckeditor/editor/_source/internals/fck_contextmenu.js @ 1349

Revision 1349, 8.3 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1/*
2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2007 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
25FCK.ContextMenu = new Object() ;
26FCK.ContextMenu.Listeners = new Array() ;
27
28FCK.ContextMenu.RegisterListener = function( listener )
29{
30        if ( listener )
31                this.Listeners.push( listener ) ;
32}
33
34function FCK_ContextMenu_Init()
35{
36        var oInnerContextMenu = FCK.ContextMenu._InnerContextMenu = new FCKContextMenu( FCKBrowserInfo.IsIE ? window : window.parent, FCKLang.Dir ) ;
37        oInnerContextMenu.OnBeforeOpen  = FCK_ContextMenu_OnBeforeOpen ;
38        oInnerContextMenu.OnItemClick   = FCK_ContextMenu_OnItemClick ;
39
40        // Get the registering function.
41        var oMenu = FCK.ContextMenu ;
42
43        // Register all configured context menu listeners.
44        for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ )
45                oMenu.RegisterListener( FCK_ContextMenu_GetListener( FCKConfig.ContextMenu[i] ) ) ;
46}
47
48function FCK_ContextMenu_GetListener( listenerName )
49{
50        switch ( listenerName )
51        {
52                case 'Generic' :
53                        return {
54                        AddItems : function( menu, tag, tagName )
55                        {
56                                menu.AddItem( 'Cut'             , FCKLang.Cut   , 7, FCKCommands.GetCommand( 'Cut' ).GetState() == FCK_TRISTATE_DISABLED ) ;
57                                menu.AddItem( 'Copy'    , FCKLang.Copy  , 8, FCKCommands.GetCommand( 'Copy' ).GetState() == FCK_TRISTATE_DISABLED ) ;
58                                menu.AddItem( 'Paste'   , FCKLang.Paste , 9, FCKCommands.GetCommand( 'Paste' ).GetState() == FCK_TRISTATE_DISABLED ) ;
59                        }} ;
60
61                case 'Table' :
62                        return {
63                        AddItems : function( menu, tag, tagName )
64                        {
65                                var bIsTable    = ( tagName == 'TABLE' ) ;
66                                var bIsCell             = ( !bIsTable && FCKSelection.HasAncestorNode( 'TABLE' ) ) ;
67
68                                if ( bIsCell )
69                                {
70                                        menu.AddSeparator() ;
71                                        var oItem = menu.AddItem( 'Cell'        , FCKLang.CellCM ) ;
72                                        oItem.AddItem( 'TableInsertCell'        , FCKLang.InsertCell, 58 ) ;
73                                        oItem.AddItem( 'TableDeleteCells'       , FCKLang.DeleteCells, 59 ) ;
74                                        oItem.AddItem( 'TableMergeCells'        , FCKLang.MergeCells, 60 ) ;
75                                        oItem.AddItem( 'TableSplitCell'         , FCKLang.SplitCell, 61 ) ;
76                                        oItem.AddSeparator() ;
77                                        oItem.AddItem( 'TableCellProp'          , FCKLang.CellProperties, 57 ) ;
78
79                                        menu.AddSeparator() ;
80                                        oItem = menu.AddItem( 'Row'                     , FCKLang.RowCM ) ;
81                                        oItem.AddItem( 'TableInsertRow'         , FCKLang.InsertRow, 62 ) ;
82                                        oItem.AddItem( 'TableDeleteRows'        , FCKLang.DeleteRows, 63 ) ;
83
84                                        menu.AddSeparator() ;
85                                        oItem = menu.AddItem( 'Column'          , FCKLang.ColumnCM ) ;
86                                        oItem.AddItem( 'TableInsertColumn'      , FCKLang.InsertColumn, 64 ) ;
87                                        oItem.AddItem( 'TableDeleteColumns'     , FCKLang.DeleteColumns, 65 ) ;
88                                }
89
90                                if ( bIsTable || bIsCell )
91                                {
92                                        menu.AddSeparator() ;
93                                        menu.AddItem( 'TableDelete'                     , FCKLang.TableDelete ) ;
94                                        menu.AddItem( 'TableProp'                       , FCKLang.TableProperties, 39 ) ;
95                                }
96                        }} ;
97
98                case 'Link' :
99                        return {
100                        AddItems : function( menu, tag, tagName )
101                        {
102                                var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
103
104                                if ( bInsideLink || FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED )
105                                {
106                                        // Go up to the anchor to test its properties
107                                        var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
108                                        var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
109                                        // If it isn't a link then don't add the Link context menu
110                                        if ( bIsAnchor )
111                                                return ;
112
113                                        menu.AddSeparator() ;
114                                        if ( bInsideLink )
115                                                menu.AddItem( 'Link', FCKLang.EditLink          , 34 ) ;
116                                        menu.AddItem( 'Unlink'  , FCKLang.RemoveLink    , 35 ) ;
117                                }
118                        }} ;
119
120                case 'Image' :
121                        return {
122                        AddItems : function( menu, tag, tagName )
123                        {
124                                if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) )
125                                {
126                                        menu.AddSeparator() ;
127                                        menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ;
128                                }
129                        }} ;
130
131                case 'Anchor' :
132                        return {
133                        AddItems : function( menu, tag, tagName )
134                        {
135                                // Go up to the anchor to test its properties
136                                var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
137                                var bIsAnchor = ( oLink && oLink.name.length > 0 ) ;
138
139                                if ( bIsAnchor || ( tagName == 'IMG' && tag.getAttribute( '_fckanchor' ) ) )
140                                {
141                                        menu.AddSeparator() ;
142                                        menu.AddItem( 'Anchor', FCKLang.AnchorProp, 36 ) ;
143                                }
144                        }} ;
145
146                case 'Flash' :
147                        return {
148                        AddItems : function( menu, tag, tagName )
149                        {
150                                if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) )
151                                {
152                                        menu.AddSeparator() ;
153                                        menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ;
154                                }
155                        }} ;
156
157                case 'Form' :
158                        return {
159                        AddItems : function( menu, tag, tagName )
160                        {
161                                if ( FCKSelection.HasAncestorNode('FORM') )
162                                {
163                                        menu.AddSeparator() ;
164                                        menu.AddItem( 'Form', FCKLang.FormProp, 48 ) ;
165                                }
166                        }} ;
167
168                case 'Checkbox' :
169                        return {
170                        AddItems : function( menu, tag, tagName )
171                        {
172                                if ( tagName == 'INPUT' && tag.type == 'checkbox' )
173                                {
174                                        menu.AddSeparator() ;
175                                        menu.AddItem( 'Checkbox', FCKLang.CheckboxProp, 49 ) ;
176                                }
177                        }} ;
178
179                case 'Radio' :
180                        return {
181                        AddItems : function( menu, tag, tagName )
182                        {
183                                if ( tagName == 'INPUT' && tag.type == 'radio' )
184                                {
185                                        menu.AddSeparator() ;
186                                        menu.AddItem( 'Radio', FCKLang.RadioButtonProp, 50 ) ;
187                                }
188                        }} ;
189
190                case 'TextField' :
191                        return {
192                        AddItems : function( menu, tag, tagName )
193                        {
194                                if ( tagName == 'INPUT' && ( tag.type == 'text' || tag.type == 'password' ) )
195                                {
196                                        menu.AddSeparator() ;
197                                        menu.AddItem( 'TextField', FCKLang.TextFieldProp, 51 ) ;
198                                }
199                        }} ;
200
201                case 'HiddenField' :
202                        return {
203                        AddItems : function( menu, tag, tagName )
204                        {
205                                if ( tagName == 'IMG' && tag.getAttribute( '_fckinputhidden' ) )
206                                {
207                                        menu.AddSeparator() ;
208                                        menu.AddItem( 'HiddenField', FCKLang.HiddenFieldProp, 56 ) ;
209                                }
210                        }} ;
211
212                case 'ImageButton' :
213                        return {
214                        AddItems : function( menu, tag, tagName )
215                        {
216                                if ( tagName == 'INPUT' && tag.type == 'image' )
217                                {
218                                        menu.AddSeparator() ;
219                                        menu.AddItem( 'ImageButton', FCKLang.ImageButtonProp, 55 ) ;
220                                }
221                        }} ;
222
223                case 'Button' :
224                        return {
225                        AddItems : function( menu, tag, tagName )
226                        {
227                                if ( tagName == 'INPUT' && ( tag.type == 'button' || tag.type == 'submit' || tag.type == 'reset' ) )
228                                {
229                                        menu.AddSeparator() ;
230                                        menu.AddItem( 'Button', FCKLang.ButtonProp, 54 ) ;
231                                }
232                        }} ;
233
234                case 'Select' :
235                        return {
236                        AddItems : function( menu, tag, tagName )
237                        {
238                                if ( tagName == 'SELECT' )
239                                {
240                                        menu.AddSeparator() ;
241                                        menu.AddItem( 'Select', FCKLang.SelectionFieldProp, 53 ) ;
242                                }
243                        }} ;
244
245                case 'Textarea' :
246                        return {
247                        AddItems : function( menu, tag, tagName )
248                        {
249                                if ( tagName == 'TEXTAREA' )
250                                {
251                                        menu.AddSeparator() ;
252                                        menu.AddItem( 'Textarea', FCKLang.TextareaProp, 52 ) ;
253                                }
254                        }} ;
255
256                case 'BulletedList' :
257                        return {
258                        AddItems : function( menu, tag, tagName )
259                        {
260                                if ( FCKSelection.HasAncestorNode('UL') )
261                                {
262                                        menu.AddSeparator() ;
263                                        menu.AddItem( 'BulletedList', FCKLang.BulletedListProp, 27 ) ;
264                                }
265                        }} ;
266
267                case 'NumberedList' :
268                        return {
269                        AddItems : function( menu, tag, tagName )
270                        {
271                                if ( FCKSelection.HasAncestorNode('OL') )
272                                {
273                                        menu.AddSeparator() ;
274                                        menu.AddItem( 'NumberedList', FCKLang.NumberedListProp, 26 ) ;
275                                }
276                        }} ;
277        }
278        return null ;
279}
280
281function FCK_ContextMenu_OnBeforeOpen()
282{
283        // Update the UI.
284        FCK.Events.FireEvent( 'OnSelectionChange' ) ;
285
286        // Get the actual selected tag (if any).
287        var oTag, sTagName ;
288
289        // The extra () is to avoid a warning with strict error checking. This is ok.
290        if ( (oTag = FCKSelection.GetSelectedElement()) )
291                sTagName = oTag.tagName ;
292
293        // Cleanup the current menu items.
294        var oMenu = FCK.ContextMenu._InnerContextMenu ;
295        oMenu.RemoveAllItems() ;
296
297        // Loop through the listeners.
298        var aListeners = FCK.ContextMenu.Listeners ;
299        for ( var i = 0 ; i < aListeners.length ; i++ )
300                aListeners[i].AddItems( oMenu, oTag, sTagName ) ;
301}
302
303function FCK_ContextMenu_OnItemClick( item )
304{
305        FCK.Focus() ;
306        FCKCommands.GetCommand( item.Name ).Execute() ;
307}
Note: See TracBrowser for help on using the repository browser.