2
* FCKeditor - The text editor for internet
3
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
5
* Licensed under the terms of the GNU Lesser General Public License:
6
* http://www.opensource.org/licenses/lgpl-license.php
8
* For further information visit:
9
* http://www.fckeditor.net/
11
* "Support Open Source software. What about a donation today?"
14
* This is the first part of the "FCK" object creation. This is the main
15
* object that represents an editor instance.
18
* Frederico Caldeira Knabben (fredck@fckeditor.net)
21
var FCK_StartupValue ;
23
FCK.Events = new FCKEvents( FCK ) ;
26
FCK.TempBaseTag = FCKConfig.BaseHref.length > 0 ? '<base href="' + FCKConfig.BaseHref + '" _fcktemp="true"></base>' : '' ;
28
FCK.StartEditor = function()
30
// Get the editor's window and document (DOM)
31
this.EditorWindow = window.frames[ 'eEditorArea' ] ;
32
this.EditorDocument = this.EditorWindow.document ;
34
// TODO: Wait stable version and remove the following commented lines.
35
// The Base Path of the editor is saved to rebuild relative URL (IE issue).
36
// this.BaseUrl = this.EditorDocument.location.protocol + '//' + this.EditorDocument.location.host ;
38
// if ( FCKBrowserInfo.IsGecko )
39
// this.MakeEditable() ;
41
// Set the editor's startup contents
42
this.SetHTML( FCKTools.GetLinkedFieldValue() ) ;
44
// Save the startup value for the "IsDirty()" check.
47
// Attach the editor to the form onsubmit event
48
FCKTools.AttachToLinkedFieldFormSubmit( this.UpdateLinkedField ) ;
50
FCKUndo.SaveUndoStep() ;
52
this.SetStatus( FCK_STATUS_ACTIVE ) ;
55
function Window_OnFocus()
58
FCK.Events.FireEvent( "OnFocus" ) ;
61
function Window_OnBlur()
63
if ( !FCKDialog.IsOpened )
64
return FCK.Events.FireEvent( "OnBlur" ) ;
67
FCK.SetStatus = function( newStatus )
69
this.Status = newStatus ;
71
if ( newStatus == FCK_STATUS_ACTIVE )
73
// Force the focus in the window to go to the editor.
74
window.frameElement.onfocus = window.document.body.onfocus = Window_OnFocus ;
75
window.frameElement.onblur = Window_OnBlur ;
77
// Force the focus in the editor.
78
if ( FCKConfig.StartupFocus )
81
// @Packager.Compactor.Remove.Start
82
var sBrowserSuffix = FCKBrowserInfo.IsIE ? "ie" : "gecko" ;
84
FCKScriptLoader.AddScript( '_source/internals/fck_2.js' ) ;
85
FCKScriptLoader.AddScript( '_source/internals/fck_2_' + sBrowserSuffix + '.js' ) ;
86
FCKScriptLoader.AddScript( '_source/internals/fckselection.js' ) ;
87
FCKScriptLoader.AddScript( '_source/internals/fckselection_' + sBrowserSuffix + '.js' ) ;
88
FCKScriptLoader.AddScript( '_source/classes/fckpanel_' + sBrowserSuffix + '.js' ) ;
89
FCKScriptLoader.AddScript( '_source/internals/fcktablehandler.js' ) ;
90
FCKScriptLoader.AddScript( '_source/internals/fcktablehandler_' + sBrowserSuffix + '.js' ) ;
91
FCKScriptLoader.AddScript( '_source/classes/fckxml_' + sBrowserSuffix + '.js' ) ;
92
FCKScriptLoader.AddScript( '_source/classes/fckstyledef.js' ) ;
93
FCKScriptLoader.AddScript( '_source/classes/fckstyledef_' + sBrowserSuffix + '.js' ) ;
94
FCKScriptLoader.AddScript( '_source/classes/fckstylesloader.js' ) ;
96
FCKScriptLoader.AddScript( '_source/commandclasses/fcknamedcommand.js' ) ;
97
FCKScriptLoader.AddScript( '_source/commandclasses/fck_othercommands.js' ) ;
98
FCKScriptLoader.AddScript( '_source/commandclasses/fckspellcheckcommand_' + sBrowserSuffix + '.js' ) ;
99
FCKScriptLoader.AddScript( '_source/commandclasses/fcktextcolorcommand.js' ) ;
100
FCKScriptLoader.AddScript( '_source/commandclasses/fckpasteplaintextcommand.js' ) ;
101
FCKScriptLoader.AddScript( '_source/commandclasses/fckpastewordcommand.js' ) ;
102
FCKScriptLoader.AddScript( '_source/commandclasses/fcktablecommand.js' ) ;
103
FCKScriptLoader.AddScript( '_source/commandclasses/fckstylecommand.js' ) ;
105
FCKScriptLoader.AddScript( '_source/internals/fckcommands.js' ) ;
106
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarbutton.js' ) ;
107
FCKScriptLoader.AddScript( '_source/classes/fckspecialcombo.js' ) ;
108
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarspecialcombo.js' ) ;
109
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarfontscombo.js' ) ;
110
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarfontsizecombo.js' ) ;
111
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarfontformatcombo.js' ) ;
112
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarstylecombo.js' ) ;
113
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarpanelbutton.js' ) ;
114
FCKScriptLoader.AddScript( '_source/internals/fcktoolbaritems.js' ) ;
115
FCKScriptLoader.AddScript( '_source/classes/fcktoolbar.js' ) ;
116
FCKScriptLoader.AddScript( '_source/classes/fcktoolbarbreak_' + sBrowserSuffix + '.js' ) ;
117
FCKScriptLoader.AddScript( '_source/internals/fcktoolbarset.js' ) ;
118
FCKScriptLoader.AddScript( '_source/internals/fckdialog.js' ) ;
119
FCKScriptLoader.AddScript( '_source/internals/fckdialog_' + sBrowserSuffix + '.js' ) ;
120
FCKScriptLoader.AddScript( '_source/classes/fckcontextmenuitem.js' ) ;
121
FCKScriptLoader.AddScript( '_source/classes/fckcontextmenuseparator.js' ) ;
122
FCKScriptLoader.AddScript( '_source/classes/fckcontextmenugroup.js' ) ;
123
FCKScriptLoader.AddScript( '_source/internals/fckcontextmenu.js' ) ;
124
// FCKScriptLoader.AddScript( '_source/internals/fckcontextmenu_' + sBrowserSuffix + '.js' ) ;
125
FCKScriptLoader.AddScript( '_source/classes/fckplugin.js' ) ;
126
FCKScriptLoader.AddScript( '_source/internals/fckplugins.js' ) ;
127
FCKScriptLoader.AddScript( '_source/internals/fck_last.js' ) ;
128
// @Packager.Compactor.Remove.End
130
/* @Packager.Compactor.RemoveLine
132
if ( FCKBrowserInfo.IsIE )
133
FCKScriptLoader.AddScript( 'js/fckeditorcode_ie_2.js' ) ;
135
FCKScriptLoader.AddScript( 'js/fckeditorcode_gecko_2.js' ) ;
137
@Packager.Compactor.RemoveLine */
140
this.Events.FireEvent( 'OnStatusChange', newStatus ) ;
143
// Deprecated : returns the same value as GetXHTML.
144
FCK.GetHTML = function( format )
146
FCK.GetXHTML( format ) ;
150
if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
152
// TODO: Wait stable version and remove the following commented lines.
153
// if ( FCKBrowserInfo.IsIE )
154
// FCK.CheckRelativeLinks() ;
156
if ( FCKBrowserInfo.IsIE )
157
sHTML = this.EditorDocument.body.innerHTML.replace( FCKRegexLib.ToReplace, '$1' ) ;
159
sHTML = this.EditorDocument.body.innerHTML ;
162
sHTML = document.getElementById('eSourceField').value ;
165
return FCKCodeFormatter.Format( sHTML ) ;
171
FCK.GetXHTML = function( format )
173
var bSource = ( FCK.EditMode == FCK_EDITMODE_SOURCE ) ;
176
this.SwitchEditMode() ;
180
if ( FCKConfig.FullPage )
181
sXHTML = FCKXHtml.GetXHTML( this.EditorDocument.getElementsByTagName( 'html' )[0], true, format ) ;
184
if ( FCKConfig.IgnoreEmptyParagraphValue && this.EditorDocument.body.innerHTML == '<P> </P>' )
187
sXHTML = FCKXHtml.GetXHTML( this.EditorDocument.body, false, format ) ;
191
this.SwitchEditMode() ;
193
if ( FCKBrowserInfo.IsIE )
194
sXHTML = sXHTML.replace( FCKRegexLib.ToReplace, '$1' ) ;
196
if ( FCK.DocTypeDeclaration && FCK.DocTypeDeclaration.length > 0 )
197
sXHTML = FCK.DocTypeDeclaration + '\n' + sXHTML ;
199
if ( FCK.XmlDeclaration && FCK.XmlDeclaration.length > 0 )
200
sXHTML = FCK.XmlDeclaration + '\n' + sXHTML ;
202
return FCKConfig.ProtectedSource.Revert( sXHTML ) ;
205
FCK.UpdateLinkedField = function()
207
// EnableXHTML has been deprecated
208
// if ( FCKConfig.EnableXHTML )
209
FCK.LinkedField.value = FCK.GetXHTML( FCKConfig.FormatOutput ) ;
211
// FCK.LinkedField.value = FCK.GetHTML( FCKConfig.FormatOutput ) ;
213
FCK.Events.FireEvent( 'OnAfterLinkedFieldUpdate' ) ;
216
FCK.ShowContextMenu = function( x, y )
218
if ( this.Status != FCK_STATUS_COMPLETE )
221
FCKContextMenu.Show( x, y ) ;
222
this.Events.FireEvent( "OnContextMenu" ) ;
225
FCK.RegisteredDoubleClickHandlers = new Object() ;
227
FCK.OnDoubleClick = function( element )
229
var oHandler = FCK.RegisteredDoubleClickHandlers[ element.tagName ] ;
231
oHandler( element ) ;
234
// Register objects that can handle double click operations.
235
FCK.RegisterDoubleClickHandler = function( handlerFunction, tag )
237
FCK.RegisteredDoubleClickHandlers[ tag.toUpperCase() ] = handlerFunction ;
240
FCK.OnAfterSetHTML = function()
242
var oProcessor, i = 0 ;
243
while( ( oProcessor = FCKDocumentProcessors[i++] ) )
244
oProcessor.ProcessDocument( FCK.EditorDocument ) ;
246
this.Events.FireEvent( 'OnAfterSetHTML' ) ;
249
// Saves URLs on links and images on special attributes, so they don't change when
251
FCK.ProtectUrls = function( html )
254
html = html.replace( FCKRegexLib.ProtectUrlsAApo , '$1$2$3$2 _fcksavedurl=$2$3$2' ) ;
255
html = html.replace( FCKRegexLib.ProtectUrlsANoApo , '$1$2 _fcksavedurl="$2"' ) ;
258
html = html.replace( FCKRegexLib.ProtectUrlsImgApo , '$1$2$3$2 _fcksavedurl=$2$3$2' ) ;
259
html = html.replace( FCKRegexLib.ProtectUrlsImgNoApo, '$1$2 _fcksavedurl="$2"' ) ;
264
FCK.IsDirty = function()
266
return ( FCK_StartupValue != FCK.EditorDocument.body.innerHTML ) ;
269
FCK.ResetIsDirty = function()
271
if ( FCK.EditorDocument.body )
272
FCK_StartupValue = FCK.EditorDocument.body.innerHTML ;
275
// Advanced document processors.
277
var FCKDocumentProcessors = new Array() ;
279
var FCKDocumentProcessors_CreateFakeImage = function( fakeClass, realElement )
281
var oImg = FCK.EditorDocument.createElement( 'IMG' ) ;
282
oImg.className = fakeClass ;
283
oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ;
284
oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
285
oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
290
var FCKAnchorsProcessor = new Object() ;
291
FCKAnchorsProcessor.ProcessDocument = function( document )
293
var aLinks = document.getElementsByTagName( 'A' ) ;
296
var i = aLinks.length - 1 ;
297
while ( i >= 0 && ( oLink = aLinks[i--] ) )
300
if ( oLink.name.length > 0 && ( !oLink.getAttribute('href') || oLink.getAttribute('href').length == 0 ) )
302
var oImg = FCKDocumentProcessors_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ;
303
oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
305
oLink.parentNode.insertBefore( oImg, oLink ) ;
306
oLink.parentNode.removeChild( oLink ) ;
311
FCKDocumentProcessors.addItem( FCKAnchorsProcessor ) ;
314
var FCKPageBreaksProcessor = new Object() ;
315
FCKPageBreaksProcessor.ProcessDocument = function( document )
317
var aDIVs = document.getElementsByTagName( 'DIV' ) ;
320
var i = aDIVs.length - 1 ;
321
while ( i >= 0 && ( eDIV = aDIVs[i--] ) )
323
if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' )
325
var oFakeImage = FCKDocumentProcessors_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ;
327
eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ;
328
eDIV.parentNode.removeChild( eDIV ) ;
332
var aCenters = document.getElementsByTagName( 'CENTER' ) ;
335
var i = aCenters.length - 1 ;
336
while ( i >= 0 && ( oCenter = aCenters[i--] ) )
338
if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.trim().length == 0 )
340
var oFakeImage = FCKDocumentProcessors_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ;
342
oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ;
343
oCenter.parentNode.removeChild( oCenter ) ;
349
FCKDocumentProcessors.addItem( FCKPageBreaksProcessor ) ;
352
var FCKFlashProcessor = new Object() ;
353
FCKFlashProcessor.ProcessDocument = function( document )
357
This is some <embed src="/UserFiles/Flash/Yellow_Runners.swf"></embed><strong>sample text</strong>. You are <a name="fred"></a> using <a href="http://www.fckeditor.net/">FCKeditor</a>.
360
var aEmbeds = document.getElementsByTagName( 'EMBED' ) ;
363
var i = aEmbeds.length - 1 ;
364
while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) )
366
if ( oEmbed.src.endsWith( '.swf', true ) )
368
var oCloned = oEmbed.cloneNode( true ) ;
370
// On IE, some properties are not getting clonned properly, so we
371
// must fix it. Thanks to Alfonso Martinez.
372
if ( FCKBrowserInfo.IsIE )
374
oCloned.setAttribute( 'scale', oEmbed.getAttribute( 'scale' ) );
375
oCloned.setAttribute( 'play', oEmbed.getAttribute( 'play' ) );
376
oCloned.setAttribute( 'loop', oEmbed.getAttribute( 'loop' ) );
377
oCloned.setAttribute( 'menu', oEmbed.getAttribute( 'menu' ) );
380
var oImg = FCKDocumentProcessors_CreateFakeImage( 'FCK__Flash', oCloned ) ;
381
oImg.setAttribute( '_fckflash', 'true', 0 ) ;
383
FCKFlashProcessor.RefreshView( oImg, oEmbed ) ;
385
oEmbed.parentNode.insertBefore( oImg, oEmbed ) ;
386
oEmbed.parentNode.removeChild( oEmbed ) ;
388
// oEmbed.setAttribute( '_fckdelete', 'true', 0) ;
389
// oEmbed.style.display = 'none' ;
390
// oEmbed.hidden = true ;
395
FCKFlashProcessor.RefreshView = function( placholderImage, originalEmbed )
397
if ( originalEmbed.width > 0 )
398
placholderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.width ) ;
400
if ( originalEmbed.height > 0 )
401
placholderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.height ) ;
404
FCKDocumentProcessors.addItem( FCKFlashProcessor ) ;
406
FCK.GetRealElement = function( fakeElement )
408
var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ;
410
if ( fakeElement.getAttribute('_fckflash') )
412
if ( fakeElement.style.width.length > 0 )
413
e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ;
415
if ( fakeElement.style.height.length > 0 )
416
e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ;
422
// START iCM MODIFICATIONS
424
var FCKTablesProcessor = new Object() ;
425
FCKTablesProcessor.ProcessDocument = function( document )
427
FCKTablesProcessor.CheckTablesNesting( document ) ;
430
// Ensure that tables are not incorrectly nested within P, H1, H2, etc tags
431
FCKTablesProcessor.CheckTablesNesting = function( document )
433
var aTables = document.getElementsByTagName( "TABLE" ) ;
436
for ( var i=0; i<aTables.length; i++ )
438
FCKTablesProcessor.CheckTableNesting( aTables[i] ) ;
442
// Corrects nesting of the supplied table as necessary.
443
// Also called by fck_table.html to check that a newly inserted table is correctly nested.
444
FCKTablesProcessor.CheckTableNesting = function( oTableNode )
446
var oParentBlockNode = FCKTools.GetParentBlockNode( oTableNode.parentNode ) ;
448
if ( oParentBlockNode && !FCKRegexLib.TableBlockElements.test( oParentBlockNode.nodeName ) )
450
// Create a new tag which holds the content of the child nodes located before the table
451
var oNode1 = FCK.EditorDocument.createElement( oParentBlockNode.tagName ) ;
452
var oFragment1 = FCKTools.GetDocumentFragment( oParentBlockNode, oParentBlockNode.firstChild, oTableNode, true, false, true ) ;
453
oNode1.appendChild( oFragment1 ) ;
454
FCKTools.SetElementAttributes( oNode1, oParentBlockNode.attributes ) ; // Transfer across any class attributes, etc
456
// Create a new tag which holds the content of the child nodes located after the table
457
var oNode2 = FCK.EditorDocument.createElement( oParentBlockNode.tagName );
458
var oFragment2 = FCKTools.GetDocumentFragment( oParentBlockNode, oTableNode, oParentBlockNode.lastChild, false, true, true ) ;
459
oNode2.appendChild( oFragment2 ) ;
460
FCKTools.SetElementAttributes( oNode2, oParentBlockNode.attributes ) ; // Transfer across any class attributes, etc
462
// Create a document fragment that contains the two new elements with the table element inbetween
463
var oNewNode = FCK.EditorDocument.createDocumentFragment() ;
464
if ( !FCKTools.NodeIsEmpty( oNode1 ) )
465
oNewNode.appendChild( oNode1 ) ;
466
oNewNode.appendChild( oTableNode ) ;
467
if ( !FCKTools.NodeIsEmpty( oNode2 ) )
468
oNewNode.appendChild( oNode2 ) ;
470
// Replace the existing parent node with the nodes in the fragment
471
oParentBlockNode.parentNode.replaceChild( oNewNode, oParentBlockNode ) ;
475
FCKDocumentProcessors.addItem( FCKTablesProcessor ) ;
477
// END iCM MODIFICATIONS
b'\\ No newline at end of file'