~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/internals/fck.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
 * Creation and initialization of the "FCK" object. This is the main object
 
22
 * that represents an editor instance.
 
23
 */
 
24
 
 
25
// FCK represents the active editor instance.
 
26
var FCK =
 
27
{
 
28
        Name            : FCKURLParams[ 'InstanceName' ],
 
29
        Status          : FCK_STATUS_NOTLOADED,
 
30
        EditMode        : FCK_EDITMODE_WYSIWYG,
 
31
        Toolbar         : null,
 
32
        HasFocus        : false,
 
33
 
 
34
        AttachToOnSelectionChange : function( functionPointer )
 
35
        {
 
36
                this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ;
 
37
        },
 
38
 
 
39
        GetLinkedFieldValue : function()
 
40
        {
 
41
                return this.LinkedField.value ;
 
42
        },
 
43
 
 
44
        GetParentForm : function()
 
45
        {
 
46
                return this.LinkedField.form ;
 
47
        } ,
 
48
 
 
49
        // # START : IsDirty implementation
 
50
 
 
51
        StartupValue : '',
 
52
 
 
53
        IsDirty : function()
 
54
        {
 
55
                if ( this.EditMode == FCK_EDITMODE_SOURCE )
 
56
                        return ( this.StartupValue != this.EditingArea.Textarea.value ) ;
 
57
                else
 
58
                        return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
 
59
        },
 
60
 
 
61
        ResetIsDirty : function()
 
62
        {
 
63
                if ( this.EditMode == FCK_EDITMODE_SOURCE )
 
64
                        this.StartupValue = this.EditingArea.Textarea.value ;
 
65
                else if ( this.EditorDocument.body )
 
66
                        this.StartupValue = this.EditorDocument.body.innerHTML ;
 
67
        },
 
68
 
 
69
        // # END : IsDirty implementation
 
70
 
 
71
        StartEditor : function()
 
72
        {
 
73
                this.TempBaseTag = FCKConfig.BaseHref.length > 0 ? '<base href="' + FCKConfig.BaseHref + '" _fcktemp="true"></base>' : '' ;
 
74
 
 
75
                // Setup the keystroke handler.
 
76
                var oKeystrokeHandler = FCK.KeystrokeHandler = new FCKKeystrokeHandler() ;
 
77
                oKeystrokeHandler.OnKeystroke = _FCK_KeystrokeHandler_OnKeystroke ;
 
78
 
 
79
                oKeystrokeHandler.SetKeystrokes( FCKConfig.Keystrokes ) ;
 
80
 
 
81
                // In IE7, if the editor tries to access the clipboard by code, a dialog is
 
82
                // shown to the user asking if the application is allowed to access or not.
 
83
                // Due to the IE implementation of it, the KeystrokeHandler will not work
 
84
                //well in this case, so we must leave the pasting keys to have their default behavior.
 
85
                if ( FCKBrowserInfo.IsIE7 )
 
86
                {
 
87
                        if ( ( CTRL + 86 /*V*/ ) in oKeystrokeHandler.Keystrokes )
 
88
                                oKeystrokeHandler.SetKeystrokes( [ CTRL + 86, true ] ) ;
 
89
 
 
90
                        if ( ( SHIFT + 45 /*INS*/ ) in oKeystrokeHandler.Keystrokes )
 
91
                                oKeystrokeHandler.SetKeystrokes( [ SHIFT + 45, true ] ) ;
 
92
                }
 
93
 
 
94
                this.EditingArea = new FCKEditingArea( document.getElementById( 'xEditingArea' ) ) ;
 
95
                this.EditingArea.FFSpellChecker = FCKConfig.FirefoxSpellChecker ;
 
96
 
 
97
                // Final setup of the lists lib.
 
98
                FCKListsLib.Setup() ;
 
99
 
 
100
                // Set the editor's startup contents
 
101
                this.SetHTML( this.GetLinkedFieldValue(), true ) ;
 
102
        },
 
103
 
 
104
        Focus : function()
 
105
        {
 
106
                FCK.EditingArea.Focus() ;
 
107
        },
 
108
 
 
109
        SetStatus : function( newStatus )
 
110
        {
 
111
                this.Status = newStatus ;
 
112
 
 
113
                if ( newStatus == FCK_STATUS_ACTIVE )
 
114
                {
 
115
                        FCKFocusManager.AddWindow( window, true ) ;
 
116
 
 
117
                        if ( FCKBrowserInfo.IsIE )
 
118
                                FCKFocusManager.AddWindow( window.frameElement, true ) ;
 
119
 
 
120
                        // Force the focus in the editor.
 
121
                        if ( FCKConfig.StartupFocus )
 
122
                                FCK.Focus() ;
 
123
                }
 
124
 
 
125
                this.Events.FireEvent( 'OnStatusChange', newStatus ) ;
 
126
        },
 
127
 
 
128
        // Fixes the body by moving all inline and text nodes to appropriate block
 
129
        // elements.
 
130
        FixBody : function()
 
131
        {
 
132
                var sBlockTag = FCKConfig.EnterMode ;
 
133
 
 
134
                // In 'br' mode, no fix must be done.
 
135
                if ( sBlockTag != 'p' && sBlockTag != 'div' )
 
136
                        return ;
 
137
 
 
138
                var oDocument = this.EditorDocument ;
 
139
 
 
140
                if ( !oDocument )
 
141
                        return ;
 
142
 
 
143
                var oBody = oDocument.body ;
 
144
 
 
145
                if ( !oBody )
 
146
                        return ;
 
147
 
 
148
                FCKDomTools.TrimNode( oBody ) ;
 
149
 
 
150
                var oNode = oBody.firstChild ;
 
151
                var oNewBlock ;
 
152
 
 
153
                while ( oNode )
 
154
                {
 
155
                        var bMoveNode = false ;
 
156
 
 
157
                        switch ( oNode.nodeType )
 
158
                        {
 
159
                                // Element Node.
 
160
                                case 1 :
 
161
                                        if ( !FCKListsLib.BlockElements[ oNode.nodeName.toLowerCase() ] )
 
162
                                                bMoveNode = true ;
 
163
                                        break ;
 
164
 
 
165
                                // Text Node.
 
166
                                case 3 :
 
167
                                        // Ignore space only or empty text.
 
168
                                        if ( oNewBlock || oNode.nodeValue.Trim().length > 0 )
 
169
                                                bMoveNode = true ;
 
170
                        }
 
171
 
 
172
                        if ( bMoveNode )
 
173
                        {
 
174
                                var oParent = oNode.parentNode ;
 
175
 
 
176
                                if ( !oNewBlock )
 
177
                                        oNewBlock = oParent.insertBefore( oDocument.createElement( sBlockTag ), oNode ) ;
 
178
 
 
179
                                oNewBlock.appendChild( oParent.removeChild( oNode ) ) ;
 
180
 
 
181
                                oNode = oNewBlock.nextSibling ;
 
182
                        }
 
183
                        else
 
184
                        {
 
185
                                if ( oNewBlock )
 
186
                                {
 
187
                                        FCKDomTools.TrimNode( oNewBlock ) ;
 
188
                                        oNewBlock = null ;
 
189
                                }
 
190
                                oNode = oNode.nextSibling ;
 
191
                        }
 
192
                }
 
193
 
 
194
                if ( oNewBlock )
 
195
                        FCKDomTools.TrimNode( oNewBlock ) ;
 
196
        },
 
197
 
 
198
        GetXHTML : function( format )
 
199
        {
 
200
                // We assume that if the user is in source editing, the editor value must
 
201
                // represent the exact contents of the source, as the user wanted it to be.
 
202
                if ( FCK.EditMode == FCK_EDITMODE_SOURCE )
 
203
                                return FCK.EditingArea.Textarea.value ;
 
204
 
 
205
                this.FixBody() ;
 
206
 
 
207
                var sXHTML ;
 
208
                var oDoc = FCK.EditorDocument ;
 
209
 
 
210
                if ( !oDoc )
 
211
                        return null ;
 
212
 
 
213
                if ( FCKConfig.FullPage )
 
214
                {
 
215
                        sXHTML = FCKXHtml.GetXHTML( oDoc.getElementsByTagName( 'html' )[0], true, format ) ;
 
216
 
 
217
                        if ( FCK.DocTypeDeclaration && FCK.DocTypeDeclaration.length > 0 )
 
218
                                sXHTML = FCK.DocTypeDeclaration + '\n' + sXHTML ;
 
219
 
 
220
                        if ( FCK.XmlDeclaration && FCK.XmlDeclaration.length > 0 )
 
221
                                sXHTML = FCK.XmlDeclaration + '\n' + sXHTML ;
 
222
                }
 
223
                else
 
224
                {
 
225
                        sXHTML = FCKXHtml.GetXHTML( oDoc.body, false, format ) ;
 
226
 
 
227
                        if ( FCKConfig.IgnoreEmptyParagraphValue && FCKRegexLib.EmptyOutParagraph.test( sXHTML ) )
 
228
                                sXHTML = '' ;
 
229
                }
 
230
 
 
231
                // Restore protected attributes.
 
232
                sXHTML = FCK.ProtectEventsRestore( sXHTML ) ;
 
233
 
 
234
                if ( FCKBrowserInfo.IsIE )
 
235
                        sXHTML = sXHTML.replace( FCKRegexLib.ToReplace, '$1' ) ;
 
236
 
 
237
                return FCKConfig.ProtectedSource.Revert( sXHTML ) ;
 
238
        },
 
239
 
 
240
        UpdateLinkedField : function()
 
241
        {
 
242
                FCK.LinkedField.value = FCK.GetXHTML( FCKConfig.FormatOutput ) ;
 
243
                FCK.Events.FireEvent( 'OnAfterLinkedFieldUpdate' ) ;
 
244
        },
 
245
 
 
246
        RegisteredDoubleClickHandlers : new Object(),
 
247
 
 
248
        OnDoubleClick : function( element )
 
249
        {
 
250
                var oHandler = FCK.RegisteredDoubleClickHandlers[ element.tagName ] ;
 
251
                if ( oHandler )
 
252
                        oHandler( element ) ;
 
253
        },
 
254
 
 
255
        // Register objects that can handle double click operations.
 
256
        RegisterDoubleClickHandler : function( handlerFunction, tag )
 
257
        {
 
258
                FCK.RegisteredDoubleClickHandlers[ tag.toUpperCase() ] = handlerFunction ;
 
259
        },
 
260
 
 
261
        OnAfterSetHTML : function()
 
262
        {
 
263
                FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
 
264
                FCKUndo.SaveUndoStep() ;
 
265
 
 
266
                FCK.Events.FireEvent( 'OnSelectionChange' ) ;
 
267
                FCK.Events.FireEvent( 'OnAfterSetHTML' ) ;
 
268
        },
 
269
 
 
270
        // Saves URLs on links and images on special attributes, so they don't change when
 
271
        // moving around.
 
272
        ProtectUrls : function( html )
 
273
        {
 
274
                // <A> href
 
275
                html = html.replace( FCKRegexLib.ProtectUrlsA   , '$& _fcksavedurl=$1' ) ;
 
276
 
 
277
                // <IMG> src
 
278
                html = html.replace( FCKRegexLib.ProtectUrlsImg , '$& _fcksavedurl=$1' ) ;
 
279
 
 
280
                return html ;
 
281
        },
 
282
 
 
283
        // Saves event attributes (like onclick) so they don't get executed while
 
284
        // editing.
 
285
        ProtectEvents : function( html )
 
286
        {
 
287
                return html.replace( FCKRegexLib.TagsWithEvent, _FCK_ProtectEvents_ReplaceTags ) ;
 
288
        },
 
289
 
 
290
        ProtectEventsRestore : function( html )
 
291
        {
 
292
                return html.replace( FCKRegexLib.ProtectedEvents, _FCK_ProtectEvents_RestoreEvents ) ;
 
293
        },
 
294
 
 
295
        ProtectTags : function( html )
 
296
        {
 
297
                var sTags = FCKConfig.ProtectedTags ;
 
298
 
 
299
                // IE doesn't support <abbr> and it breaks it. Let's protect it.
 
300
                if ( FCKBrowserInfo.IsIE )
 
301
                        sTags += sTags.length > 0 ? '|ABBR|XML' : 'ABBR|XML' ;
 
302
                
 
303
                var oRegex ;
 
304
                if ( sTags.length > 0 )
 
305
                {
 
306
                        oRegex = new RegExp( '<(' + sTags + ')(?!\w|:)', 'gi' ) ;
 
307
                        html = html.replace( oRegex, '<FCK:$1' ) ;
 
308
 
 
309
                        oRegex = new RegExp( '<\/(' + sTags + ')>', 'gi' ) ;
 
310
                        html = html.replace( oRegex, '<\/FCK:$1>' ) ;
 
311
                }
 
312
                
 
313
                // Protect some empty elements. We must do it separately becase the
 
314
                // original tag may not contain the closing slash, like <hr>:
 
315
                //              - <meta> tags get executed, so if you have a redirect meta, the
 
316
                //                content will move to the target page.
 
317
                //              - <hr> may destroy the document structure if not well
 
318
                //                positioned. The trick is protect it here and restore them in
 
319
                //                the FCKDocumentProcessor.
 
320
                sTags = 'META' ;
 
321
                if ( FCKBrowserInfo.IsIE )
 
322
                        sTags += '|HR' ;
 
323
 
 
324
                oRegex = new RegExp( '<((' + sTags + ')(?=\\s|>|/)[\\s\\S]*?)/?>', 'gi' ) ;
 
325
                html = html.replace( oRegex, '<FCK:$1 />' ) ;
 
326
 
 
327
                return html ;
 
328
        },
 
329
 
 
330
        SetHTML : function( html, resetIsDirty )
 
331
        {
 
332
                this.EditingArea.Mode = FCK.EditMode ;
 
333
 
 
334
                if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
335
                {
 
336
                        html = FCKConfig.ProtectedSource.Protect( html ) ;
 
337
 
 
338
                        // Fix for invalid self-closing tags (see #152).
 
339
                        html = html.replace( FCKRegexLib.InvalidSelfCloseTags, '$1></$2>' ) ;
 
340
 
 
341
                        html = FCK.ProtectEvents( html ) ;
 
342
                        html = FCK.ProtectUrls( html ) ;
 
343
                        html = FCK.ProtectTags( html ) ;
 
344
 
 
345
                        // Firefox can't handle correctly the editing of the STRONG and EM tags.
 
346
                        // We must replace them with B and I.
 
347
                        if ( FCKBrowserInfo.IsGecko )
 
348
                        {
 
349
                                html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ;
 
350
                                html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ;
 
351
                                html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
 
352
                                html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
 
353
                        }
 
354
 
 
355
                        this._ForceResetIsDirty = ( resetIsDirty === true ) ;
 
356
 
 
357
                        var sHtml = '' ;
 
358
 
 
359
                        if ( FCKConfig.FullPage )
 
360
                        {
 
361
                                // The HTML must be fixed if the <head> is not available.
 
362
                                if ( !FCKRegexLib.HeadOpener.test( html ) )
 
363
                                {
 
364
                                        // Check if the <html> is available.
 
365
                                        if ( !FCKRegexLib.HtmlOpener.test( html ) )
 
366
                                                html = '<html dir="' + FCKConfig.ContentLangDirection + '">' + html + '</html>' ;
 
367
 
 
368
                                        // Add the <head>.
 
369
                                        html = html.replace( FCKRegexLib.HtmlOpener, '$&<head></head>' ) ;
 
370
                                }
 
371
 
 
372
                                // Save the DOCTYPE.
 
373
                                FCK.DocTypeDeclaration = html.match( FCKRegexLib.DocTypeTag ) ;
 
374
 
 
375
                                if ( FCKBrowserInfo.IsIE )
 
376
                                        sHtml = FCK._GetBehaviorsStyle() ;
 
377
                                else if ( FCKConfig.ShowBorders )
 
378
                                        sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
379
 
 
380
                                sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
381
 
 
382
                                // Attention: do not change it before testing it well (sample07)!
 
383
                                // This is tricky... if the head ends with <meta ... content type>,
 
384
                                // Firefox will break. But, it works if we include the temporary
 
385
                                // links as the last elements in the HEAD.
 
386
                                sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ;
 
387
 
 
388
                                // Insert the base tag (FCKConfig.BaseHref), if not exists in the source.
 
389
                                // The base must be the first tag in the HEAD, to get relative
 
390
                                // links on styles, for example.
 
391
                                if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) )
 
392
                                        sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
 
393
                        }
 
394
                        else
 
395
                        {
 
396
                                sHtml =
 
397
                                        FCKConfig.DocType +
 
398
                                        '<html dir="' + FCKConfig.ContentLangDirection + '"' ;
 
399
 
 
400
                                // On IE, if you are use a DOCTYPE differenft of HTML 4 (like
 
401
                                // XHTML), you must force the vertical scroll to show, otherwise
 
402
                                // the horizontal one may appear when the page needs vertical scrolling.
 
403
                                if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) )
 
404
                                        sHtml += ' style="overflow-y: scroll"' ;
 
405
 
 
406
                                sHtml +=
 
407
                                        '><head><title></title>' +
 
408
                                        _FCK_GetEditorAreaStyleTags() +
 
409
                                        '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
410
 
 
411
                                if ( FCKBrowserInfo.IsIE )
 
412
                                        sHtml += FCK._GetBehaviorsStyle() ;
 
413
                                else if ( FCKConfig.ShowBorders )
 
414
                                        sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 
415
 
 
416
                                sHtml += FCK.TempBaseTag ;
 
417
 
 
418
                                // Add ID and Class to the body
 
419
                                var sBodyTag = '<body' ;
 
420
                                if ( FCKConfig.BodyId && FCKConfig.BodyId.length > 0 )
 
421
                                        sBodyTag += ' id="' + FCKConfig.BodyId + '"' ;
 
422
                                if ( FCKConfig.BodyClass && FCKConfig.BodyClass.length > 0 )
 
423
                                        sBodyTag += ' class="' + FCKConfig.BodyClass + '"' ;
 
424
                                sHtml += '</head>' + sBodyTag + '>' ;
 
425
 
 
426
                                if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) )
 
427
                                        sHtml += GECKO_BOGUS ;
 
428
                                else
 
429
                                        sHtml += html ;
 
430
 
 
431
                                sHtml += '</body></html>' ;
 
432
                        }
 
433
 
 
434
                        this.EditingArea.OnLoad = _FCK_EditingArea_OnLoad ;
 
435
                        this.EditingArea.Start( sHtml ) ;
 
436
                }
 
437
                else
 
438
                {
 
439
                        // Remove the references to the following elements, as the editing area
 
440
                        // IFRAME will be removed.
 
441
                        FCK.EditorWindow        = null ;
 
442
                        FCK.EditorDocument      = null ;
 
443
 
 
444
                        this.EditingArea.OnLoad = null ;
 
445
                        this.EditingArea.Start( html ) ;
 
446
 
 
447
                        // Enables the context menu in the textarea.
 
448
                        this.EditingArea.Textarea._FCKShowContextMenu = true ;
 
449
 
 
450
                        // Removes the enter key handler.
 
451
                        FCK.EnterKeyHandler = null ;
 
452
 
 
453
                        if ( resetIsDirty )
 
454
                                this.ResetIsDirty() ;
 
455
 
 
456
                        // Listen for keystroke events.
 
457
                        FCK.KeystrokeHandler.AttachToElement( this.EditingArea.Textarea ) ;
 
458
 
 
459
                        this.EditingArea.Textarea.focus() ;
 
460
 
 
461
                        FCK.Events.FireEvent( 'OnAfterSetHTML' ) ;
 
462
                }
 
