source: branches/1.2/workflow/js/fckeditor/editor/_source/internals/fck.js @ 1349

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