source: branches/1.2/workflow/js/fckeditor/editor/_source/commandclasses/fck_othercommands.js @ 1349

Revision 1349, 8.1 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
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 * Definition of other commands that are not available internaly in the
22 * browser (see FCKNamedCommand).
23 */
24
25// ### General Dialog Box Commands.
26var FCKDialogCommand = function( name, title, url, width, height, getStateFunction, getStateParam )
27{
28        this.Name       = name ;
29        this.Title      = title ;
30        this.Url        = url ;
31        this.Width      = width ;
32        this.Height     = height ;
33
34        this.GetStateFunction   = getStateFunction ;
35        this.GetStateParam              = getStateParam ;
36
37        this.Resizable = false ;
38}
39
40FCKDialogCommand.prototype.Execute = function()
41{
42        FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, null, null, this.Resizable ) ;
43}
44
45FCKDialogCommand.prototype.GetState = function()
46{
47        if ( this.GetStateFunction )
48                return this.GetStateFunction( this.GetStateParam ) ;
49        else
50                return FCK_TRISTATE_OFF ;
51}
52
53// Generic Undefined command (usually used when a command is under development).
54var FCKUndefinedCommand = function()
55{
56        this.Name = 'Undefined' ;
57}
58
59FCKUndefinedCommand.prototype.Execute = function()
60{
61        alert( FCKLang.NotImplemented ) ;
62}
63
64FCKUndefinedCommand.prototype.GetState = function()
65{
66        return FCK_TRISTATE_OFF ;
67}
68
69// ### FontName
70var FCKFontNameCommand = function()
71{
72        this.Name = 'FontName' ;
73}
74
75FCKFontNameCommand.prototype.Execute = function( fontName )
76{
77        if (fontName == null || fontName == "")
78        {
79                // TODO: Remove font name attribute.
80        }
81        else
82                FCK.ExecuteNamedCommand( 'FontName', fontName ) ;
83}
84
85FCKFontNameCommand.prototype.GetState = function()
86{
87        return FCK.GetNamedCommandValue( 'FontName' ) ;
88}
89
90// ### FontSize
91var FCKFontSizeCommand = function()
92{
93        this.Name = 'FontSize' ;
94}
95
96FCKFontSizeCommand.prototype.Execute = function( fontSize )
97{
98        if ( typeof( fontSize ) == 'string' ) fontSize = parseInt(fontSize, 10) ;
99
100        if ( fontSize == null || fontSize == '' )
101        {
102                // TODO: Remove font size attribute (Now it works with size 3. Will it work forever?)
103                FCK.ExecuteNamedCommand( 'FontSize', 3 ) ;
104        }
105        else
106                FCK.ExecuteNamedCommand( 'FontSize', fontSize ) ;
107}
108
109FCKFontSizeCommand.prototype.GetState = function()
110{
111        return FCK.GetNamedCommandValue( 'FontSize' ) ;
112}
113
114// ### FormatBlock
115var FCKFormatBlockCommand = function()
116{
117        this.Name = 'FormatBlock' ;
118}
119
120FCKFormatBlockCommand.prototype.Execute = function( formatName )
121{
122        if ( formatName == null || formatName == '' )
123                FCK.ExecuteNamedCommand( 'FormatBlock', '<P>' ) ;
124        else if ( formatName == 'div' && FCKBrowserInfo.IsGecko )
125                FCK.ExecuteNamedCommand( 'FormatBlock', 'div' ) ;
126        else
127                FCK.ExecuteNamedCommand( 'FormatBlock', '<' + formatName + '>' ) ;
128}
129
130FCKFormatBlockCommand.prototype.GetState = function()
131{
132        return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
133}
134
135// ### Preview
136var FCKPreviewCommand = function()
137{
138        this.Name = 'Preview' ;
139}
140
141FCKPreviewCommand.prototype.Execute = function()
142{
143     FCK.Preview() ;
144}
145
146FCKPreviewCommand.prototype.GetState = function()
147{
148        return FCK_TRISTATE_OFF ;
149}
150
151// ### Save
152var FCKSaveCommand = function()
153{
154        this.Name = 'Save' ;
155}
156
157FCKSaveCommand.prototype.Execute = function()
158{
159        // Get the linked field form.
160        var oForm = FCK.GetParentForm() ;
161
162        if ( typeof( oForm.onsubmit ) == 'function' )
163        {
164                var bRet = oForm.onsubmit() ;
165                if ( bRet != null && bRet === false )
166                        return ;
167        }
168
169        // Submit the form.
170        oForm.submit() ;
171}
172
173FCKSaveCommand.prototype.GetState = function()
174{
175        return FCK_TRISTATE_OFF ;
176}
177
178// ### NewPage
179var FCKNewPageCommand = function()
180{
181        this.Name = 'NewPage' ;
182}
183
184FCKNewPageCommand.prototype.Execute = function()
185{
186        FCKUndo.SaveUndoStep() ;
187        FCK.SetHTML( '' ) ;
188        FCKUndo.Typing = true ;
189}
190
191FCKNewPageCommand.prototype.GetState = function()
192{
193        return FCK_TRISTATE_OFF ;
194}
195
196// ### Source button
197var FCKSourceCommand = function()
198{
199        this.Name = 'Source' ;
200}
201
202FCKSourceCommand.prototype.Execute = function()
203{
204        if ( FCKConfig.SourcePopup )    // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.
205        {
206                var iWidth      = FCKConfig.ScreenWidth * 0.65 ;
207                var iHeight     = FCKConfig.ScreenHeight * 0.65 ;
208                FCKDialog.OpenDialog( 'FCKDialog_Source', FCKLang.Source, 'dialog/fck_source.html', iWidth, iHeight, null, null, true ) ;
209        }
210        else
211            FCK.SwitchEditMode() ;
212}
213
214FCKSourceCommand.prototype.GetState = function()
215{
216        return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;
217}
218
219// ### Undo
220var FCKUndoCommand = function()
221{
222        this.Name = 'Undo' ;
223}
224
225FCKUndoCommand.prototype.Execute = function()
226{
227        if ( FCKBrowserInfo.IsIE )
228                FCKUndo.Undo() ;
229        else
230                FCK.ExecuteNamedCommand( 'Undo' ) ;
231}
232
233FCKUndoCommand.prototype.GetState = function()
234{
235        if ( FCKBrowserInfo.IsIE )
236                return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
237        else
238                return FCK.GetNamedCommandState( 'Undo' ) ;
239}
240
241// ### Redo
242var FCKRedoCommand = function()
243{
244        this.Name = 'Redo' ;
245}
246
247FCKRedoCommand.prototype.Execute = function()
248{
249        if ( FCKBrowserInfo.IsIE )
250                FCKUndo.Redo() ;
251        else
252                FCK.ExecuteNamedCommand( 'Redo' ) ;
253}
254
255FCKRedoCommand.prototype.GetState = function()
256{
257        if ( FCKBrowserInfo.IsIE )
258                return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
259        else
260                return FCK.GetNamedCommandState( 'Redo' ) ;
261}
262
263// ### Page Break
264var FCKPageBreakCommand = function()
265{
266        this.Name = 'PageBreak' ;
267}
268
269FCKPageBreakCommand.prototype.Execute = function()
270{
271//      var e = FCK.EditorDocument.createElement( 'CENTER' ) ;
272//      e.style.pageBreakAfter = 'always' ;
273
274        // Tidy was removing the empty CENTER tags, so the following solution has
275        // been found. It also validates correctly as XHTML 1.0 Strict.
276        var e = FCK.EditorDocument.createElement( 'DIV' ) ;
277        e.style.pageBreakAfter = 'always' ;
278        e.innerHTML = '<span style="DISPLAY:none">&nbsp;</span>' ;
279
280        var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;
281        oFakeImage      = FCK.InsertElement( oFakeImage ) ;
282}
283
284FCKPageBreakCommand.prototype.GetState = function()
285{
286        return 0 ; // FCK_TRISTATE_OFF
287}
288
289// FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)
290var FCKUnlinkCommand = function()
291{
292        this.Name = 'Unlink' ;
293}
294
295FCKUnlinkCommand.prototype.Execute = function()
296{
297        if ( FCKBrowserInfo.IsGecko )
298        {
299                var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
300                if ( oLink )
301                        FCK.Selection.SelectNode( oLink ) ;
302        }
303
304        FCK.ExecuteNamedCommand( this.Name ) ;
305
306        if ( FCKBrowserInfo.IsGecko )
307                FCK.Selection.Collapse( true ) ;
308}
309
310FCKUnlinkCommand.prototype.GetState = function()
311{
312        var state = FCK.GetNamedCommandState( this.Name ) ;
313
314        // Check that it isn't an anchor
315        if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG )
316        {
317                var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
318                var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
319                if ( bIsAnchor )
320                        state = FCK_TRISTATE_DISABLED ;
321        }
322
323        return state ;
324}
325
326// FCKSelectAllCommand
327var FCKSelectAllCommand = function()
328{
329        this.Name = 'SelectAll' ;
330}
331
332FCKSelectAllCommand.prototype.Execute = function()
333{
334        if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
335        {
336                FCK.ExecuteNamedCommand( 'SelectAll' ) ;
337        }
338        else
339        {
340                // Select the contents of the textarea
341                var textarea = FCK.EditingArea.Textarea ;
342                if ( FCKBrowserInfo.IsIE )
343                {
344                        textarea.createTextRange().execCommand( 'SelectAll' ) ;
345                }
346                else
347                {
348                        textarea.selectionStart = 0;
349                        textarea.selectionEnd = textarea.value.length ;
350                }
351                textarea.focus() ;
352        }
353}
354
355FCKSelectAllCommand.prototype.GetState = function()
356{
357        return FCK_TRISTATE_OFF ;
358}
359
360// FCKPasteCommand
361var FCKPasteCommand = function()
362{
363        this.Name = 'Paste' ;
364}
365
366FCKPasteCommand.prototype =
367{
368        Execute : function()
369        {
370                if ( FCKBrowserInfo.IsIE )
371                        FCK.Paste() ;
372                else
373                        FCK.ExecuteNamedCommand( 'Paste' ) ;
374        },
375
376        GetState : function()
377        {
378                return FCK.GetNamedCommandState( 'Paste' ) ;
379        }
380} ;
Note: See TracBrowser for help on using the repository browser.