Changeset 1675 for FCKeditor/branches

Show
Ignore:
Timestamp:
2008-03-04 04:28:31 (9 months ago)
Author:
martinkou
Message:

Initial commit of the generic object and embed code for #922.

Location:
FCKeditor/branches/features/generic_plugin
Files:
1 added
5 modified
1 copied

Legend:

Unmodified
Added
Removed
  • FCKeditor/branches/features/generic_plugin/editor/css/fck_internal.css

    r1598 r1675  
    5252        background-position: center center; 
    5353        background-image: url(images/fck_flashlogo.gif); 
     54        background-repeat: no-repeat; 
     55        width: 80px; 
     56        height: 80px; 
     57} 
     58 
     59.FCK__UnknownObject 
     60{ 
     61        border: #a9a9a9 1px solid; 
     62        background-position: center center; 
     63        background-image: url(images/fck_plugin.gif); 
    5464        background-repeat: no-repeat; 
    5565        width: 80px; 
  • FCKeditor/branches/features/generic_plugin/editor/dialog/fck_flash/fck_flash.js

    r1598 r1675  
    142142        } 
    143143 
    144         oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oEmbed ) ; 
     144        oEditor.FCKFlashHandler.Refresh( oFakeImage, oEmbed ) ; 
    145145 
    146146        return true ; 
  • FCKeditor/branches/features/generic_plugin/editor/_source/internals/fckconfig.js

    r1628 r1675  
    177177 
    178178        // <noscript> tags (get lost in IE and messed up in FF). 
    179         /<noscript[\s\S]*?<\/noscript>/gi, 
    180  
    181         // Protect <object> tags. See #359. 
    182         /<object[\s\S]+?<\/object>/gi 
     179        /<noscript[\s\S]*?<\/noscript>/gi 
    183180] ; 
     181 
     182FCKConfig.ProtectedSource.CustomRegexHandlers = [] ; 
    184183 
    185184FCKConfig.ProtectedSource.Add = function( regexPattern ) 
     
    195194                var index = FCKTempBin.AddElement( protectedSource ) ; 
    196195                return '<!--{' + codeTag + index + '}-->' ; 
     196        } 
     197 
     198        for ( var i = 0 ; i < this.CustomRegexHandlers.length ; i++ ) 
     199        { 
     200                html = html.replace( this.CustomRegexHandlers[i][0], this.CustomRegexHandlers[i][1] ) ; 
    197201        } 
    198202 
  • FCKeditor/branches/features/generic_plugin/editor/_source/internals/fckdocumentprocessor.js

    r1565 r1675  
    4141var FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement ) 
    4242{ 
    43         var oImg = FCK.EditorDocument.createElement( 'IMG' ) ; 
     43        var oImg = FCKTools.GetElementDocument( realElement ).createElement( 'IMG' ) ; 
    4444        oImg.className = fakeClass ; 
    4545        oImg.src = FCKConfig.FullBasePath + 'images/spacer.gif' ; 
     
    119119} 
    120120 
    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&nbsp;<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. 
     122var FCKEmbedAndObjectProcessor = FCKDocumentProcessor.AppendNew() ; 
     123FCKTools.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        } ) ; 
     284if ( 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 ) ] ) ; 
    170289} 
    171290 
     
    230349        } 
    231350} 
     351 
     352// Flash handler. 
     353var FCKFlashHandler = 
     354{ 
     355        Process : function( el ) 
     356        { 
     357                var clone = el.cloneNode( true ) ; 
     358                var fakeImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', clone ) ; 
     359                fakeImg.setAttribute( '_fckflash', 'true', 0 );  
     360                this.Refresh( fakeImg, el ) ; 
     361                el.parentNode.replaceChild( fakeImg, el ) ; 
     362        }, 
     363 
     364        Refresh : function( placeHolderImage, originalEmbed ) 
     365        { 
     366                if ( originalEmbed.getAttribute( 'width' ) > 0 ) 
     367                        placeHolderImage.style.width = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'width' ) ) ; 
     368 
     369                if ( originalEmbed.getAttribute( 'height' ) > 0 ) 
     370                        placeHolderImage.style.height = FCKTools.ConvertHtmlSizeToStyle( originalEmbed.getAttribute( 'height' ) ) ; 
     371        } 
     372} ; 
     373FCKEmbedAndObjectProcessor.AttachEmbedHandlerByFileSuffix( 'swf', FCKFlashHandler ) ; 
     374FCKEmbedAndObjectProcessor.AttachEmbedHandlerByMimeType( 'application/x-shockwave-flash', FCKFlashHandler ) ; 
  • FCKeditor/branches/features/generic_plugin/editor/_source/internals/fck.js

    r1629 r1675  
    400400                if ( FCKBrowserInfo.IsIE && FCK.EditorDocument ) 
    401401                { 
    402                                 FCK.EditorDocument.detachEvent("onselectionchange", Doc_OnSelectionChange ) ; 
     402                        FCK.EditorDocument.detachEvent("onselectionchange", Doc_OnSelectionChange ) ; 
    403403                } 
    404404