463
 
 
464
                if ( FCKBrowserInfo.IsGecko )
 
465
                        window.onresize() ;
 
466
        },
 
467
 
 
468
        // For the FocusManager
 
469
        HasFocus : false,
 
470
 
 
471
 
 
472
        // This collection is used by the browser specific implementations to tell
 
473
        // wich named commands must be handled separately.
 
474
        RedirectNamedCommands : new Object(),
 
475
 
 
476
        ExecuteNamedCommand : function( commandName, commandParameter, noRedirect )
 
477
        {
 
478
                FCKUndo.SaveUndoStep() ;
 
479
 
 
480
                if ( !noRedirect && FCK.RedirectNamedCommands[ commandName ] != null )
 
481
                        FCK.ExecuteRedirectedNamedCommand( commandName, commandParameter ) ;
 
482
                else
 
483
                {
 
484
                        FCK.Focus() ;
 
485
                        FCK.EditorDocument.execCommand( commandName, false, commandParameter ) ;
 
486
                        FCK.Events.FireEvent( 'OnSelectionChange' ) ;
 
487
                }
 
488
 
 
489
                FCKUndo.SaveUndoStep() ;
 
490
        },
 
491
 
 
492
        GetNamedCommandState : function( commandName )
 
493
        {
 
494
                try
 
495
                {
 
496
 
 
497
                        if ( !FCK.EditorDocument.queryCommandEnabled( commandName ) )
 
498
                                return FCK_TRISTATE_DISABLED ;
 
499
                        else
 
500
                                return FCK.EditorDocument.queryCommandState( commandName ) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ;
 
501
                }
 
502
                catch ( e )
 
503
                {
 
504
                        return FCK_TRISTATE_OFF ;
 
505
                }
 
506
        },
 
