Ticket #617: 617_2.patch

File 617_2.patch, 9.3 KB (added by Martin Kou, 16 years ago)

Proposed fix for #617, version 2.

  • editor/_source/internals/fckxhtml.js

     
    3030        FCKDomTools.CheckAndRemovePaddingNode( node.ownerDocument, FCKConfig.EnterMode ) ;
    3131        FCKXHtmlEntities.Initialize() ;
    3232
     33        // Random ID for protected attributes.
     34        this._ProtectID = Math.random() ;
     35
    3336        // Set the correct entity to use for empty blocks.
    3437        this._NbspEntity = ( FCKConfig.ProcessHTMLEntities? 'nbsp' : '#160' ) ;
    3538
     
    484487} ;
    485488
    486489FCKXHtml.TagProcessors.ul = FCKXHtml.TagProcessors.ol ;
     490
     491FCKXHtml.AttributeProcessors =
     492{
     493        style : function( node, htmlNode, attrValue )
     494        {
     495                var borderPattern = /border[a-zA-Z-]*\s*:[^;]+(;|$)\s*/g ;
     496               
     497                if ( attrValue.match( borderPattern ) )
     498                {
     499                        // Remove all border attributes from the style string.
     500                        attrValue = attrValue.replace( borderPattern, '' ) ;
     501                        var oldAttrValue = attrValue ;
     502
     503                        // Calculate the most compact border style representation.
     504                        // 1. Start from the 12 basic border-[DIRECTION]-[STYLE] values.
     505                        // 2. If [STYLE] has the same value for all [DIRECTION]s, compress to a single border-[STYLE] value,
     506                        //      and eliminate the redundant values.
     507                        // 3. If any border-[DIRECTION] or border have all 3 [STYLE]s under it, compress the [STYLES]s to
     508                        //      a single string and eliminate the redundant values.
     509                        var directions = ['top', 'right', 'bottom', 'left'] ;
     510                        var styles = ['width', 'style', 'color'] ;
     511                        var borderStyle = {} ;
     512                        for ( var i = 0 ; i < directions.length ; i++ )
     513                        {
     514                                for ( var j = 0 ; j < styles.length ; j++ )
     515                                {
     516                                        var cssName = ['border', directions[i], styles[j]].join( '-' ) ;
     517                                        var jsName = ['border', directions[i].charAt(0).toUpperCase() + directions[i].substr(1),
     518                                            styles[j].charAt(0).toUpperCase() + styles[j].substr(1)].join( '' ) ;
     519                                        borderStyle[cssName] = FCKDomTools.GetCurrentElementStyle( FCKTools.GetElementWindow( htmlNode ),
     520                                                        htmlNode, jsName ) ;
     521                                        if ( styles[j] == 'color' )
     522                                                borderStyle[cssName] = FCKTools.RGBToHex( borderStyle[cssName] ) ;
     523                                }
     524                        }
     525
     526                        for ( var i = 0 ; i < styles.length ; i++ )
     527                        {
     528                                var isEqual = true ;
     529                                var lastValue = null ;
     530                                for ( var j = 0 ; j < directions.length ; j++ )
     531                                {
     532                                        var cssName = ['border', directions[j], styles[i]].join( '-' ) ;
     533                                        if ( lastValue == null )
     534                                                lastValue = borderStyle[cssName] ;
     535                                        if ( lastValue != borderStyle[cssName] )
     536                                        {
     537                                                isEqual = false ;
     538                                                break ;
     539                                        }
     540                                }
     541                                if ( isEqual )
     542                                {
     543                                        borderStyle['border-' + styles[i]] = lastValue ;
     544                                        for ( var j = 0 ; j < directions.length ; j++ )
     545                                                delete borderStyle[['border', directions[j], styles[i]].join( '-' )] ;
     546                                }
     547                        }
     548
     549                        for ( var i = 0 ; i < directions.length ; i++ )
     550                        {
     551                                if ( borderStyle['border-' + directions[i] + '-width'] &&
     552                                                borderStyle['border-' + directions[i] + '-style'] &&
     553                                                borderStyle['border-' + directions[i] + '-color'])
     554                                {
     555                                        borderStyle['border-' + directions[i]] = borderStyle['border-' + directions[i] + '-width'] + ' '
     556                                                + borderStyle['border-' + directions[i] + '-style'] + ' '
     557                                                + borderStyle['border-' + directions[i] + '-color'] ;
     558                                        delete borderStyle['border-' + directions[i] + '-width'] ;
     559                                        delete borderStyle['border-' + directions[i] + '-style'] ;
     560                                        delete borderStyle['border-' + directions[i] + '-color'] ;
     561                                }
     562                        }
     563
     564                        if ( borderStyle['border-width'] && borderStyle['border-style'] && borderStyle['border-color'] )
     565                        {
     566                                borderStyle['border'] = borderStyle['border-width'] + ' '
     567                                        + borderStyle['border-style'] + ' '
     568                                        + borderStyle['border-color'] ;
     569                                delete borderStyle['border-width'] ;
     570                                delete borderStyle['border-style'] ;
     571                                delete borderStyle['border-color'] ;
     572                        }
     573
     574                        // Calculate the style string fragment according to the minimal representation and append it
     575                        // to the attrValue.
     576                        var fragment = [] ;
     577                        for ( var i in borderStyle )
     578                                fragment.push( i + ': ' + borderStyle[i] ) ;
     579                        fragment = ' ' + fragment.join( '; ' ) + ';' ;
     580                        attrValue += fragment ;
     581                        attrValue = attrValue.Trim() ;
     582                }
     583
     584                FCKXHtml._AppendAttribute( node, 'style_protected_' + FCKXHtml._ProtectID , attrValue ) ;
     585        }
     586} ;
  • editor/_source/internals/fcktools.js

     
    619619{
    620620  return function() { obj[methodName].apply(obj, arguments); } ;
    621621}
     622
     623/**
     624 * Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
     625 */
     626FCKTools.RGBToHex = function( rgb )
     627{
     628        var matchResults = rgb.match( /(rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/i ) ;
     629        if ( !matchResults )
     630                return rgb ;
     631
     632        var red = parseInt( matchResults[2], 10 ).toString( 16 ),
     633            green = parseInt( matchResults[3], 10 ).toString( 16 ),
     634            blue = parseInt( matchResults[4], 10 ).toString( 16 ) ;
     635        var color = [red, green, blue] ;
     636       
     637        // Add padding zeros if the hex value is less than 0x10.
     638        for ( var i = 0 ; i < color.length ; i++ )
     639                color[i] = String( '0' + color[i] ).slice( -2 ) ;
     640
     641        return '#' + color.join( '' ) ;
     642}
  • editor/_source/internals/fckxhtml_gecko.js

     
    2424
    2525FCKXHtml._GetMainXmlString = function()
    2626{
    27         return '<xhtml>' + this.MainNode.innerHTML + '</xhtml>' ;
     27        var html = this.MainNode.innerHTML.replace( new RegExp( '_protected_' + this._ProtectID, 'g' ), '' ) ;
     28        return '<xhtml>' + html + '</xhtml>' ;
    2829}
    2930
    3031FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node )
     
    6061                        else
    6162                                sAttValue = htmlNode.getAttribute( sAttName, 2 ) ;      // We must use getAttribute to get it exactly as it is defined.
    6263
    63                         this._AppendAttribute( node, sAttName, sAttValue ) ;
     64                        if ( this.AttributeProcessors[sAttName] )
     65                                this.AttributeProcessors[sAttName]( node, htmlNode, sAttValue ) ;
     66                        else
     67                                this._AppendAttribute( node, sAttName, sAttValue ) ;
    6468                }
    6569        }
    6670}
  • editor/_source/internals/fckxhtml_ie.js

     
    2424
    2525FCKXHtml._GetMainXmlString = function()
    2626{
    27         return this.MainNode.xml ;
     27        var html = this.MainNode.xml.replace( new RegExp( '_protected_' + this._ProtectID, 'g' ), '' ) ;
     28        return html ;
    2829}
    2930
    3031FCKXHtml._AppendAttributes = function( xmlNode, htmlNode, node, nodeName )
     
    7778                                }
    7879                                catch (e) {}
    7980                        }
    80                         this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ;
     81                        if ( this.AttributeProcessors[sAttName] )
     82                                this.AttributeProcessors[sAttName]( node, htmlNode, sAttValue) ;
     83                        else
     84                                this._AppendAttribute( node, sAttName, sAttValue || oAttribute.nodeValue ) ;
    8185                }
    8286        }
    8387}
     
    200204        node = FCKXHtml._AppendChildNodes( node, htmlNode ) ;
    201205
    202206        return node ;
    203 }
    204  No newline at end of file
     207}
  • editor/dialog/fck_tablecell.html

     
    6464                if ( oCell.attributes['noWrap'] != null && oCell.attributes['noWrap'].specified )
    6565                        GetE('selWordWrap').value = !oCell.noWrap ;
    6666
     67                var sBorderColor = oCell.style.borderColor ;
     68                var matchResults = null ;
     69                sBorderColor = oEditor.FCKTools.RGBToHex( sBorderColor ) ;
     70
    6771                GetE('txtWidth').value                  = iWidth ;
    6872                GetE('txtHeight').value                 = GetAttribute( oCell, 'height' ) ;
    6973                GetE('selHAlign').value                 = GetAttribute( oCell, 'align' ) ;
     
    7175                GetE('txtRowSpan').value                = GetAttribute( oCell, 'rowSpan' ) ;
    7276                GetE('txtCollSpan').value               = GetAttribute( oCell, 'colSpan' ) ;
    7377                GetE('txtBackColor').value              = GetAttribute( oCell, 'bgColor' ) ;
    74                 GetE('txtBorderColor').value    = GetAttribute( oCell, 'borderColor' ) ;
     78                GetE('txtBorderColor').value    = sBorderColor ;
    7579//              GetE('cmbFontStyle').value              = oCell.className ;
    7680        }
    7781}
     
    97101                SetAttribute( aCells[i], 'rowSpan'              , GetE('txtRowSpan').value ) ;
    98102                SetAttribute( aCells[i], 'colSpan'              , GetE('txtCollSpan').value ) ;
    99103                SetAttribute( aCells[i], 'bgColor'              , GetE('txtBackColor').value ) ;
    100                 SetAttribute( aCells[i], 'borderColor'  , GetE('txtBorderColor').value ) ;
     104
     105                var sBorderColor = GetE( 'txtBorderColor' ).value ;
     106                if ( sBorderColor.length > 0 )
     107                {
     108                        var borderStyle = {'borderColor' : sBorderColor} ;
     109                        var presentStyle = oEditor.FCKDomTools.GetCurrentElementStyle( oEditor.FCKTools.GetElementWindow( aCells[i] ), aCells[i] , 'borderTopStyle' ) ;
     110                        if ( presentStyle.match( /^(none|.*inset.*)$/ ) )
     111                        {
     112                                borderStyle.borderWidth = '1px' ;
     113                                borderStyle.borderStyle = 'solid' ;
     114                        }
     115                        oEditor.FCKDomTools.SetElementStyles( aCells[i], borderStyle ) ;
     116                }
     117                else
     118                        aCells[i].style.border = 'default' ;
    101119//              SetAttribute( aCells[i], 'className'    , GetE('cmbFontStyle').value ) ;
    102120        }
    103121
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy