source: trunk/admin/inc/FCKeditor/editor/_source/internals/fckdocumentprocessor.js@ 2

Last change on this file since 2 was 2, checked in by root, 15 years ago

importo il progetto

File size: 5.6 KB
Line 
1/*
2 * FCKeditor - The text editor for internet
3 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
4 *
5 * Licensed under the terms of the GNU Lesser General Public License:
6 * http://www.opensource.org/licenses/lgpl-license.php
7 *
8 * For further information visit:
9 * http://www.fckeditor.net/
10 *
11 * "Support Open Source software. What about a donation today?"
12 *
13 * File Name: fckdocumentprocessor.js
14 * Advanced document processors.
15 *
16 * File Authors:
17 * Frederico Caldeira Knabben (fredck@fckeditor.net)
18 */
19
20var FCKDocumentProcessor = new Object() ;
21FCKDocumentProcessor._Items = new Array() ;
22
23FCKDocumentProcessor.AppendNew = function()
24{
25 var oNewItem = new Object() ;
26 this._Items.AddItem( oNewItem ) ;
27 return oNewItem ;
28}
29
30FCKDocumentProcessor.Process = function( document )
31{
32 var oProcessor, i = 0 ;
33 while( ( oProcessor = this._Items[i++] ) )
34 oProcessor.ProcessDocument( document ) ;
35}
36
37var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
38{
39 var oImg = FCK.EditorDocument.createElement( 'IMG' ) ;
40 oImg.className = fakeClass ;
41 oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ;
42 oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
43 oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
44 return oImg ;
45}
46
47// Link Anchors
48var FCKAnchorsProcessor = FCKDocumentProcessor.AppendNew() ;
49FCKAnchorsProcessor.ProcessDocument = function( document )
50{
51 var aLinks = document.getElementsByTagName( 'A' ) ;
52
53 var oLink ;
54 var i = aLinks.length - 1 ;
55 while ( i >= 0 && ( oLink = aLinks[i--] ) )
56 {
57 // If it is anchor.
58 if ( oLink.name.length > 0 && ( !oLink.getAttribute('href') || oLink.getAttribute('href').length == 0 ) )
59 {
60 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oLink.cloneNode(true) ) ;
61 oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
62
63 oLink.parentNode.insertBefore( oImg, oLink ) ;
64 oLink.parentNode.removeChild( oLink ) ;
65 }
66 }
67}
68
69// Page Breaks
70var FCKPageBreaksProcessor = FCKDocumentProcessor.AppendNew() ;
71FCKPageBreaksProcessor.ProcessDocument = function( document )
72{
73 var aDIVs = document.getElementsByTagName( 'DIV' ) ;
74
75 var eDIV ;
76 var i = aDIVs.length - 1 ;
77 while ( i >= 0 && ( eDIV = aDIVs[i--] ) )
78 {
79 if ( eDIV.style.pageBreakAfter == 'always' && eDIV.childNodes.length == 1 && eDIV.childNodes[0].style && eDIV.childNodes[0].style.display == 'none' )
80 {
81 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', eDIV.cloneNode(true) ) ;
82
83 eDIV.parentNode.insertBefore( oFakeImage, eDIV ) ;
84 eDIV.parentNode.removeChild( eDIV ) ;
85 }
86 }
87/*
88 var aCenters = document.getElementsByTagName( 'CENTER' ) ;
89
90 var oCenter ;
91 var i = aCenters.length - 1 ;
92 while ( i >= 0 && ( oCenter = aCenters[i--] ) )
93 {
94 if ( oCenter.style.pageBreakAfter == 'always' && oCenter.innerHTML.trim().length == 0 )
95 {
96 var oFakeImage = FCKDocumentProcessor_CreateFakeImage( 'FCK__PageBreak', oCenter.cloneNode(true) ) ;
97
98 oCenter.parentNode.insertBefore( oFakeImage, oCenter ) ;
99 oCenter.parentNode.removeChild( oCenter ) ;
100 }
101 }
102*/
103}
104
105// Flash Embeds.
106var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ;
107FCKFlashProcessor.ProcessDocument = function( document )
108{
109 /*
110 Sample code:
111 This is some <embed src="/UserFiles/Flash/Yellow_Runners.swf"></embed><strong>sample text</strong>. You are&nbsp;<a name="fred"></a> using <a href="http://www.fckeditor.net/">FCKeditor</a>.
112 */
113
114 var aEmbeds = document.getElementsByTagName( 'EMBED' ) ;
115
116 var oEmbed ;
117 var i = aEmbeds.length - 1 ;
118 while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) )
119 {
120 if ( oEmbed.src.endsWith( '.swf', true ) )
121 {
122 var oCloned = oEmbed.cloneNode( true ) ;
123
124 // On IE, some properties are not getting clonned properly, so we
125 // must fix it. Thanks to Alfonso Martinez.
126 if ( FCKBrowserInfo.IsIE )
127 {
128 var oAtt ;
129 if ( oAtt = oEmbed.getAttribute( 'scale' ) ) oCloned.setAttribute( 'scale', oAtt ) ;
130 if ( oAtt = oEmbed.getAttribute( 'play' ) ) oCloned.setAttribute( 'play', oAtt ) ;
131 if ( oAtt = oEmbed.getAttribute( 'loop' ) ) oCloned.setAttribute( 'loop', oAtt ) ;
132 if ( oAtt = oEmbed.getAttribute( 'menu' ) ) oCloned.setAttribute( 'menu', oAtt ) ;
133 if ( oAtt = oEmbed.getAttribute( 'wmode' ) ) oCloned.setAttribute( 'wmode', oAtt ) ;
134 if ( oAtt = oEmbed.getAttribute( 'quality' ) ) oCloned.setAttribute( 'quality', oAtt ) ;
135 }
136
137 var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ;
138 oImg.setAttribute( '_fckflash', 'true', 0 ) ;
139
140 FCKFlashProcessor.RefreshView( oImg, oEmbed ) ;
141
142 oEmbed.parentNode.insertBefore( oImg, oEmbed ) ;
143 oEmbed.parentNode.removeChild( oEmbed ) ;
144
145// oEmbed.setAttribute( '_fcktemp', 'true', 0) ;
146// oEmbed.style.display = 'none' ;
147// oEmbed.hidden = true ;
148 }
149 }
150}
151
152FCKFlashProcessor.RefreshView = function( placholderImage, originalEmbed )
153{
154 if ( originalEmbed.width > 0 )
155 placholderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.width ) ;
156
157 if ( originalEmbed.height > 0 )
158 placholderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.height ) ;
159}
160
161FCK.GetRealElement = function( fakeElement )
162{
163 var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ;
164
165 if ( fakeElement.getAttribute('_fckflash') )
166 {
167 if ( fakeElement.style.width.length > 0 )
168 e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ;
169
170 if ( fakeElement.style.height.length > 0 )
171 e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ;
172 }
173
174 return e ;
175}
Note: See TracBrowser for help on using the repository browser.