~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/javascript/FCK/editor/_source/commandclasses/fck_othercommands.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
26
var 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
 
 
40
FCKDialogCommand.prototype.Execute = function()
 
41
{
 
42
        FCKDialog.OpenDialog( 'FCKDialog_' + this.Name , this.Title, this.Url, this.Width, this.Height, null, null, this.Resizable ) ;
 
43
}
 
44
 
 
45
FCKDialogCommand.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).
 
54
var FCKUndefinedCommand = function()
 
55
{
 
56
        this.Name = 'Undefined' ;
 
57
}
 
58
 
 
59
FCKUndefinedCommand.prototype.Execute = function()
 
60
{
 
61
        alert( FCKLang.NotImplemented ) ;
 
62
}
 
63
 
 
64
FCKUndefinedCommand.prototype.GetState = function()
 
65
{
 
66
        return FCK_TRISTATE_OFF ;
 
67
}
 
68
 
 
69
// ### FontName
 
70
var FCKFontNameCommand = function()
 
71
{
 
72
        this.Name = 'FontName' ;
 
73
}
 
74
 
 
75
FCKFontNameCommand.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
 
 
85
FCKFontNameCommand.prototype.GetState = function()
 
86
{
 
87
        return FCK.GetNamedCommandValue( 'FontName' ) ;
 
88
}
 
89
 
 
90
// ### FontSize
 
91
var FCKFontSizeCommand = function()
 
92
{
 
93
        this.Name = 'FontSize' ;
 
94
}
 
95
 
 
96
FCKFontSizeCommand.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
 
 
109
FCKFontSizeCommand.prototype.GetState = function()
 
110
{
 
111
        return FCK.GetNamedCommandValue( 'FontSize' ) ;
 
112
}
 
113
 
 
114
// ### FormatBlock
 
115
var FCKFormatBlockCommand = function()
 
116
{
 
117
        this.Name = 'FormatBlock' ;
 
118
}
 
119
 
 
120
FCKFormatBlockCommand.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
 
 
130
FCKFormatBlockCommand.prototype.GetState = function()
 
131
{
 
132
        return FCK.GetNamedCommandValue( 'FormatBlock' ) ;
 
133
}
 
134
 
 
135
// ### Preview
 
136
var FCKPreviewCommand = function()
 
137
{
 
138
        this.Name = 'Preview' ;
 
139
}
 
140
 
 
141
FCKPreviewCommand.prototype.Execute = function()
 
142
{
 
143
     FCK.Preview() ;
 
144
}
 
145
 
 
146
FCKPreviewCommand.prototype.GetState = function()
 
147
{
 
148
        return FCK_TRISTATE_OFF ;
 
149
}
 
150
 
 
151
// ### Save
 
152
var FCKSaveCommand = function()
 
153
{
 
154
        this.Name = 'Save' ;
 
155
}
 
156
 
 
157
FCKSaveCommand.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
        // 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' )
 
173
                oForm.submit() ;
 
174
        else
 
175
                oForm.submit.click() ;
 
176
}
 
177
 
 
178
FCKSaveCommand.prototype.GetState = function()
 
179
{
 
180
        return FCK_TRISTATE_OFF ;
 
181
}
 
182
 
 
183
// ### NewPage
 
184
var FCKNewPageCommand = function()
 
185
{
 
186
        this.Name = 'NewPage' ;
 
187
}
 
188
 
 
189
FCKNewPageCommand.prototype.Execute = function()
 
190
{
 
191
        FCKUndo.SaveUndoStep() ;
 
192
        FCK.SetHTML( '' ) ;
 
193
        FCKUndo.Typing = true ;
 
194
}
 
195
 
 
196
FCKNewPageCommand.prototype.GetState = function()
 
197
{
 
198
        return FCK_TRISTATE_OFF ;
 
199
}
 
200
 
 
201
// ### Source button
 
202
var FCKSourceCommand = function()
 
203
{
 
204
        this.Name = 'Source' ;
 
205
}
 
206
 
 
207
FCKSourceCommand.prototype.Execute = function()
 
208
{
 
209
        if ( FCKConfig.SourcePopup )    // Until v2.2, it was mandatory for FCKBrowserInfo.IsGecko.
 
210
        {
 
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 ) ;
 
214
        }
 
215
        else
 
216
            FCK.SwitchEditMode() ;
 
217
}
 
218
 
 
219
FCKSourceCommand.prototype.GetState = function()
 
220
{
 
221
        return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_ON ) ;
 
222
}
 
223
 
 
224
// ### Undo
 
225
var FCKUndoCommand = function()
 
226
{
 
227
        this.Name = 'Undo' ;
 
228
}
 
229
 
 
230
FCKUndoCommand.prototype.Execute = function()
 
231
{
 
232
        if ( FCKBrowserInfo.IsIE )
 
233
                FCKUndo.Undo() ;
 
234
        else
 
235
                FCK.ExecuteNamedCommand( 'Undo' ) ;
 
236
}
 
237
 
 
238
FCKUndoCommand.prototype.GetState = function()
 