507
 
 
508
        GetNamedCommandValue : function( commandName )
 
509
        {
 
510
                var sValue = '' ;
 
511
                var eState = FCK.GetNamedCommandState( commandName ) ;
 
512
 
 
513
                if ( eState == FCK_TRISTATE_DISABLED )
 
514
                        return null ;
 
515
 
 
516
                try
 
517
                {
 
518
                        sValue = this.EditorDocument.queryCommandValue( commandName ) ;
 
519
                }
 
520
                catch(e) {}
 
521
 
 
522
                return sValue ? sValue : '' ;
 
523
        },
 
524
 
 
525
        PasteFromWord : function()
 
526
        {
 
527
                FCKDialog.OpenDialog( 'FCKDialog_Paste', FCKLang.PasteFromWord, 'dialog/fck_paste.html', 400, 330, 'Word' ) ;
 
528
        },
 
529
 
 
530
        Preview : function()
 
531
        {
 
532
                var iWidth      = FCKConfig.ScreenWidth * 0.8 ;
 
533
                var iHeight     = FCKConfig.ScreenHeight * 0.7 ;
 
534
                var iLeft       = ( FCKConfig.ScreenWidth - iWidth ) / 2 ;
 
535
                var oWindow = window.open( '', null, 'toolbar=yes,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft ) ;
 
536
 
 
537
                var sHTML ;
 
538
 
 
539
                if ( FCKConfig.FullPage )
 
540
                {
 
541
                        if ( FCK.TempBaseTag.length > 0 )
 
542
                                sHTML = FCK.TempBaseTag + FCK.GetXHTML() ;
 
543
                        else
 
544
                                sHTML = FCK.GetXHTML() ;
 
545
                }
 
546
                else
 
547
                {
 
548
                        sHTML =
 
549
                                FCKConfig.DocType +
 
550
                                '<html dir="' + FCKConfig.ContentLangDirection + '">' +
 
551
                                '<head>' +
 
552
                                FCK.TempBaseTag +
 
553
                                '<title>' + FCKLang.Preview + '</title>' +
 
554
                                _FCK_GetEditorAreaStyleTags() +
 
555
                                '</head><body>' +
 
556
                                FCK.GetXHTML() +
 
557
                                '</body></html>' ;
 
558
                }
 
559
 
 
560
                oWindow.document.write( sHTML );
 
561
                oWindow.document.close();
 
562
        },
 
563
 
 
564
        SwitchEditMode : function( noUndo )
 
565
        {
 
566
                var bIsWysiwyg = ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) ;
 
567
 
 
568
                // Save the current IsDirty state, so we may restore it after the switch.
 
569
                var bIsDirty = FCK.IsDirty() ;
 
570
 
 
571
                var sHtml ;
 
572
 
 
573
                // Update the HTML in the view output to show.
 
574
                if ( bIsWysiwyg )
 
575
                {
 
576
                        if ( !noUndo && FCKBrowserInfo.IsIE )
 
577
                                FCKUndo.SaveUndoStep() ;
 
578
 
 
579
                        sHtml = FCK.GetXHTML( FCKConfig.FormatSource ) ;
 
580
 
 
581
                        if ( sHtml == null )
 
582
                                return false ;
 
583
                }
 
584
                else
 
585
                        sHtml = this.EditingArea.Textarea.value ;
 
586
 
 
587
                FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ;
 
588
 
 
589
                FCK.SetHTML( sHtml, !bIsDirty ) ;
 
590
 
 
591
                // Set the Focus.
 
592
                FCK.Focus() ;
 
593
 
 
594
                // Update the toolbar (Running it directly causes IE to fail).
 
595
                FCKTools.RunFunction( FCK.ToolbarSet.RefreshModeState, FCK.ToolbarSet ) ;
 
596
 
 
597
                return true ;
 
598
        },
 
