431 |
ddelon |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for internet
|
|
|
3 |
* Copyright (C) 2003-2005 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 |
* File Name: fckcontextmenu.js
|
|
|
12 |
* Defines the FCKContextMenu object that is responsible for all
|
|
|
13 |
* Context Menu operations.
|
|
|
14 |
*
|
|
|
15 |
* File Authors:
|
|
|
16 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
var FCKContextMenu = new Object() ;
|
|
|
20 |
|
|
|
21 |
// This property is internally used to indicate that the context menu has been created.
|
|
|
22 |
FCKContextMenu._IsLoaded = false ;
|
|
|
23 |
|
|
|
24 |
// This method creates the context menu inside a DIV tag. Take a look at the end of this file for a sample output.
|
|
|
25 |
FCKContextMenu.Reload = function()
|
|
|
26 |
{
|
|
|
27 |
// Create the Main DIV that holds the Context Menu.
|
|
|
28 |
this._Div = this._Document.createElement( 'DIV' ) ;
|
|
|
29 |
this._Div.className = 'CM_ContextMenu' ;
|
|
|
30 |
this._Div.style.position = 'absolute' ;
|
|
|
31 |
this._Div.style.visibility = 'hidden' ;
|
|
|
32 |
this._Document.body.appendChild( this._Div );
|
|
|
33 |
|
|
|
34 |
// Create the main table for the menu items.
|
|
|
35 |
var oTable = this._Document.createElement( 'TABLE' ) ;
|
|
|
36 |
oTable.cellSpacing = 0 ;
|
|
|
37 |
oTable.cellPadding = 0 ;
|
|
|
38 |
oTable.border = 0 ;
|
|
|
39 |
this._Div.appendChild( oTable ) ;
|
|
|
40 |
|
|
|
41 |
// Load all configured groups.
|
|
|
42 |
this.Groups = new Object() ;
|
|
|
43 |
|
|
|
44 |
for ( var i = 0 ; i < FCKConfig.ContextMenu.length ; i++ )
|
|
|
45 |
{
|
|
|
46 |
var sGroup = FCKConfig.ContextMenu[i] ;
|
|
|
47 |
this.Groups[ sGroup ] = this._GetGroup( sGroup ) ;
|
|
|
48 |
this.Groups[ sGroup ].CreateTableRows( oTable ) ;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
this._IsLoaded = true ;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
FCKContextMenu._GetGroup = function( groupName )
|
|
|
55 |
{
|
|
|
56 |
var oGroup ;
|
|
|
57 |
|
|
|
58 |
switch ( groupName )
|
|
|
59 |
{
|
|
|
60 |
case 'Generic' :
|
|
|
61 |
// Generic items that are always available.
|
|
|
62 |
oGroup = new FCKContextMenuGroup() ;
|
|
|
63 |
with ( oGroup )
|
|
|
64 |
{
|
|
|
65 |
Add( new FCKContextMenuItem( this, 'Cut' , FCKLang.Cut , true ) ) ;
|
|
|
66 |
Add( new FCKContextMenuItem( this, 'Copy' , FCKLang.Copy , true ) ) ;
|
|
|
67 |
Add( new FCKContextMenuItem( this, 'Paste' , FCKLang.Paste , true ) ) ;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
break ;
|
|
|
71 |
|
|
|
72 |
case 'Link' :
|
|
|
73 |
oGroup = new FCKContextMenuGroup() ;
|
|
|
74 |
with ( oGroup )
|
|
|
75 |
{
|
|
|
76 |
Add( new FCKContextMenuSeparator() ) ;
|
|
|
77 |
Add( new FCKContextMenuItem( this, 'Link' , FCKLang.EditLink , true ) ) ;
|
|
|
78 |
Add( new FCKContextMenuItem( this, 'Unlink' , FCKLang.RemoveLink, true ) ) ;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
break ;
|
|
|
82 |
|
|
|
83 |
case 'TableCell' :
|
|
|
84 |
oGroup = new FCKContextMenuGroup() ;
|
|
|
85 |
with ( oGroup )
|
|
|
86 |
{
|
|
|
87 |
Add( new FCKContextMenuSeparator() ) ;
|
|
|
88 |
Add( new FCKContextMenuItem( this, 'TableInsertRow' , FCKLang.InsertRow, true ) ) ;
|
|
|
89 |
Add( new FCKContextMenuItem( this, 'TableDeleteRows' , FCKLang.DeleteRows, true ) ) ;
|
|
|
90 |
Add( new FCKContextMenuSeparator() ) ;
|
|
|
91 |
Add( new FCKContextMenuItem( this, 'TableInsertColumn' , FCKLang.InsertColumn, true ) ) ;
|
|
|
92 |
Add( new FCKContextMenuItem( this, 'TableDeleteColumns' , FCKLang.DeleteColumns, true ) ) ;
|
|
|
93 |
Add( new FCKContextMenuSeparator() ) ;
|
|
|
94 |
Add( new FCKContextMenuItem( this, 'TableInsertCell' , FCKLang.InsertCell, true ) ) ;
|
|
|
95 |
Add( new FCKContextMenuItem( this, 'TableDeleteCells' , FCKLang.DeleteCells, true ) ) ;
|
|
|
96 |
Add( new FCKContextMenuItem( this, 'TableMergeCells' , FCKLang.MergeCells, true ) ) ;
|
|
|
97 |
Add( new FCKContextMenuItem( this, 'TableSplitCell' , FCKLang.SplitCell, true ) ) ;
|
|
|
98 |
Add( new FCKContextMenuSeparator() ) ;
|
|
|
99 |
Add( new FCKContextMenuItem( this, 'TableCellProp' , FCKLang.CellProperties, true ) ) ;
|
|
|
100 |
Add( new FCKContextMenuItem( this, 'TableProp' , FCKLang.TableProperties, true ) ) ;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
break ;
|
|
|
104 |
|
|
|
105 |
case 'Table' :
|
|
|
106 |
return new FCKContextMenuGroup( true, this, 'Table', FCKLang.TableProperties, true ) ;
|
|
|
107 |
|
|
|
108 |
case 'Image' :
|
|
|
109 |
return new FCKContextMenuGroup( true, this, 'Image', FCKLang.ImageProperties, true ) ;
|
|
|
110 |
|
|
|
111 |
case 'Flash' :
|
|
|
112 |
return new FCKContextMenuGroup( true, this, 'Flash', FCKLang.FlashProperties, true ) ;
|
|
|
113 |
|
|
|
114 |
case 'Form' :
|
|
|
115 |
return new FCKContextMenuGroup( true, this, 'Form', FCKLang.FormProp, true ) ;
|
|
|
116 |
|
|
|
117 |
case 'Checkbox' :
|
|
|
118 |
return new FCKContextMenuGroup( true, this, 'Checkbox', FCKLang.CheckboxProp, true ) ;
|
|
|
119 |
|
|
|
120 |
case 'Radio' :
|
|
|
121 |
return new FCKContextMenuGroup( true, this, 'Radio', FCKLang.RadioButtonProp, true ) ;
|
|
|
122 |
|
|
|
123 |
case 'TextField' :
|
|
|
124 |
return new FCKContextMenuGroup( true, this, 'TextField', FCKLang.TextFieldProp, true ) ;
|
|
|
125 |
|
|
|
126 |
case 'HiddenField' :
|
|
|
127 |
return new FCKContextMenuGroup( true, this, 'HiddenField', FCKLang.HiddenFieldProp, true ) ;
|
|
|
128 |
|
|
|
129 |
case 'ImageButton' :
|
|
|
130 |
return new FCKContextMenuGroup( true, this, 'ImageButton', FCKLang.ImageButtonProp, true ) ;
|
|
|
131 |
|
|
|
132 |
case 'Button' :
|
|
|
133 |
return new FCKContextMenuGroup( true, this, 'Button', FCKLang.ButtonProp, true ) ;
|
|
|
134 |
|
|
|
135 |
case 'Select' :
|
|
|
136 |
return new FCKContextMenuGroup( true, this, 'Select', FCKLang.SelectionFieldProp, true ) ;
|
|
|
137 |
|
|
|
138 |
case 'Textarea' :
|
|
|
139 |
return new FCKContextMenuGroup( true, this, 'Textarea', FCKLang.TextareaProp, true ) ;
|
|
|
140 |
|
|
|
141 |
case 'BulletedList' :
|
|
|
142 |
return new FCKContextMenuGroup( true, this, 'BulletedList', FCKLang.BulletedListProp, true ) ;
|
|
|
143 |
|
|
|
144 |
case 'NumberedList' :
|
|
|
145 |
return new FCKContextMenuGroup( true, this, 'NumberedList', FCKLang.NumberedListProp, true ) ;
|
|
|
146 |
|
|
|
147 |
case 'Anchor' :
|
|
|
148 |
return new FCKContextMenuGroup( true, this, 'Anchor', FCKLang.AnchorProp, true ) ;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
return oGroup ;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
FCKContextMenu.RefreshState = function()
|
|
|
155 |
{
|
|
|
156 |
// Get the actual selected tag (if any).
|
|
|
157 |
var oTag = FCKSelection.GetSelectedElement() ;
|
|
|
158 |
var sTagName ;
|
|
|
159 |
|
|
|
160 |
if ( oTag )
|
|
|
161 |
{
|
|
|
162 |
sTagName = oTag.tagName ;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
// Set items visibility.
|
|
|
166 |
|
|
|
167 |
// var bIsAnchor = ( sTagName == 'A' && oTag.name.length > 0 && oTag.href.length == 0 ) ;
|
|
|
168 |
|
|
|
169 |
if ( this.Groups['Link'] ) this.Groups['Link'].SetVisible( /*!bIsAnchor &&*/ FCK.GetNamedCommandState( 'Unlink' ) != FCK_TRISTATE_DISABLED ) ;
|
|
|
170 |
|
|
|
171 |
if ( this.Groups['TableCell'] ) this.Groups['TableCell'].SetVisible( sTagName != 'TABLE' && FCKSelection.HasAncestorNode('TABLE') ) ;
|
|
|
172 |
if ( this.Groups['Table'] ) this.Groups['Table'].SetVisible( sTagName == 'TABLE' ) ;
|
|
|
173 |
|
|
|
174 |
if ( this.Groups['Image'] ) this.Groups['Image'].SetVisible( sTagName == 'IMG' && !oTag.getAttribute('_fckflash') && !oTag.getAttribute('_fckanchor') ) ;
|
|
|
175 |
if ( this.Groups['Flash'] ) this.Groups['Flash'].SetVisible( sTagName == 'IMG' && oTag.getAttribute('_fckflash') ) ;
|
|
|
176 |
if ( this.Groups['Anchor'] ) this.Groups['Anchor'].SetVisible( sTagName == 'IMG' && oTag.getAttribute('_fckanchor') ) ;
|
|
|
177 |
|
|
|
178 |
if ( this.Groups['BulletedList'] ) this.Groups['BulletedList'].SetVisible( FCKSelection.HasAncestorNode('UL') ) ;
|
|
|
179 |
if ( this.Groups['NumberedList'] ) this.Groups['NumberedList'].SetVisible( FCKSelection.HasAncestorNode('OL') ) ;
|
|
|
180 |
|
|
|
181 |
if ( this.Groups['Select'] ) this.Groups['Select'].SetVisible( sTagName == 'SELECT' ) ;
|
|
|
182 |
if ( this.Groups['Textarea'] ) this.Groups['Textarea'].SetVisible( sTagName == 'TEXTAREA' ) ;
|
|
|
183 |
if ( this.Groups['Form'] ) this.Groups['Form'].SetVisible( FCKSelection.HasAncestorNode('FORM') ) ;
|
|
|
184 |
if ( this.Groups['Checkbox'] ) this.Groups['Checkbox'].SetVisible( sTagName == 'INPUT' && oTag.type == 'checkbox' ) ;
|
|
|
185 |
if ( this.Groups['Radio'] ) this.Groups['Radio'].SetVisible( sTagName == 'INPUT' && oTag.type == 'radio' ) ;
|
|
|
186 |
if ( this.Groups['TextField'] ) this.Groups['TextField'].SetVisible( sTagName == 'INPUT' && ( oTag.type == 'text' || oTag.type == 'password' ) ) ;
|
|
|
187 |
if ( this.Groups['HiddenField'] ) this.Groups['HiddenField'].SetVisible( sTagName == 'INPUT' && oTag.type == 'hidden' ) ;
|
|
|
188 |
if ( this.Groups['ImageButton'] ) this.Groups['ImageButton'].SetVisible( sTagName == 'INPUT' && oTag.type == 'image' ) ;
|
|
|
189 |
if ( this.Groups['Button'] ) this.Groups['Button'].SetVisible( sTagName == 'INPUT' && ( oTag.type == 'button' || oTag.type == 'submit' || oTag.type == 'reset' ) ) ;
|
|
|
190 |
|
|
|
191 |
// Refresh the state of all visible items (active/disactive)
|
|
|
192 |
for ( var o in this.Groups )
|
|
|
193 |
{
|
|
|
194 |
this.Groups[o].RefreshState() ;
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
/*
|
|
|
199 |
Sample Context Menu Output
|
|
|
200 |
-----------------------------------------
|
|
|
201 |
<div class="CM_ContextMenu">
|
|
|
202 |
<table cellSpacing="0" cellPadding="0" border="0">
|
|
|
203 |
<tr class="CM_Disabled">
|
|
|
204 |
<td class="CM_Icon"><img alt="" src="icons/cut.gif" width="21" height="20" unselectable="on"></td>
|
|
|
205 |
<td class="CM_Label" unselectable="on">Cut</td>
|
|
|
206 |
</tr>
|
|
|
207 |
<tr class="CM_Disabled">
|
|
|
208 |
<td class="CM_Icon"><img height="20" alt="" src="icons/copy.gif" width="21"></td>
|
|
|
209 |
<td class="CM_Label">Copy</td>
|
|
|
210 |
</tr>
|
|
|
211 |
<tr class="CM_Option" onmouseover="OnOver(this);" onmouseout="OnOut(this);">
|
|
|
212 |
<td class="CM_Icon"><img height="20" alt="" src="icons/paste.gif" width="21"></td>
|
|
|
213 |
<td class="CM_Label">Paste</td>
|
|
|
214 |
</tr>
|
|
|
215 |
<tr class="CM_Separator">
|
|
|
216 |
<td class="CM_Icon"></td>
|
|
|
217 |
<td class="CM_Label"><div></div></td>
|
|
|
218 |
</tr>
|
|
|
219 |
<tr class="CM_Option" onmouseover="OnOver(this);" onmouseout="OnOut(this);">
|
|
|
220 |
<td class="CM_Icon"><img height="20" alt="" src="icons/print.gif" width="21"></td>
|
|
|
221 |
<td class="CM_Label">Print</td>
|
|
|
222 |
</tr>
|
|
|
223 |
<tr class="CM_Separator">
|
|
|
224 |
<td class="CM_Icon"></td>
|
|
|
225 |
<td class="CM_Label"><div></div></td>
|
|
|
226 |
</tr>
|
|
|
227 |
<tr class="CM_Option" onmouseover="OnOver(this);" onmouseout="OnOut(this);">
|
|
|
228 |
<td class="CM_Icon"></td>
|
|
|
229 |
<td class="CM_Label">Do Something</td>
|
|
|
230 |
</tr>
|
|
|
231 |
<tr class="CM_Option" onmouseover="OnOver(this);" onmouseout="OnOut(this);">
|
|
|
232 |
<td class="CM_Icon"></td>
|
|
|
233 |
<td class="CM_Label">Just Testing</td>
|
|
|
234 |
</tr>
|
|
|
235 |
</table>
|
|
|
236 |
</div>
|
|
|
237 |
*/
|