source: companies/celepar/news_admin/templates/celepar/fckeditor/editor/_source/internals/fck_contextmenu.js @ 763

Revision 763, 7.7 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1/*
2 * FCKeditor - The text editor for internet
3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
4 *
5 * Licensed under the terms of the GNU Lesser General Public License:
6 *              http://www.opensource.org/licenses/lgpl-license.php
7 *
8 * For further information visit:
9 *              http://www.fckeditor.net/
10 *
11 * "Support Open Source software. What about a donation today?"
12 *
13 * File Name: fck_contextmenu.js
14 *      Defines the FCK.ContextMenu object that is responsible for all
15 *      Context Menu operations in the editing area.
16 *
17 * File Authors:
18 *              Frederico Caldeira Knabben (fredck@fckeditor.net)
19 */
20
21FCK.ContextMenu = new Object() ;
22FCK.ContextMenu.Listeners = new Array() ;
23
24FCK.ContextMenu.RegisterListener = function( listener )
25{
26        if ( listener )
27                this.Listeners.push( listener ) ;
28}
29
30function FCK_ContextMenu_Init()
31{
32        var oInnerContextMenu = FCK.ContextMenu._InnerContextMenu = new FCKContextMenu( FCKBrowserInfo.IsIE ? window : window.parent, FCK.EditorWindow, FCKLang.Dir ) ;
33        oInnerContextMenu.OnBeforeOpen  = FCK_ContextMenu_OnBeforeOpen ;
34        oInnerContextMenu.OnItemClick   = FCK_ContextMenu_OnItemClick ;
35
36        // Get the registering function.
37        var oMenu = FCK.ContextMenu ;
38
39        // Register all configured context menu listeners.
40        for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ )
41                oMenu.RegisterListener( FCK_ContextMenu_GetListener( FCKConfig.ContextMenu[i] ) ) ;
42}
43
44function FCK_ContextMenu_GetListener( listenerName )
45{
46        switch ( listenerName )
47        {
48                case 'Generic' :
49                        return {
50                        AddItems : function( menu, tag, tagName )
51                        {
52                                menu.AddItem( 'Cut'             , FCKLang.Cut   , 7, FCKCommands.GetCommand( 'Cut' ).GetState() == FCK_TRISTATE_DISABLED ) ;
53                                menu.AddItem( 'Copy'    , FCKLang.Copy  , 8, FCKCommands.GetCommand( 'Copy' ).GetState() == FCK_TRISTATE_DISABLED ) ;
54                                menu.AddItem( 'Paste'   , FCKLang.Paste , 9, FCKCommands.GetCommand( 'Paste' ).GetState() == FCK_TRISTATE_DISABLED ) ;
55                        }} ;
56
57                case 'Table' :
58                        return {
59                        AddItems : function( menu, tag, tagName )
60                        {
61                                var bIsTable    = ( tagName == 'TABLE' ) ;
62                                var bIsCell             = ( !bIsTable && FCKSelection.HasAncestorNode( 'TABLE' ) ) ;
63                               
64                                if ( bIsCell )
65                                {
66                                        menu.AddSeparator() ;
67                                        var oItem = menu.AddItem( 'Cell'        , FCKLang.CellCM ) ;
68                                        oItem.AddItem( 'TableInsertCell'        , FCKLang.InsertCell, 58 ) ;
69                                        oItem.AddItem( 'TableDeleteCells'       , FCKLang.DeleteCells, 59 ) ;
70                                        oItem.AddItem( 'TableMergeCells'        , FCKLang.MergeCells, 60 ) ;
71                                        oItem.AddItem( 'TableSplitCell'         , FCKLang.SplitCell, 61 ) ;
72                                        oItem.AddSeparator() ;
73                                        oItem.AddItem( 'TableCellProp'          , FCKLang.CellProperties, 57 ) ;
74
75                                        menu.AddSeparator() ;
76                                        oItem = menu.AddItem( 'Row'                     , FCKLang.RowCM ) ;
77                                        oItem.AddItem( 'TableInsertRow'         , FCKLang.InsertRow, 62 ) ;
78                                        oItem.AddItem( 'TableDeleteRows'        , FCKLang.DeleteRows, 63 ) ;
79                                       
80                                        menu.AddSeparator() ;
81                                        oItem = menu.AddItem( 'Column'          , FCKLang.ColumnCM ) ;
82                                        oItem.AddItem( 'TableInsertColumn'      , FCKLang.InsertColumn, 64 ) ;
83                                        oItem.AddItem( 'TableDeleteColumns'     , FCKLang.DeleteColumns, 65 ) ;
84                                }
85
86                                if ( bIsTable || bIsCell )
87                                {
88                                        menu.AddSeparator() ;
89                                        menu.AddItem( 'TableDelete'                     , FCKLang.TableDelete ) ;
90                                        menu.AddItem( 'TableProp'                       , FCKLang.TableProperties, 39 ) ;
91                                }
92                        }} ;
93
94                case 'Link' :
95                        return {
96                        AddItems : function( menu, tag, tagName )
97                        {
98                                var bInsideLink = ( tagName == 'A' || FCKSelection.HasAncestorNode( 'A' ) ) ;
99
100                                if ( bInsideLink || FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED )
101                                {
102                                        menu.AddSeparator() ;
103                                        if ( bInsideLink )
104                                                menu.AddItem( 'Link', FCKLang.EditLink          , 34 ) ;
105                                        menu.AddItem( 'Unlink'  , FCKLang.RemoveLink    , 35 ) ;
106                                }
107                        }} ;
108
109                case 'Image' :
110                        return {
111                        AddItems : function( menu, tag, tagName )
112                        {
113                                if ( tagName == 'IMG' && !tag.getAttribute( '_fckfakelement' ) )
114                                {
115                                        menu.AddSeparator() ;
116                                        menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ;
117                                }
118                        }} ;
119
120                case 'Anchor' :
121                        return {
122                        AddItems : function( menu, tag, tagName )
123                        {
124                                if ( tagName == 'IMG' && tag.getAttribute( '_fckanchor' ) )
125                                {
126                                        menu.AddSeparator() ;
127                                        menu.AddItem( 'Anchor', FCKLang.AnchorProp, 36 ) ;
128                                }
129                        }} ;
130
131                case 'Flash' :
132                        return {
133                        AddItems : function( menu, tag, tagName )
134                        {
135                                if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) )
136                                {
137                                        menu.AddSeparator() ;
138                                        menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ;
139                                }
140                        }} ;
141
142                case 'Form' :
143                        return {
144                        AddItems : function( menu, tag, tagName )
145                        {
146                                if ( FCKSelection.HasAncestorNode('FORM') )
147                                {
148                                        menu.AddSeparator() ;
149                                        menu.AddItem( 'Form', FCKLang.FormProp, 48 ) ;
150                                }
151                        }} ;
152
153                case 'Checkbox' :
154                        return {
155                        AddItems : function( menu, tag, tagName )
156                        {
157                                if ( tagName == 'INPUT' && tag.type == 'checkbox' )
158                                {
159                                        menu.AddSeparator() ;
160                                        menu.AddItem( 'Checkbox', FCKLang.CheckboxProp, 49 ) ;
161                                }
162                        }} ;
163
164                case 'Radio' :
165                        return {
166                        AddItems : function( menu, tag, tagName )
167                        {
168                                if ( tagName == 'INPUT' && tag.type == 'radio' )
169                                {
170                                        menu.AddSeparator() ;
171                                        menu.AddItem( 'Radio', FCKLang.RadioButtonProp, 50 ) ;
172                                }
173                        }} ;
174
175                case 'TextField' :
176                        return {
177                        AddItems : function( menu, tag, tagName )
178                        {
179                                if ( tagName == 'INPUT' && ( tag.type == 'text' || tag.type == 'password' ) )
180                                {
181                                        menu.AddSeparator() ;
182                                        menu.AddItem( 'TextField', FCKLang.TextFieldProp, 51 ) ;
183                                }
184                        }} ;
185
186                case 'HiddenField' :
187                        return {
188                        AddItems : function( menu, tag, tagName )
189                        {
190                                if ( tagName == 'INPUT' && tag.type == 'hidden' )
191                                {
192                                        menu.AddSeparator() ;
193                                        menu.AddItem( 'HiddenField', FCKLang.HiddenFieldProp, 56 ) ;
194                                }
195                        }} ;
196
197                case 'ImageButton' :
198                        return {
199                        AddItems : function( menu, tag, tagName )
200                        {
201                                if ( tagName == 'INPUT' && tag.type == 'image' )
202                                {
203                                        menu.AddSeparator() ;
204                                        menu.AddItem( 'ImageButton', FCKLang.ImageButtonProp, 55 ) ;
205                                }
206                        }} ;
207
208                case 'Button' :
209                        return {
210                        AddItems : function( menu, tag, tagName )
211                        {
212                                if ( tagName == 'INPUT' && ( tag.type == 'button' || tag.type == 'submit' || tag.type == 'reset' ) )
213                                {
214                                        menu.AddSeparator() ;
215                                        menu.AddItem( 'Button', FCKLang.ButtonProp, 54 ) ;
216                                }
217                        }} ;
218
219                case 'Select' :
220                        return {
221                        AddItems : function( menu, tag, tagName )
222                        {
223                                if ( tagName == 'SELECT' )
224                                {
225                                        menu.AddSeparator() ;
226                                        menu.AddItem( 'Select', FCKLang.SelectionFieldProp, 53 ) ;
227                                }
228                        }} ;
229
230                case 'Textarea' :
231                        return {
232                        AddItems : function( menu, tag, tagName )
233                        {
234                                if ( tagName == 'TEXTAREA' )
235                                {
236                                        menu.AddSeparator() ;
237                                        menu.AddItem( 'Textarea', FCKLang.TextareaProp, 52 ) ;
238                                }
239                        }} ;
240
241                case 'BulletedList' :
242                        return {
243                        AddItems : function( menu, tag, tagName )
244                        {
245                                if ( FCKSelection.HasAncestorNode('UL') )
246                                {
247                                        menu.AddSeparator() ;
248                                        menu.AddItem( 'BulletedList', FCKLang.BulletedListProp, 27 ) ;
249                                }
250                        }} ;
251
252                case 'NumberedList' :
253                        return {
254                        AddItems : function( menu, tag, tagName )
255                        {
256                                if ( FCKSelection.HasAncestorNode('OL') )
257                                {
258                                        menu.AddSeparator() ;
259                                        menu.AddItem( 'NumberedList', FCKLang.NumberedListProp, 26 ) ;
260                                }
261                        }} ;
262        }
263}
264
265function FCK_ContextMenu_OnBeforeOpen()
266{
267        // Update the UI.
268        FCK.Events.FireEvent( "OnSelectionChange" ) ;
269
270        // Get the actual selected tag (if any).
271        var oTag, sTagName ;
272       
273        if ( oTag = FCKSelection.GetSelectedElement() )
274                sTagName = oTag.tagName ;
275
276        // Cleanup the current menu items.
277        var oMenu = FCK.ContextMenu._InnerContextMenu ;
278        oMenu.RemoveAllItems() ;
279
280        // Loop through the listeners.
281        var aListeners = FCK.ContextMenu.Listeners ;
282        for ( var i = 0 ; i < aListeners.length ; i++ )
283                aListeners[i].AddItems( oMenu, oTag, sTagName ) ;
284}
285
286function FCK_ContextMenu_OnItemClick( item )
287{
288        FCK.Focus() ;
289        FCKCommands.GetCommand( item.Name ).Execute() ;
290}
Note: See TracBrowser for help on using the repository browser.