2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 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 oProcessor, i = 0 ;
37
while( ( oProcessor = this._Items[i++] ) )
38
oProcessor.ProcessDocument( document ) ;
41
var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
43
var oImg = FCK.EditorDocument.createElement( 'IMG' ) ;
44
oImg.className = fakeClass ;
45
oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ;
46
oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
47
oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
52
if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
54
var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ;
55
FCKAnchorsProcessor.ProcessDocument = function( document )
57
var aLinks = document.getElementsByTagName( 'A' ) ;
60
var i = aLinks.length - 1 ;
61
while ( i >= 0 && ( oLink = aLinks[i--] ) )
63
// 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)
64
if ( oLink.name.length > 0 )
66
//if the anchor has some content then we just add a temporary class
67
if ( oLink.innerHTML !== '' )
69
if ( FCKBrowserInfo.IsIE )
70
oLink.className += ' FCK__AnchorC' ;
74
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ;
75
oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
77
oLink.parentNode.insertBefore( oImg, oLink ) ;
78
oLink.parentNode.removeChild( oLink ) ;
86
var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ;
87
FCKPageBreaksProcessor.ProcessDocument = function( document )
89
var aDIVs = document.getElementsByTagName( 'DIV' ) ;
92
var i = aDIVs.length - 1 ;
93
while ( i >= 0 && ( eDIV = aDIVs[i--] ) )
95
if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' )
97
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ;
99
eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ;
100
eDIV.parentNode.removeChild( eDIV ) ;
104
var aCenters = document.getElementsByTagName( 'CENTER' ) ;
107
var i = aCenters.length - 1 ;
108
while ( i >= 0 && ( oCenter = aCenters[i--] ) )
110
if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.Trim().length == 0 )
112
var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ;
114
oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ;
115
oCenter.parentNode.removeChild( oCenter ) ;
122
var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ;
123
FCKFlashProcessor.ProcessDocument = function( document )
127
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>.
130
var aEmbeds = document.getElementsByTagName( 'EMBED' ) ;
133
var i = aEmbeds.length - 1 ;
134
while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) )
136
// IE doesn't return the type attribute with oEmbed.type or oEmbed.getAttribute("type")
137
// But it turns out that after accessing it then it doesn't gets copied later
138
var oType = oEmbed.attributes[ 'type' ] ;
140
// Check the extension and the type. Now it should be enough with just the type
141
// Opera doesn't return oEmbed.src so oEmbed.src.EndsWith will fail
142
if ( (oEmbed.src && oEmbed.src.EndsWith( '.swf', true )) || ( oType && oType.nodeValue == 'application/x-shockwave-flash' ) )
144
var oCloned = oEmbed.cloneNode( true ) ;
146
// On IE, some properties are not getting clonned properly, so we
147
// must fix it. Thanks to Alfonso Martinez.
148
if ( FCKBrowserInfo.IsIE )
150
var aAttributes = [ 'scale', 'play', 'loop', 'menu', 'wmode', 'quality' ] ;
151
for ( var iAtt = 0 ; iAtt < aAttributes.length ; iAtt++ )
153
var oAtt = oEmbed.getAttribute( aAttributes[iAtt] ) ;
154
if ( oAtt ) oCloned.setAttribute( aAttributes[iAtt], oAtt ) ;
156
// It magically gets lost after reading it in oType
157
oCloned.setAttribute( 'type', oType.nodeValue ) ;
160
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ;
161
oImg.setAttribute( '_fckflash', 'true', 0 ) ;
163
FCKFlashProcessor.RefreshView( oImg, oEmbed ) ;
165
oEmbed.parentNode.insertBefore( oImg, oEmbed ) ;
166
oEmbed.parentNode.removeChild( oEmbed ) ;
168
// oEmbed.setAttribute( '_fcktemp', 'true', 0) ;
169
// oEmbed.style.display = 'none' ;
170
// oEmbed.hidden = true ;
175
FCKFlashProcessor.RefreshView = function( placeHolderImage, originalEmbed )
177
if ( originalEmbed.getAttribute( 'width' ) > 0 )
178
placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'width' ) ) ;
180
if ( originalEmbed.getAttribute( 'height' ) > 0 )
181
placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'height' ) ) ;
184
FCK.GetRealElement = function( fakeElement )
186
var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ;
188
if ( fakeElement.getAttribute('_fckflash') )
190
if ( fakeElement.style.width.length > 0 )
191
e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ;
193
if ( fakeElement.style.height.length > 0 )
194
e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ;
201
// This is a IE only (tricky) thing. We protect all HR tags before loading them
202
// (see FCK.ProtectTags). Here we put the HRs back.
203
if ( FCKBrowserInfo.IsIE )
205
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
207
var aHRs = document.getElementsByTagName( 'HR' ) ;
210
var i = aHRs.length - 1 ;
211
while ( i >= 0 && ( eHR = aHRs[i--] ) )
213
// Create the replacement HR.
214
var newHR = document.createElement( 'hr' ) ;
215
newHR.mergeAttributes( eHR, true ) ;
217
// We must insert the new one after it. insertBefore will not work in all cases.
218
FCKDomTools.InsertAfterNode( eHR, newHR ) ;
220
eHR.parentNode.removeChild( eHR ) ;
225
// INPUT:hidden Processor.
226
FCKDocumentProcessor.AppendNew().ProcessDocument = function( document )
228
var aInputs = document.getElementsByTagName( 'INPUT' ) ;
231
var i = aInputs.length - 1 ;
232
while ( i >= 0 && ( oInput = aInputs[i--] ) )
234
if ( oInput.type == 'hidden' )
236
var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__InputHidden', oInput.cloneNode(true) ) ;
237
oImg.setAttribute( '_fckinputhidden', 'true', 0 ) ;
239
oInput.parentNode.insertBefore( oImg, oInput ) ;
240
oInput.parentNode.removeChild( oInput ) ;
b'\\ No newline at end of file'