599
 
 
600
        CreateElement : function( tag )
 
601
        {
 
602
                var e = FCK.EditorDocument.createElement( tag ) ;
 
603
                return FCK.InsertElementAndGetIt( e ) ;
 
604
        },
 
605
 
 
606
        InsertElementAndGetIt : function( e )
 
607
        {
 
608
                e.setAttribute( 'FCKTempLabel', 'true' ) ;
 
609
 
 
610
                this.InsertElement( e ) ;
 
611
 
 
612
                var aEls = FCK.EditorDocument.getElementsByTagName( e.tagName ) ;
 
613
 
 
614
                for ( var i = 0 ; i < aEls.length ; i++ )
 
615
                {
 
616
                        if ( aEls[i].getAttribute( 'FCKTempLabel' ) )
 
617
                        {
 
618
                                aEls[i].removeAttribute( 'FCKTempLabel' ) ;
 
619
                                return aEls[i] ;
 
620
                        }
 
621
                }
 
622
                return null ;
 
623
        }
 
624
 
 
625
} ;
 
626
 
 
627
FCK.Events      = new FCKEvents( FCK ) ;
 
628
// GetHTML is Deprecated : returns the same value as GetXHTML.
 
629
FCK.GetHTML     = FCK.GetXHTML ;
 
630
 
 
631
// Replace all events attributes (like onclick).
 
632
function _FCK_ProtectEvents_ReplaceTags( tagMatch )
 
633
{
 
634
        return tagMatch.replace( FCKRegexLib.EventAttributes, _FCK_ProtectEvents_ReplaceEvents ) ;
 
635
}
 
636
 
 
637
// Replace an event attribute with its respective __fckprotectedatt attribute.
 
638
// The original event markup will be encoded and saved as the value of the new
 
639
// attribute.
 
640
function _FCK_ProtectEvents_ReplaceEvents( eventMatch, attName )
 
