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 * Define all commands available in the editor.
22 */
23
24var FCKCommands = FCK.Commands = new Object() ;
25FCKCommands.LoadedCommands = new Object() ;
26
27FCKCommands.RegisterCommand = function( commandName, command )
28{
29	this.LoadedCommands[ commandName ] = command ;
30}
31
32FCKCommands.GetCommand = function( commandName )
33{
34	var oCommand = FCKCommands.LoadedCommands[ commandName ] ;
35
36	if ( oCommand )
37		return oCommand ;
38
39	switch ( commandName )
40	{
41		case 'Bold'			:
42		case 'Italic'		:
43		case 'Underline'	:
44		case 'StrikeThrough':
45		case 'Subscript'	:
46		case 'Superscript'	: oCommand = new FCKCoreStyleCommand( commandName ) ; break ;
47
48		case 'RemoveFormat'	: oCommand = new FCKRemoveFormatCommand() ; break ;
49
50		case 'DocProps'		: oCommand = new FCKDialogCommand( 'DocProps'	, FCKLang.DocProps				, 'dialog/fck_docprops.html'	, 400, 390, FCKCommands.GetFullPageState ) ; break ;
51		case 'Templates'	: oCommand = new FCKDialogCommand( 'Templates'	, FCKLang.DlgTemplatesTitle		, 'dialog/fck_template.html'	, 380, 450 ) ; break ;
52		case 'Link'			: oCommand = new FCKDialogCommand( 'Link'		, FCKLang.DlgLnkWindowTitle		, 'dialog/fck_link.html'		, 400, 330 ) ; break ;
53		case 'Unlink'		: oCommand = new FCKUnlinkCommand() ; break ;
54		case 'Anchor'		: oCommand = new FCKDialogCommand( 'Anchor'		, FCKLang.DlgAnchorTitle		, 'dialog/fck_anchor.html'		, 370, 170 ) ; break ;
55		case 'AnchorDelete'	: oCommand = new FCKAnchorDeleteCommand() ; break ;
56		case 'BulletedList'	: oCommand = new FCKDialogCommand( 'BulletedList', FCKLang.BulletedListProp		, 'dialog/fck_listprop.html?UL'	, 370, 170 ) ; break ;
57		case 'NumberedList'	: oCommand = new FCKDialogCommand( 'NumberedList', FCKLang.NumberedListProp		, 'dialog/fck_listprop.html?OL'	, 370, 170 ) ; break ;
58		case 'About'		: oCommand = new FCKDialogCommand( 'About'		, FCKLang.About					, 'dialog/fck_about.html'		, 400, 330 ) ; break ;
59
60		case 'Find'			: oCommand = new FCKDialogCommand( 'Find'		, FCKLang.DlgFindAndReplaceTitle			, 'dialog/fck_replace.html'		, 340, 250 ) ; break ;
61		case 'Replace'		: oCommand = new FCKDialogCommand( 'Replace'	, FCKLang.DlgFindAndReplaceTitle		, 'dialog/fck_replace.html'		, 340, 250 ) ; break ;
62
63		case 'Image'		: oCommand = new FCKDialogCommand( 'Image'		, FCKLang.DlgImgTitle			, 'dialog/fck_image.html'		, 450, 400 ) ; break ;
64		case 'Flash'		: oCommand = new FCKDialogCommand( 'Flash'		, FCKLang.DlgFlashTitle			, 'dialog/fck_flash.html'		, 450, 400 ) ; break ;
65		case 'SpecialChar'	: oCommand = new FCKDialogCommand( 'SpecialChar', FCKLang.DlgSpecialCharTitle	, 'dialog/fck_specialchar.html'	, 400, 320 ) ; break ;
66		case 'Smiley'		: oCommand = new FCKDialogCommand( 'Smiley'		, FCKLang.DlgSmileyTitle		, 'dialog/fck_smiley.html'		, FCKConfig.SmileyWindowWidth, FCKConfig.SmileyWindowHeight ) ; break ;
67		case 'Table'		: oCommand = new FCKDialogCommand( 'Table'		, FCKLang.DlgTableTitle			, 'dialog/fck_table.html'		, 450, 250 ) ; break ;
68		case 'TableProp'	: oCommand = new FCKDialogCommand( 'Table'		, FCKLang.DlgTableTitle			, 'dialog/fck_table.html?Parent', 400, 250 ) ; break ;
69		case 'TableCellProp': oCommand = new FCKDialogCommand( 'TableCell'	, FCKLang.DlgCellTitle			, 'dialog/fck_tablecell.html'	, 550, 250 ) ; break ;
70
71		case 'Style'		: oCommand = new FCKStyleCommand() ; break ;
72
73		case 'FontName'		: oCommand = new FCKFontNameCommand() ; break ;
74		case 'FontSize'		: oCommand = new FCKFontSizeCommand() ; break ;
75		case 'FontFormat'	: oCommand = new FCKFormatBlockCommand() ; break ;
76
77		case 'Source'		: oCommand = new FCKSourceCommand() ; break ;
78		case 'Preview'		: oCommand = new FCKPreviewCommand() ; break ;
79		case 'Save'			: oCommand = new FCKSaveCommand() ; break ;
80		case 'NewPage'		: oCommand = new FCKNewPageCommand() ; break ;
81		case 'PageBreak'	: oCommand = new FCKPageBreakCommand() ; break ;
82		case 'Rule'			: oCommand = new FCKRuleCommand() ; break ;
83
84		case 'TextColor'	: oCommand = new FCKTextColorCommand('ForeColor') ; break ;
85		case 'BGColor'		: oCommand = new FCKTextColorCommand('BackColor') ; break ;
86
87		case 'Paste'		: oCommand = new FCKPasteCommand() ; break ;
88		case 'PasteText'	: oCommand = new FCKPastePlainTextCommand() ; break ;
89		case 'PasteWord'	: oCommand = new FCKPasteWordCommand() ; break ;
90
91		case 'JustifyLeft'	: oCommand = new FCKJustifyCommand( 'left' ) ; break ;
92		case 'JustifyCenter'	: oCommand = new FCKJustifyCommand( 'center' ) ; break ;
93		case 'JustifyRight'	: oCommand = new FCKJustifyCommand( 'right' ) ; break ;
94		case 'JustifyFull'	: oCommand = new FCKJustifyCommand( 'justify' ) ; break ;
95		case 'Indent'	: oCommand = new FCKIndentCommand( 'indent', FCKConfig.IndentLength ) ; break ;
96		case 'Outdent'	: oCommand = new FCKIndentCommand( 'outdent', FCKConfig.IndentLength * -1 ) ; break ;
97		case 'Blockquote'	: oCommand = new FCKBlockQuoteCommand() ; break ;
98
99		case 'TableInsertRowAfter'		: oCommand = new FCKTableCommand('TableInsertRowAfter') ; break ;
100		case 'TableInsertRowBefore'		: oCommand = new FCKTableCommand('TableInsertRowBefore') ; break ;
101		case 'TableDeleteRows'			: oCommand = new FCKTableCommand('TableDeleteRows') ; break ;
102		case 'TableInsertColumnAfter'	: oCommand = new FCKTableCommand('TableInsertColumnAfter') ; break ;
103		case 'TableInsertColumnBefore'	: oCommand = new FCKTableCommand('TableInsertColumnBefore') ; break ;
104		case 'TableDeleteColumns'		: oCommand = new FCKTableCommand('TableDeleteColumns') ; break ;
105		case 'TableInsertCellAfter'		: oCommand = new FCKTableCommand('TableInsertCellAfter') ; break ;
106		case 'TableInsertCellBefore'	: oCommand = new FCKTableCommand('TableInsertCellBefore') ; break ;
107		case 'TableDeleteCells'			: oCommand = new FCKTableCommand('TableDeleteCells') ; break ;
108		case 'TableMergeCells'			: oCommand = new FCKTableCommand('TableMergeCells') ; break ;
109		case 'TableMergeRight'			: oCommand = new FCKTableCommand('TableMergeRight') ; break ;
110		case 'TableMergeDown'			: oCommand = new FCKTableCommand('TableMergeDown') ; break ;
111		case 'TableHorizontalSplitCell'	: oCommand = new FCKTableCommand('TableHorizontalSplitCell') ; break ;
112		case 'TableVerticalSplitCell'	: oCommand = new FCKTableCommand('TableVerticalSplitCell') ; break ;
113		case 'TableDelete'				: oCommand = new FCKTableCommand('TableDelete') ; break ;
114
115		case 'Form'			: oCommand = new FCKDialogCommand( 'Form'		, FCKLang.Form			, 'dialog/fck_form.html'		, 380, 230 ) ; break ;
116		case 'Checkbox'		: oCommand = new FCKDialogCommand( 'Checkbox'	, FCKLang.Checkbox		, 'dialog/fck_checkbox.html'	, 380, 230 ) ; break ;
117		case 'Radio'		: oCommand = new FCKDialogCommand( 'Radio'		, FCKLang.RadioButton	, 'dialog/fck_radiobutton.html'	, 380, 230 ) ; break ;
118		case 'TextField'	: oCommand = new FCKDialogCommand( 'TextField'	, FCKLang.TextField		, 'dialog/fck_textfield.html'	, 380, 230 ) ; break ;
119		case 'Textarea'		: oCommand = new FCKDialogCommand( 'Textarea'	, FCKLang.Textarea		, 'dialog/fck_textarea.html'	, 380, 230 ) ; break ;
120		case 'HiddenField'	: oCommand = new FCKDialogCommand( 'HiddenField', FCKLang.HiddenField	, 'dialog/fck_hiddenfield.html'	, 380, 230 ) ; break ;
121		case 'Button'		: oCommand = new FCKDialogCommand( 'Button'		, FCKLang.Button		, 'dialog/fck_button.html'		, 380, 230 ) ; break ;
122		case 'Select'		: oCommand = new FCKDialogCommand( 'Select'		, FCKLang.SelectionField, 'dialog/fck_select.html'		, 400, 380 ) ; break ;
123		case 'ImageButton'	: oCommand = new FCKDialogCommand( 'ImageButton', FCKLang.ImageButton	, 'dialog/fck_image.html?ImageButton', 450, 400 ) ; break ;
124
125		case 'SpellCheck'	: oCommand = new FCKSpellCheckCommand() ; break ;
126		case 'FitWindow'	: oCommand = new FCKFitWindow() ; break ;
127
128		case 'Undo'	: oCommand = new FCKUndoCommand() ; break ;
129		case 'Redo'	: oCommand = new FCKRedoCommand() ; break ;
130		case 'Copy'	: oCommand = new FCKCopyCommand() ; break ;
131
132		case 'SelectAll'			: oCommand = new FCKSelectAllCommand() ; break ;
133		case 'InsertOrderedList'	: oCommand = new FCKListCommand( 'insertorderedlist', 'ol' ) ; break ;
134		case 'InsertUnorderedList'	: oCommand = new FCKListCommand( 'insertunorderedlist', 'ul' ) ; break ;
135		case 'ShowBlocks' : oCommand = new FCKShowBlockCommand( 'ShowBlocks', FCKConfig.StartupShowBlocks ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ) ; break ;
136
137		// Generic Undefined command (usually used when a command is under development).
138		case 'Undefined'	: oCommand = new FCKUndefinedCommand() ; break ;
139
140		// By default we assume that it is a named command.
141		default:
142			if ( FCKRegexLib.NamedCommands.test( commandName ) )
143				oCommand = new FCKNamedCommand( commandName ) ;
144			else
145			{
146				alert( FCKLang.UnknownCommand.replace( /%1/g, commandName ) ) ;
147				return null ;
148			}
149	}
150
151	FCKCommands.LoadedCommands[ commandName ] = oCommand ;
152
153	return oCommand ;
154}
155
156// Gets the state of the "Document Properties" button. It must be enabled only
157// when "Full Page" editing is available.
158FCKCommands.GetFullPageState = function()
159{
160	return FCKConfig.FullPage ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ;
161}
162
163
164FCKCommands.GetBooleanState = function( isDisabled )
165{
166	return isDisabled ? FCK_TRISTATE_DISABLED : FCK_TRISTATE_OFF ;
167}
168