2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Advanced document processors.
24
var FCKDocumentProcessor = new Object() ;
25
FCKDocumentProcessor._Items = new Array() ;
27
FCKDocumentProcessor.AppendNew = function()
29
var oNewItem = new Object() ;
30
this._Items.AddItem( oNewItem ) ;
34
FCKDocumentProcessor.Process = function( document )
36
var bIsDirty = FCK.IsDirty() ;
37
var oProcessor, i = 0 ;
38
while( ( oProcessor = this._Items[i++] ) )
39
oProcessor.ProcessDocument( document ) ;
44
var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
46
var oImg = FCKTools.GetElementDocument( realElement ).createElement( 'IMG' ) ;
47
oImg.className = fakeClass ;
48
oImg.src = FCKConfig.BasePath + 'images/spacer.gif' ;
49
oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
50
oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
55
if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
57
var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ;
58
FCKAnchorsProcessor.ProcessDocument = function( document )
60
var aLinks = document.getElementsByTagName( 'A' ) ;
63
var i = aLinks.length - 1 ;
64
while ( i >= 0 && ( oLink = aLinks[i--] ) )
66
// If it is anchor. Doesn't matter if it's also a link (even better: we show that it's both a link and an anchor)
67
if ( oLink.name.length > 0 )
69
//if the anchor has some content then we just add a temporary class
70
if ( oLink.innerHTML !== '' )
72
if ( FCKBrowserInfo.IsIE )
73
oLink.className += ' FCK__AnchorC' ;
77
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ;
78
oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
80
oLink.parentNode.insertBefore( oImg, oLink ) ;
81
oLink.parentNode.removeChild( oLink ) ;
89
var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ;
90
FCKPageBreaksProcessor.ProcessDocument = function( document )
92
var aDIVs = document.getElementsByTagName( 'DIV' ) ;
95
var i = aDIVs.length - 1 ;
96
while ( i >= 0 && ( eDIV = aDIVs[i--] ) )
98
if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' )
100
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ;
102
eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ;
103
eDIV.parentNode.removeChild( eDIV ) ;
107
var aCenters = document.getElementsByTagName( 'CENTER' ) ;
110
var i = aCenters.length - 1 ;
111
while ( i >= 0 && ( oCenter = aCenters[i--] ) )
113
if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.Trim().length == 0 )
115
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ;
117
oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ;
118
oCenter.parentNode.removeChild( oCenter ) ;
124
// EMBED and OBJECT tags.
125
FCKEmbedAndObjectProcessor = (function()
127
var customProcessors = [] ;
129
var processElement = function( el )
131
var clone = el.cloneNode( true ) ;
133
var fakeImg = replaceElement = FCKDocumentProcessor_CreateFakeImage( 'FCK__UnknownObject', clone ) ;
134
FCKEmbedAndObjectProcessor.RefreshView( fakeImg, el ) ;
136
for ( var i = 0 ; i < customProcessors.length ; i++ )
137
replaceElement = customProcessors[i]( el, replaceElement ) || replaceElement ;
139
if ( replaceElement != fakeImg )
140
FCKTempBin.RemoveElement( fakeImg.getAttribute( '_fckrealelement' ) ) ;
142
el.parentNode.replaceChild( replaceElement, el ) ;
145
var processElementsByName = function( elementName, doc )
147
var aObjects = doc.getElementsByTagName( elementName );
148
for ( var i = aObjects.length - 1 ; i >= 0 ; i-- )
149
processElement( aObjects[i] ) ;
152
var processObjectAndEmbed = function( doc )
154
processElementsByName( 'object', doc );
155
processElementsByName( 'embed', doc );
158
return FCKTools.Merge( FCKDocumentProcessor.AppendNew(),
160
ProcessDocument : function( doc )
162
// Firefox 3 would sometimes throw an unknown exception while accessing EMBEDs and OBJECTs
163
// without the setTimeout().
164
if ( FCKBrowserInfo.IsGecko )
165
FCKTools.RunFunction( processObjectAndEmbed, this, [ doc ] ) ;
167
processObjectAndEmbed( doc ) ;
170
RefreshView : function( placeHolder, original )
172
if ( original.getAttribute( 'width' ) > 0 )
173
placeHolder.style.width = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'width' ) ) ;
175
if ( original.getAttribute( 'height' ) > 0 )
176
placeHolder.style.height = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'height' ) ) ;
179
AddCustomHandler : function( func )
181
customProcessors.push( func ) ;
186
FCK.GetRealElement = function( fakeElement )
188
var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ;
190
if ( fakeElement.getAttribute('_fckflash') )
192
if ( fakeElement.style.width.length > 0 )
193
e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ;
195
if ( fakeElement.style.height.length > 0 )
196
e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ;
203
// This is a IE only (tricky) thing. We protect all HR tags before loading them
204
// (see FCK.ProtectTags). Here we put the HRs back.
205
if ( FCKBrowserInfo.IsIE )
207
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
209
var aHRs = document.getElementsByTagName( 'HR' ) ;
212
var i = aHRs.length - 1 ;
213
while ( i >= 0 && ( eHR = aHRs[i--] ) )
215
// Create the replacement HR.
216
var newHR = document.createElement( 'hr' ) ;
217
newHR.mergeAttributes( eHR, true ) ;
219
// We must insert the new one after it. insertBefore will not work in all cases.
220
FCKDomTools.InsertAfterNode( eHR, newHR ) ;
222
eHR.parentNode.removeChild( eHR ) ;
227
// INPUT:hidden Processor.
228
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
230
var aInputs = document.getElementsByTagName( 'INPUT' ) ;
233
var i = aInputs.length - 1 ;
234
while ( i >= 0 && ( oInput = aInputs[i--] ) )
236
if ( oInput.type == 'hidden' )
238
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oInput.cloneNode(true) ) ;
239
oImg.setAttribute( '_fckinputhidden', 'true', 0 ) ;
241
oInput.parentNode.insertBefore( oImg, oInput ) ;
242
oInput.parentNode.removeChild( oInput ) ;
248
FCKEmbedAndObjectProcessor.AddCustomHandler( function( el, fakeImg )
250
if ( ! ( el.nodeName.IEquals( 'embed' ) && ( el.type == 'application/x-shockwave-flash' || /\.swf($|#|\?)/i.test( el.src ) ) ) )
252
fakeImg.className = 'FCK__Flash' ;
253
fakeImg.setAttribute( '_fckflash', 'true', 0 );
256
// Buggy <span class="Apple-style-span"> tags added by Safari.
257
if ( FCKBrowserInfo.IsSafari )
259
FCKDocumentProcessor.AppendNew().ProcessDocument = function( doc )
261
var spans = doc.getElementsByClassName ?
262
doc.getElementsByClassName( 'Apple-style-span' ) :
263
Array.prototype.filter.call(
264
doc.getElementsByTagName( 'span' ),
265
function( item ){ return item.className == 'Apple-style-span' ; }
267
for ( var i = spans.length - 1 ; i >= 0 ; i-- )
268
FCKDomTools.RemoveNode( spans[i], true ) ;