641
{
 
642
        return ' ' + attName + '_fckprotectedatt="' + eventMatch.ReplaceAll( [/&/g,/'/g,/"/g,/=/g,/</g,/>/g,/\r/g,/\n/g], ['&apos;','&#39;','&quot;','&#61;','&lt;','&gt;','&#10;','&#13;'] ) + '"' ;
 
643
}
 
644
 
 
645
function _FCK_ProtectEvents_RestoreEvents( match, encodedOriginal )
 
646
{
 
647
        return encodedOriginal.ReplaceAll( [/&#39;/g,/&quot;/g,/&#61;/g,/&lt;/g,/&gt;/g,/&#10;/g,/&#13;/g,/&apos;/g], ["'",'"','=','<','>','\r','\n','&'] ) ;
 
648
}
 
649
 
 
650
function _FCK_EditingArea_OnLoad()
 
651
{
 
652
        // Get the editor's window and document (DOM)
 
653
        FCK.EditorWindow        = FCK.EditingArea.Window ;
 
654
        FCK.EditorDocument      = FCK.EditingArea.Document ;
 
655
 
 
656
        FCK.InitializeBehaviors() ;
 
657
 
 
658
        // Create the enter key handler
 
659
        if ( !FCKConfig.DisableEnterKeyHandler )
 
660
                FCK.EnterKeyHandler = new FCKEnterKey( FCK.EditorWindow, FCKConfig.EnterMode, FCKConfig.ShiftEnterMode ) ;
 
661
 
 
662
        // Listen for keystroke events.
 
663
        FCK.KeystrokeHandler.AttachToElement( FCK.EditorDocument ) ;
 
664
 
 
665
        if ( FCK._ForceResetIsDirty )
 
666
                FCK.ResetIsDirty() ;
 
667
 
 
668
        // This is a tricky thing for IE. In some cases, even if the cursor is
 
669
        // blinking in the editing, the keystroke handler doesn't catch keyboard
 
670
        // events. We must activate the editing area to make it work. (#142).
 
671
        if ( FCKBrowserInfo.IsIE && FCK.HasFocus )
 
672
                FCK.EditorDocument.body.setActive() ;
 
673
 
 
674
        FCK.OnAfterSetHTML() ;
 
675
 
 
676
        // Check if it is not a startup call, otherwise complete the startup.
 
677
        if ( FCK.Status != FCK_STATUS_NOTLOADED )
 
678
                return ;
 
679
 
 
680
        FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
 
681
}
 
682
 
 
683
function _FCK_GetEditorAreaStyleTags()
 
684
{
 
685
        var sTags = '' ;
 
686
        var aCSSs = FCKConfig.EditorAreaCSS ;
 
687
 
 
688
        for ( var i = 0 ; i < aCSSs.length ; i++ )
 
689
                sTags += '<link href="' + aCSSs[i] + '" rel="stylesheet" type="text/css" />' ;
 
690
 
 
691
        return sTags ;
 
692
}
 
693
 
 
694
function _FCK_KeystrokeHandler_OnKeystroke( keystroke, keystrokeValue )
 
695
{
 
696
        if ( FCK.Status != FCK_STATUS_COMPLETE )
 
697
                return false ;
 
698
 
 
699
        if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 
700
        {
 
701
                if ( keystrokeValue == 'Paste' )
 
702
                        return !FCK.Events.FireEvent( 'OnPaste' ) ;
 
703
        }
 
704
        else
 
705
        {
 
706
                // In source mode, some actions must have their default behavior.
 
707
                if ( keystrokeValue.Equals( 'Paste', 'Undo', 'Redo', 'SelectAll' ) )
 
708
                        return false ;
 
709
        }
 
710
 
 
711
        // The return value indicates if the default behavior of the keystroke must
 
712
        // be cancelled. Let's do that only if the Execute() call explicitelly returns "false".
 
713
        var oCommand = FCK.Commands.GetCommand( keystrokeValue ) ;
 
714
        return ( oCommand.Execute.apply( oCommand, FCKTools.ArgumentsToArray( arguments, 2 ) ) !== false ) ;
 
715
}
 
716
 
 
717
// Set the FCK.LinkedField reference to the field that will be used to post the
 
718
// editor data.
 
719
(function()
 
720
{
 
721
        // There is a bug on IE... getElementById returns any META tag that has the
 
722
        // name set to the ID you are looking for. So the best way in to get the array
 
723
        // by names and look for the correct one.
 
724
        // As ASP.Net generates a ID that is different from the Name, we must also
 
725
        // look for the field based on the ID (the first one is the ID).
 
726
 
 
727
        var oDocument = window.parent.document ;
 
728
 
 
729
        // Try to get the field using the ID.
 
730
        var eLinkedField = oDocument.getElementById( FCK.Name ) ;
 
731
 
 
732
        var i = 0;
 
733
        while ( eLinkedField || i == 0 )
 
734
        {
 
735
                if ( eLinkedField && eLinkedField.tagName.toLowerCase().Equals( 'input', 'textarea' ) )
 
736
                {
 
737
                        FCK.LinkedField = eLinkedField ;
 
738
                        break ;
 
739
                }
 
740
 
 
741
                eLinkedField = oDocument.getElementsByName( FCK.Name )[i++] ;
 
742
        }
 
743
})() ;
 
744
 
 
745
var FCKTempBin =
 
746
{
 
747
        Elements : new Array(),
 
748
 
 
749
        AddElement : function( element )
 
750
        {
 
751
                var iIndex = this.Elements.length ;
 
752
                this.Elements[ iIndex ] = element ;
 
753
                return iIndex ;
 
754
        },
 
755
 
 
756
        RemoveElement : function( index )
 
757
        {
 
758
                var e = this.Elements[ index ] ;
 
759
                this.Elements[ index ] = null ;
 
760
                return e ;
 
761
        },
 
762
 
 
763
        Reset : function()
 
764
        {
 
765
                var i = 0 ;
 
766
                while ( i < this.Elements.length )
 
767
                        this.Elements[ i++ ] = null ;
 
768
                this.Elements.length = 0 ;
 
769
        }
 
770
} ;
 
771
 
 
772
 
 
773
 
 
774
// # Focus Manager: Manages the focus in the editor.
 
775
var FCKFocusManager = FCK.FocusManager =
 
776
{
 
777
        IsLocked : false,
 
778
 
 
779
        AddWindow : function( win, sendToEditingArea )
 
780
        {
 
781
                var oTarget ;
 
782
 
 
783
                if ( FCKBrowserInfo.IsIE )
 
784
                        oTarget = win.nodeType == 1 ? win : win.frameElement ? win.frameElement : win.document ;
 
785
                else
 
786
                        oTarget = win.document ;
 
787
 
 
788
                FCKTools.AddEventListener( oTarget, 'blur', FCKFocusManager_Win_OnBlur ) ;
 
789
                FCKTools.AddEventListener( oTarget, 'focus', sendToEditingArea ? FCKFocusManager_Win_OnFocus_Area : FCKFocusManager_Win_OnFocus ) ;
 
790
        },
 
791
 
 
792
        RemoveWindow : function( win )
 
793
        {
 
794
                if ( FCKBrowserInfo.IsIE )
 
795
                        oTarget = win.nodeType == 1 ? win : win.frameElement ? win.frameElement : win.document ;
 
796
                else
 
797
                        oTarget = win.document ;
 
798
 
 
799
                FCKTools.RemoveEventListener( oTarget, 'blur', FCKFocusManager_Win_OnBlur ) ;
 
800
                FCKTools.RemoveEventListener( oTarget, 'focus', FCKFocusManager_Win_OnFocus_Area ) ;
 
801
                FCKTools.RemoveEventListener( oTarget, 'focus', FCKFocusManager_Win_OnFocus ) ;
 
802
        },
 
803
 
 
804
        Lock : function()
 
805
        {
 
806
                this.IsLocked = true ;
 
807
        },
 
808
 
 
809
        Unlock : function()
 
810
        {
 
811
                if ( this._HasPendingBlur )
 
812
                        FCKFocusManager._Timer = window.setTimeout( FCKFocusManager_FireOnBlur, 100 ) ;
 
813
 
 
814
                this.IsLocked = false ;
 
815
        },
 
816
 
 
817
        _ResetTimer : function()
 
818
        {
 
819
                this._HasPendingBlur = false ;
 
820
 
 
821
                if ( this._Timer )
 
822
                {
 
823
                        window.clearTimeout( this._Timer ) ;
 
824
                        delete this._Timer ;
 
825
                }
 
826
        }
 
827
} ;
 
828
 
 
829
function FCKFocusManager_Win_OnBlur()
 
830
{
 
831
        if ( typeof(FCK) != 'undefined' && FCK.HasFocus )
 
832
        {
 
833
                FCKFocusManager._ResetTimer() ;
 
834
                FCKFocusManager._Timer = window.setTimeout( FCKFocusManager_FireOnBlur, 100 ) ;
 
835
        }
 
836
}
 
837
 
 
838
function FCKFocusManager_FireOnBlur()
 
839
{
 
840
        if ( FCKFocusManager.IsLocked )
 
841
                FCKFocusManager._HasPendingBlur = true ;
 
842
        else
 
843
        {
 
844
                FCK.HasFocus = false ;
 
845
                FCK.Events.FireEvent( "OnBlur" ) ;
 
846
        }
 
847
}
 
848
 
 
849
function FCKFocusManager_Win_OnFocus_Area()
 
850
{
 
851
        FCK.Focus() ;
 
852
        FCKFocusManager_Win_OnFocus() ;
 
853
}
 
854
 
 
855
function FCKFocusManager_Win_OnFocus()
 
856
{
 
857
        FCKFocusManager._ResetTimer() ;
 
858
 
 
859
        if ( !FCK.HasFocus && !FCKFocusManager.IsLocked )
 
860
        {
 
861
                FCK.HasFocus = true ;
 
862
                FCK.Events.FireEvent( "OnFocus" ) ;
 
863
        }
 
864
}