2
/* ##########################################################
3
* RestrictedNamedCommand
4
* extends FCKNamedCommand
5
* ##########################################################
7
var RestrictedNamedCommand = function(commandName, forbidden)
9
this.Name = commandName;
10
this.forbidden = forbidden;
13
RestrictedNamedCommand.prototype = new FCKNamedCommand();
15
RestrictedNamedCommand.prototype.GetState = function()
17
var bState = FCK.GetNamedCommandState(this.Name);
18
if (FCKSelection.GetType() == 'Control')
22
else if (FCKSelection.CheckForNodeNames(this.forbidden))
24
return FCK_TRISTATE_DISABLED;
29
/* #######################################################
30
* RestrictedUniqueNamedFormat
31
* extends RestrictedNamedCommand
32
* #######################################################
35
var RestrictedUniqueNamedFormat = function(commandName, forbidden)
37
this.Name = commandName;
38
this.forbidden = forbidden;
41
RestrictedUniqueNamedFormat.prototype = new RestrictedNamedCommand();
43
RestrictedUniqueNamedFormat.prototype.Execute = function()
45
if (FCK.GetNamedCommandState(this.Name)==FCK_TRISTATE_OFF)
46
FCK.ExecuteNamedCommand('RemoveFormat');
48
FCK.ExecuteNamedCommand(this.Name);
51
/* #######################################################
52
* RestrictedFormatBlockCommand
53
* extends FCKFormatBlockCommand
54
* #######################################################
56
var RestrictedFormatBlockCommand = function(forbidden)
58
this.Name = 'FormatBlock' ;
59
this.forbidden = forbidden;
62
RestrictedFormatBlockCommand.prototype = new FCKFormatBlockCommand();
64
RestrictedFormatBlockCommand.prototype.GetState = function()
66
if (FCKSelection.CheckForNodeNames(this.forbidden))
67
return FCK_TRISTATE_DISABLED;
69
return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
72
RestrictedFormatBlockCommand.prototype.Execute = function( formatName )
74
if ( formatName == null || formatName == '' || formatName == 'P')
75
FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' );
78
FCK.ExecuteNamedCommand('RemoveFormat');
79
FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' );
83
/* ####################################################################
84
* RestrictedStyleCommand
85
* extends FCKStyleCommand
86
* ####################################################################
89
var RestrictedStyleCommand = function(forbidden)
91
this.forbidden = forbidden;
94
RestrictedStyleCommand.prototype = new FCKStyleCommand();
95
RestrictedStyleCommand.prototype.GetState = function()
97
if (FCKSelection.CheckForNodeNames(this.forbidden))
98
return FCK_TRISTATE_DISABLED;
101
var oSelection = FCK.EditorDocument.selection;
102
if ( FCKSelection.GetType() == 'Control' )
104
var e = FCKSelection.GetSelectedElement();
106
return this.StylesLoader.StyleGroups[e.tagName] ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
111
return FCK_TRISTATE_OFF;
115
RestrictedStyleCommand.prototype.Execute = function(styleName, styleComboItem )
117
if ( styleComboItem.Selected )
118
styleComboItem.Style.RemoveFromSelection() ;
121
if (styleName == "Typewriter")
122
FCK.ExecuteNamedCommand('RemoveFormat');
124
styleComboItem.Style.ApplyToSelection() ;
127
FCK.Events.FireEvent( "OnSelectionChange" );
130
/* ####################################################################
132
* ####################################################################
135
var StyleButtonCommand = function(stylename, unique)
137
// using FCK.Style instead of fckstylesloader
138
this.style = FCK.Styles.GetStyle(stylename);
139
this.unique = unique;
142
StyleButtonCommand.prototype = new FCKStyleCommand();
144
StyleButtonCommand.prototype.Execute = function()
146
if (this.GetState()==FCK_TRISTATE_ON)
148
this.style.RemoveFromSelection();
152
if (this.unique) FCK.ExecuteNamedCommand('RemoveFormat');
153
this.style.ApplyToSelection();
155
//FCKSelection.GetParentElement().normalize();
157
FCK.Events.FireEvent("OnSelectionChange");
162
/* ####################################################################
163
* RestrictedStyleButtonCommand
164
* ####################################################################
167
var RestrictedStyleButtonCommand = function(stylename, forbidden, unique)
169
this.style = FCK.Styles.GetStyle(stylename); // using FCK.Style instead of fckstylesloader
170
this.forbidden = forbidden;
171
this.unique = unique;
174
RestrictedStyleButtonCommand.prototype = new StyleButtonCommand();
176
RestrictedStyleButtonCommand.prototype.GetState = function()
178
if (FCKSelection.CheckForNodeNames(this.forbidden))
179
return FCK_TRISTATE_DISABLED;
182
aStyles = this.GetActiveStyles();
183
for (i=0;i<aStyles.length;i++)
184
if (aStyles[i] == this.style) return FCK_TRISTATE_ON;
185
return FCK_TRISTATE_OFF;
189
// ####################################################################
191
var noformat = "H1|H2|H3|H4|H5|H6|PRE|A|TT|IMG";
192
var noextendedformat = noformat + "|SUB|SUPER";
193
var noFormat = new RegExp("^(?:" + noformat + ")$", "i");
194
var noExtendedFormat = new RegExp("^(?:" + noextendedformat + ")$", "i");
195
var noFormatandIndent = new RegExp("^(?:" + noformat + "|TABLE|TR|TD)$", "i");
196
var noTT = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|IMG)$/i;
197
var noBlock = /^(?:TABLE|TR|TD|A|IMG)$/i;
198
var noSmileys = /^(?:H1|H2|H3|H4|H5|H6|PRE|A|TT|SUB|SUPER)$/i;
199
var noTable = new RegExp("^(?:" + noextendedformat + "|TABLE|UL|OL|DL)$", "i");
201
// Register some context sensitive commands
202
// register commands every browser
205
FCKCommands.RegisterCommand('Bold',
206
new RestrictedNamedCommand('Bold', noExtendedFormat));
207
FCKCommands.RegisterCommand('Italic',
208
new RestrictedNamedCommand('Italic', noExtendedFormat));
210
FCKCommands.RegisterCommand('Underline',
211
new RestrictedNamedCommand('Underline', noExtendedFormat));
212
FCKCommands.RegisterCommand('StrikeThrough',
213
new RestrictedNamedCommand('StrikeThrough', noExtendedFormat));
216
FCKCommands.RegisterCommand('Small',
217
new RestrictedStyleButtonCommand('Small', noExtendedFormat));
218
FCKCommands.RegisterCommand('Big',
219
new RestrictedStyleButtonCommand('Big', noExtendedFormat));
222
// formats no allowing formats inside
223
FCKCommands.RegisterCommand('Subscript',
224
new RestrictedUniqueNamedFormat('Subscript', noFormat));
225
FCKCommands.RegisterCommand('Superscript',
226
new RestrictedUniqueNamedFormat('Superscript', noFormat));
229
FCKCommands.RegisterCommand('Typewriter',
230
new RestrictedStyleButtonCommand('Typewriter', noTT, true));
234
FCKCommands.RegisterCommand('Outdent',
235
new RestrictedNamedCommand('Outdent', noFormatandIndent));
236
FCKCommands.RegisterCommand('Indent',
237
new RestrictedNamedCommand('Indent', noFormatandIndent));
238
FCKCommands.RegisterCommand('InsertOrderedList',
239
new RestrictedNamedCommand('InsertOrderedList', noFormatandIndent));
240
FCKCommands.RegisterCommand('InsertUnorderedList',
241
new RestrictedNamedCommand('InsertUnorderedList', noFormatandIndent));
242
FCKCommands.RegisterCommand('InsertHorizontalRule',
243
new RestrictedNamedCommand('InsertHorizontalRule', noFormatandIndent));
245
// Font formats and styles
246
FCKCommands.RegisterCommand('FontFormat',
247
new RestrictedFormatBlockCommand(noBlock));
248
FCKCommands.RegisterCommand('Style',
249
new RestrictedStyleCommand(noFormat));
252
FCKCommands.RegisterCommand('Smiley',
253
new FCKDialogCommand( 'Smiley', FCKLang.DlgSmileyTitle,
254
'dialog/fck_smiley.html', FCKConfig.SmileyWindowWidth,
255
FCKConfig.SmileyWindowHeight,
256
FCKSelection.CheckForNodeNames, noSmileys));
257
FCKCommands.RegisterCommand('Table', new FCKDialogCommand
258
('Table', FCKLang.DlgTableTitle, 'dialog/fck_table.html', 400, 250,
259
FCKSelection.CheckForNodeNames, noTable));
261
// useless code, this code make each menu's icon disapear.
263
// Make toolbar items context sensitive
264
FCKToolbarItems.RegisterItem('Smiley', new FCKToolbarButton
265
('Smiley', FCKLang.InsertSmileyLbl, FCKLang.InsertSmiley, null, false, true));
266
FCKToolbarItems.RegisterItem('Table', new FCKToolbarButton
267
('Table', FCKLang.InsertTableLbl, FCKLang.InsertTable, null, false, true));
270
FCKToolbarItems.RegisterItem('Big', new FCKToolbarButton
271
('Big', 'Big>', 'Big',
272
FCK_TOOLBARITEM_ONLYICON, false, true));
273
FCKToolbarItems.RegisterItem('Small', new FCKToolbarButton
274
('Small', 'Small', 'Small',
275
FCK_TOOLBARITEM_ONLYICON, false, true));
276
FCKToolbarItems.RegisterItem('Typewriter', new FCKToolbarButton
277
('Typewriter', 'Typewriter', 'Typewriter',
278
FCK_TOOLBARITEM_ONLYICON, false, true));