| 121 | | // Flash Embeds. |
| 122 | | var FCKFlashProcessor = FCKDocumentProcessor.AppendNew() ; |
| 123 | | FCKFlashProcessor.ProcessDocument = function( document ) |
| 124 | | { |
| 125 | | /* |
| 126 | | Sample code: |
| 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>. |
| 128 | | */ |
| 129 | | |
| 130 | | var bIsDirty = FCK.IsDirty() ; |
| 131 | | |
| 132 | | var aEmbeds = document.getElementsByTagName( 'EMBED' ) ; |
| 133 | | |
| 134 | | var oEmbed ; |
| 135 | | var i = aEmbeds.length - 1 ; |
| 136 | | while ( i >= 0 && ( oEmbed = aEmbeds[i--] ) ) |
| 137 | | { |
| 138 | | // IE doesn't return the type attribute with oEmbed.type or oEmbed.getAttribute("type") |
| 139 | | // But it turns out that after accessing it then it doesn't gets copied later |
| 140 | | var oType = oEmbed.attributes[ 'type' ] ; |
| 141 | | |
| 142 | | // Check the extension and the type. Now it should be enough with just the type |
| 143 | | // Opera doesn't return oEmbed.src so oEmbed.src.EndsWith will fail |
| 144 | | if ( (oEmbed.src && oEmbed.src.EndsWith( '.swf', true )) || ( oType && oType.nodeValue == 'application/x-shockwave-flash' ) ) |
| 145 | | { |
| 146 | | var oCloned = oEmbed.cloneNode( true ) ; |
| 147 | | |
| 148 | | var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oCloned ) ; |
| 149 | | oImg.setAttribute( '_fckflash', 'true', 0 ) ; |
| 150 | | |
| 151 | | FCKFlashProcessor.RefreshView( oImg, oEmbed ) ; |
| 152 | | |
| 153 | | oEmbed.parentNode.insertBefore( oImg, oEmbed ) ; |
| 154 | | oEmbed.parentNode.removeChild( oEmbed ) ; |
| 155 | | } |
| 156 | | } |
| 157 | | |
| 158 | | // Fix the IsDirty state (#1406). |
| 159 | | if ( !bIsDirty ) |
| 160 | | FCK.ResetIsDirty() ; |
| 161 | | } |
| 162 | | |
| 163 | | FCKFlashProcessor.RefreshView = function( placeHolderImage, originalEmbed ) |
| 164 | | { |
| 165 | | if ( originalEmbed.getAttribute( 'width' ) > 0 ) |
| 166 | | placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'width' ) ) ; |
| 167 | | |
| 168 | | if ( originalEmbed.getAttribute( 'height' ) > 0 ) |
| 169 | | placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'height' ) ) ; |
| | 121 | // EMBED and OBJECT tags. |
| | 122 | var FCKEmbedAndObjectProcessor = FCKDocumentProcessor.AppendNew() ; |
| | 123 | FCKTools.Merge( FCKEmbedAndObjectProcessor, |
| | 124 | { |
| | 125 | ProcessDocument : function( doc ) |
| | 126 | { |
| | 127 | var bIsDirty = FCK.IsDirty() ; |
| | 128 | |
| | 129 | // Process OBJECTs first, since EMBEDs can sometimes go inside OBJECTS (e.g. Flash). |
| | 130 | var aObjects = doc.getElementsByTagName( 'object' ); |
| | 131 | for ( var i = aObjects.length - 1 ; i >= 0 ; i-- ) |
| | 132 | this.ProcessObjectElement( aObjects[i] ) ; |
| | 133 | |
| | 134 | // Now process any EMBEDs left. |
| | 135 | var aEmbeds = doc.getElementsByTagName( 'embed' ) ; |
| | 136 | for ( var i = aEmbeds.length - 1 ; i >= 0 ; i-- ) |
| | 137 | this.ProcessEmbedElement( aEmbeds[i] ) ; |
| | 138 | |
| | 139 | if ( !bIsDirty ) |
| | 140 | FCK.ResetIsDirty() ; |
| | 141 | }, |
| | 142 | |
| | 143 | ProcessHtml : function( html ) |
| | 144 | { |
| | 145 | var tmp = document.createElement( 'div' ) ; |
| | 146 | tmp.innerHTML = html ; |
| | 147 | |
| | 148 | // We're only processing <OBJECT> tags from HTML right now, so let's just ignore <EMBED> tag processing here for now. |
| | 149 | this.ProcessObjectElement( tmp.firstChild ) ; |
| | 150 | return tmp.innerHTML ; |
| | 151 | }, |
| | 152 | |
| | 153 | ProcessObjectElement : function( el ) |
| | 154 | { |
| | 155 | var classId = el.attributes.classid ; |
| | 156 | if ( classId ) |
| | 157 | { |
| | 158 | classId = classId.value.replace( /[ \t]/g, '' ).toLowerCase() ; |
| | 159 | if ( this.ObjectProcessors[classId] ) |
| | 160 | this.ObjectProcessors[classId].Process( el ) ; |
| | 161 | else |
| | 162 | this.DefaultObjectHandler.Process( el ) ; |
| | 163 | } |
| | 164 | else |
| | 165 | this.DefaultObjectHandler.Process( el ) ; |
| | 166 | }, |
| | 167 | |
| | 168 | ProcessEmbedElement : function( el ) |
| | 169 | { |
| | 170 | var suffix = el.src.match( /\.(\w+)(?:\?[0-9A-Za-z!'()*-._~+&=]*)?$/ ) ; |
| | 171 | var type = el.attributes.type && el.attributes.type.nodeValue ; |
| | 172 | if ( type && this.EmbedMimeTypeProcessors[type] ) |
| | 173 | this.EmbedMimeTypeProcessors[type].Process( el ) ; |
| | 174 | else if ( suffix ) |
| | 175 | { |
| | 176 | suffix = suffix[1].toLowerCase() ; |
| | 177 | if ( this.EmbedSuffixProcessors[suffix] ) |
| | 178 | this.EmbedSuffixProcessors[suffix].Process( el ) ; |
| | 179 | else |
| | 180 | this.DefaultEmbedHandler.Process( el ) ; |
| | 181 | } |
| | 182 | else |
| | 183 | this.DefaultEmbedHandler.Process( el ) ; |
| | 184 | }, |
| | 185 | |
| | 186 | RefreshView : function( placeHolder, original ) |
| | 187 | { |
| | 188 | if ( original.nodeName.IEquals( 'object' ) ) |
| | 189 | { |
| | 190 | var classid = original.attributes.classid ; |
| | 191 | if ( classid ) |
| | 192 | { |
| | 193 | classId = classId.value.replace( /[ \t]/g, '' ).toLowerCase() ; |
| | 194 | if ( this.ObjectProcessors[classId] ) |
| | 195 | this.ObjectProcessors[classId].Refresh.apply( this, [placeHolder, original] ); |
| | 196 | else |
| | 197 | this.DefaultObjectHandler.Refresh( placeHolder, original ); |
| | 198 | } |
| | 199 | else |
| | 200 | this.DefaultObjectHandler.Refresh( placeHolder, original ); |
| | 201 | } |
| | 202 | else |
| | 203 | { |
| | 204 | var suffix = original.src.match( /\.(\w+)(?:\?[0-9A-Za-z!'()*-._~+&=]*)?$/ ) ; |
| | 205 | var type = original.attributes.type && el.attributes.type.nodeValue ; |
| | 206 | if ( type && this.EmbedMimeTypeProcessors[type] ) |
| | 207 | this.EmbedMimeTypeProcessors[type].Refresh.apply( this, [placeHolder, original] ) ; |
| | 208 | else if ( suffix ) |
| | 209 | { |
| | 210 | suffix = suffix[1].toLowerCase() ; |
| | 211 | if ( this.EmbedSuffixProcessors[suffix] ) |
| | 212 | this.EmbedSuffixProcessors[suffix].Refresh.apply( this, [placeHolder, original] ) ; |
| | 213 | else |
| | 214 | this.DefaultEmbedHandler.Refresh( placeHolder, original ) ; |
| | 215 | } |
| | 216 | else |
| | 217 | this.DefaultEmbedHandler.Refresh( placeHolder, original ) ; |
| | 218 | } |
| | 219 | }, |
| | 220 | |
| | 221 | ObjectProcessors : {}, |
| | 222 | EmbedSuffixProcessors : {}, |
| | 223 | EmbedMimeTypeProcessors : {}, |
| | 224 | |
| | 225 | // Include the "clsid:" part to classID as well, case insensitive. |
| | 226 | AttachObjectHandler : function( classId, obj ) |
| | 227 | { |
| | 228 | classId = classId.replace( /[ \t]/g, '' ).toLowerCase() ; |
| | 229 | this.ObjectProcessors[classId] = obj ; |
| | 230 | }, |
| | 231 | |
| | 232 | // Suffix is case insensitive. |
| | 233 | AttachEmbedHandlerByFileSuffix : function( suffix, obj ) |
| | 234 | { |
| | 235 | this.EmbedSuffixProcessors[suffix.toLowerCase()] = obj ; |
| | 236 | }, |
| | 237 | |
| | 238 | // MIME type is case sensitive since there are some MIME types that are distinguished by case alone. |
| | 239 | AttachEmbedHandlerByMimeType : function( mimestr, obj ) |
| | 240 | { |
| | 241 | this.EmbedMimeTypeProcessors[mimestr] = obj ; |
| | 242 | }, |
| | 243 | |
| | 244 | DefaultObjectHandler : |
| | 245 | { |
| | 246 | 'Process' : function( el ) |
| | 247 | { |
| | 248 | var clone = el.cloneNode( true ) ; |
| | 249 | var fakeImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__UnknownObject', clone ) ; |
| | 250 | this.Refresh( fakeImg, el ) ; |
| | 251 | el.parentNode.replaceChild( fakeImg, el ) ; |
| | 252 | }, |
| | 253 | |
| | 254 | 'Refresh' : function( placeHolder, original ) |
| | 255 | { |
| | 256 | if ( original.getAttribute( 'width' ) > 0 ) |
| | 257 | placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'width' ) ) ; |
| | 258 | |
| | 259 | if ( original.getAttribute( 'height' ) > 0 ) |
| | 260 | placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'height' ) ) ; |
| | 261 | } |
| | 262 | }, |
| | 263 | |
| | 264 | DefaultEmbedHandler : |
| | 265 | { |
| | 266 | 'Process' : function( el ) |
| | 267 | { |
| | 268 | var clone = el.cloneNode( true ) ; |
| | 269 | var fakeImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__UnknownObject', clone ) ; |
| | 270 | this.Refresh( fakeImg, el ) ; |
| | 271 | el.parentNode.replaceChild( fakeImg, el ) ; |
| | 272 | }, |
| | 273 | |
| | 274 | 'Refresh' : function( placeHolder, original ) |
| | 275 | { |
| | 276 | if ( original.getAttribute( 'width' ) > 0 ) |
| | 277 | placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'width' ) ) ; |
| | 278 | |
| | 279 | if ( original.getAttribute( 'height' ) > 0 ) |
| | 280 | placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( original.getAttribute( 'height' ) ) ; |
| | 281 | } |
| | 282 | } |
| | 283 | } ) ; |
| | 284 | if ( FCKBrowserInfo.IsIE ) |
| | 285 | { |
| | 286 | // Protect <object> tags. See #359. |
| | 287 | FCKConfig.ProtectedSource.CustomRegexHandlers.push( [/<object[\s\S]+?<\/object>/gi, |
| | 288 | FCKTools.Bind( FCKEmbedAndObjectProcessor, FCKEmbedAndObjectProcessor.ProcessHtml ) ] ) ; |