239
{
 
240
        if ( FCKBrowserInfo.IsIE )
 
241
                return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
 
242
        else
 
243
                return FCK.GetNamedCommandState( 'Undo' ) ;
 
244
}
 
245
 
 
246
// ### Redo
 
247
var FCKRedoCommand = function()
 
248
{
 
249
        this.Name = 'Redo' ;
 
250
}
 
251
 
 
252
FCKRedoCommand.prototype.Execute = function()
 
253
{
 
254
        if ( FCKBrowserInfo.IsIE )
 
255
                FCKUndo.Redo() ;
 
256
        else
 
257
                FCK.ExecuteNamedCommand( 'Redo' ) ;
 
258
}
 
259
 
 
260
FCKRedoCommand.prototype.GetState = function()
 
261
{
 
262
        if ( FCKBrowserInfo.IsIE )
 
263
                return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
 
264
        else
 
265
                return FCK.GetNamedCommandState( 'Redo' ) ;
 
266
}
 
267
 
 
268
// ### Page Break
 
269
var FCKPageBreakCommand = function()
 
270
{
 
271
        this.Name = 'PageBreak' ;
 
272
}
 
273
 
 
274
FCKPageBreakCommand.prototype.Execute = function()
 
275
{
 
276
//      var e = FCK.EditorDocument.createElement( 'CENTER' ) ;
 
277
//      e.style.pageBreakAfter = 'always' ;
 
278
 
 
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">&nbsp;</span>' ;
 
284
 
 
285
        var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', e ) ;
 
286
        oFakeImage      = FCK.InsertElement( oFakeImage ) ;
 
287
}
 
288
 
 
289
FCKPageBreakCommand.prototype.GetState = function()
 
290
{
 
291
        return 0 ; // FCK_TRISTATE_OFF
 
292
}
 
293
 
 
294
// FCKUnlinkCommand - by Johnny Egeland (johnny@coretrek.com)
 
295
var FCKUnlinkCommand = function()
 
296
{
 
297
        this.Name = 'Unlink' ;
 
298
}
 
299
 
 
300
FCKUnlinkCommand.prototype.Execute = function()
 
301
{
 
302
        if ( FCKBrowserInfo.IsGecko )
 
303
        {
 
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
 
306
                if ( oLink )
 
307
                        FCKTools.RemoveOuterTags( oLink ) ;
 
308
 
 
309
                return ;
 
310
        }
 
311
        
 
312
        FCK.ExecuteNamedCommand( this.Name ) ;
 
313
}
 
314
 
 
315
FCKUnlinkCommand.prototype.GetState = function()
 
316
{
 
317
        var state = FCK.GetNamedCommandState( this.Name ) ;
 
318
 
 
319
        // Check that it isn't an anchor
 
320
        if ( state == FCK_TRISTATE_OFF && FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
321
        {
 
322
                var oLink = FCKSelection.MoveToAncestorNode( 'A' ) ;
 
323
                var bIsAnchor = ( oLink && oLink.name.length > 0 && oLink.href.length == 0 ) ;
 
324
                if ( bIsAnchor )
 
325
                        state = FCK_TRISTATE_DISABLED ;
 
326
        }
 
327
 
 
328
        return state ;
 
329
}
 
330
 
 
331
// FCKSelectAllCommand
 
332
var FCKSelectAllCommand = function()
 
333
{
 
334
        this.Name = 'SelectAll' ;
 
335
}
 
336
 
 
337
FCKSelectAllCommand.prototype.Execute = function()
 
338
{
 
339
        if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
340
        {
 
341
                FCK.ExecuteNamedCommand( 'SelectAll' ) ;
 
342
        }
 
343
        else
 
344
        {
 
345
                // Select the contents of the textarea
 
346
                var textarea = FCK.EditingArea.Textarea ;
 
347
                if ( FCKBrowserInfo.IsIE )
 
348
                {
 
349
                        textarea.createTextRange().execCommand( 'SelectAll' ) ;
 
350
                }
 
351
                else
 
352
                {
 
353
                        textarea.selectionStart = 0;
 
354
                        textarea.selectionEnd = textarea.value.length ;
 
355
                }
 
356
                textarea.focus() ;
 
357
        }
 
358
}
 
359
 
 
360
FCKSelectAllCommand.prototype.GetState = function()
 
361
{
 
362
        return FCK_TRISTATE_OFF ;
 
363
}
 
364
 
 
365
// FCKPasteCommand
 
366
var FCKPasteCommand = function()
 
367
{
 
368
        this.Name = 'Paste' ;
 
369
}
 
370
 
 
371
FCKPasteCommand.prototype =
 
372
{
 
373
        Execute : function()
 
374
        {
 
375
                if ( FCKBrowserInfo.IsIE )
 
376
                        FCK.Paste() ;
 
377
                else
 
378
                        FCK.ExecuteNamedCommand( 'Paste' ) ;
 
379
        },
 
380
 
 
381
        GetState : function()
 
382
        {
 
383
                return FCK.GetNamedCommandState( 'Paste' ) ;
 
384
        }
 
385
} ;