2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Definition of other commands that are not available internaly in the
22
* browser (see FCKNamedCommand).
25
// ### General Dialog Box Commands.
26
var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam )
32
this.Height = height ;
34
this.GetStateFunction = getStateFunction ;
35
this.GetStateParam = getStateParam ;
37
this.Resizable = false ;
40
FCKDialogCommand.prototype.Execute = function()
42
FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, null, null, this.Resizable ) ;
45
FCKDialogCommand.prototype.GetState = function()
47
if ( this.GetStateFunction )
48
return this.GetStateFunction( this.GetStateParam ) ;
50
return FCK_TRISTATE_OFF ;
53
// Generic Undefined command (usually used when a command is under development).
54
var FCKUndefinedCommand = function()
56
this.Name = 'Undefined' ;
59
FCKUndefinedCommand.prototype.Execute = function()
61
alert( FCKLang.NotImplemented ) ;
64
FCKUndefinedCommand.prototype.GetState = function()
66
return FCK_TRISTATE_OFF ;
70
var FCKFontNameCommand = function()
72
this.Name = 'FontName' ;
75
FCKFontNameCommand.prototype.Execute = function( fontName )
77
if (fontName == null || fontName == "")
79
// TODO: Remove font name attribute.
82
FCK.ExecuteNamedCommand( 'FontName', fontName ) ;
85
FCKFontNameCommand.prototype.GetState = function()
87
return FCK.GetNamedCommandValue( 'FontName' ) ;
91
var FCKFontSizeCommand = function()
93
this.Name = 'FontSize' ;
96
FCKFontSizeCommand.prototype.Execute = function( fontSize )
98
if ( typeof( fontSize ) == 'string' ) fontSize = parseInt(fontSize, 10) ;
100
if ( fontSize == null || fontSize == '' )
102
// TODO: Remove font size attribute (Now it works with size 3. Will it work forever?)
103
FCK.ExecuteNamedCommand( 'FontSize', 3 ) ;
106
FCK.ExecuteNamedCommand( 'FontSize', fontSize ) ;
109
FCKFontSizeCommand.prototype.GetState = function()
111
return FCK.GetNamedCommandValue( 'FontSize' ) ;
115
var FCKFormatBlockCommand = function()
117
this.Name = 'FormatBlock' ;
120
FCKFormatBlockCommand.prototype.Execute = function( formatName )
122
if ( formatName == null || formatName == '' )
123
FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' ) ;
124
else if ( formatName == 'div' && FCKBrowserInfo.IsGecko )
125
FCK.ExecuteNamedCommand( 'FormatBlock', 'div' ) ;
127
FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' ) ;
130
FCKFormatBlockCommand.prototype.GetState = function()
132
return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
136
var FCKPreviewCommand = function()
138
this.Name = 'Preview' ;
141
FCKPreviewCommand.prototype.Execute = function()
146
FCKPreviewCommand.prototype.GetState = function()
148
return FCK_TRISTATE_OFF ;
152
var FCKSaveCommand = function()
157
FCKSaveCommand.prototype.Execute = function()
159
// Get the linked field form.
160
var oForm = FCK.GetParentForm() ;
162
if ( typeof( oForm.onsubmit ) == 'function' )
164
var bRet = oForm.onsubmit() ;
165
if ( bRet != null && bRet === false )
170
// If there's a button named "submit" then the form.submit() function is masked and
171
// can't be called in Mozilla, so we call the click() method of that button.
172
if ( typeof( oForm.submit ) == 'function' )
175
oForm.submit.click() ;
178
FCKSaveCommand.prototype.GetState = function()
180
return FCK_TRISTATE_OFF ;
184
var FCKNewPageCommand = function()
186
this.Name = 'NewPage' ;
189
FCKNewPageCommand.prototype.Execute = function()
191
FCKUndo.SaveUndoStep() ;
193
FCKUndo.Typing = true ;
196
FCKNewPageCommand.prototype.GetState = function()
198
return FCK_TRISTATE_OFF ;
202
var FCKSourceCommand = function()
204
this.Name = 'Source' ;
207
FCKSourceCommand.prototype.Execute = function()
209
if ( FCKConfig.SourcePopup ) // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.
211
var iWidth = FCKConfig.ScreenWidth * 0.65 ;
212
var iHeight = FCKConfig.ScreenHeight * 0.65 ;
213
FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, null, true ) ;
216
FCK.SwitchEditMode() ;
219
FCKSourceCommand.prototype.GetState = function()
221
return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;
225
var FCKUndoCommand = function()
230
FCKUndoCommand.prototype.Execute = function()
232
if ( FCKBrowserInfo.IsIE )
235
FCK.ExecuteNamedCommand( 'Undo' ) ;
238
FCKUndoCommand.prototype.GetState = function()
240
if ( FCKBrowserInfo.IsIE )
241
return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
243
return FCK.GetNamedCommandState( 'Undo' ) ;
247
var FCKRedoCommand = function()
252
FCKRedoCommand.prototype.Execute = function()
254
if ( FCKBrowserInfo.IsIE )
257
FCK.ExecuteNamedCommand( 'Redo' ) ;
260
FCKRedoCommand.prototype.GetState = function()
262
if ( FCKBrowserInfo.IsIE )
263
return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
265
return FCK.GetNamedCommandState( 'Redo' ) ;
269
var FCKPageBreakCommand = function()
271
this.Name = 'PageBreak' ;
274
FCKPageBreakCommand.prototype.Execute = function()
276
// var e = FCK.EditorDocument.createElement( 'CENTER' ) ;
277
// e.style.pageBreakAfter = 'always' ;
279
// Tidy was removing the empty CENTER tags, so the following solution has
280
// been found. It also validates correctly as XHTML 1.0 Strict.
281
var e = FCK.EditorDocument.createElement( 'DIV' ) ;
282
e.style.pageBreakAfter = 'always' ;
283
e.innerHTML = '<span style="DISPLAY:none"> </span>' ;
285
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;
286
oFakeImage = FCK.InsertElement( oFakeImage ) ;
289
FCKPageBreakCommand.prototype.GetState = function()
291
return 0 ; // FCK_TRISTATE_OFF
294
// FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)
295
var FCKUnlinkCommand = function()
297
this.Name = 'Unlink' ;
300
FCKUnlinkCommand.prototype.Execute = function()
302
if ( FCKBrowserInfo.IsGecko )
304
var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
305
// The unlink command can generate a span in Firefox, so let's do it our way. See #430
307
FCKTools.RemoveOuterTags( oLink ) ;
312
FCK.ExecuteNamedCommand( this.Name ) ;
315
FCKUnlinkCommand.prototype.GetState = function()
317
var state = FCK.GetNamedCommandState( this.Name ) ;
319
// Check that it isn't an anchor
320
if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG )
322
var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
323
var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
325
state = FCK_TRISTATE_DISABLED ;
331
// FCKSelectAllCommand
332
var FCKSelectAllCommand = function()
334
this.Name = 'SelectAll' ;
337
FCKSelectAllCommand.prototype.Execute = function()
339
if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
341
FCK.ExecuteNamedCommand( 'SelectAll' ) ;
345
// Select the contents of the textarea
346
var textarea = FCK.EditingArea.Textarea ;
347
if ( FCKBrowserInfo.IsIE )
349
textarea.createTextRange().execCommand( 'SelectAll' ) ;
353
textarea.selectionStart = 0;
354
textarea.selectionEnd = textarea.value.length ;
360
FCKSelectAllCommand.prototype.GetState = function()
362
return FCK_TRISTATE_OFF ;
366
var FCKPasteCommand = function()
368
this.Name = 'Paste' ;
371
FCKPasteCommand.prototype =
375
if ( FCKBrowserInfo.IsIE )
378
FCK.ExecuteNamedCommand( 'Paste' ) ;
381
GetState : function()
383
return FCK.GetNamedCommandState( 'Paste' ) ;