Ticket #1858: fckjustifycommands.js.patch

File fckjustifycommands.js.patch, 3.9 KB (added by Karen Ananiev, 16 years ago)

I'm not sure that it is good solution but it works :)

  • editor/_source/commandclasses/fckjustifycommands.js

     
    1 /*
     1/*
    22 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
    33 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
    44 *
     
    8888        {
    8989                // Save an undo snapshot before doing anything.
    9090                FCKUndo.SaveUndoStep() ;
    91 
     91               
    9292                var range = new FCKDomRange( FCK.EditorWindow ) ;
    9393                range.MoveToSelection() ;
    94 
     94               
    9595                var currentState = this.GetState() ;
    9696                if ( currentState == FCK_TRISTATE_DISABLED )
    9797                        return ;
    98 
    99                 // Store a bookmark of the selection since the paragraph iterator might
    100                 // change the DOM tree and break selections.
    101                 var bookmark = range.CreateBookmark() ;
    102 
    103                 var cssClassName = this._CssClassName ;
    104 
    105                 // Apply alignment setting for each paragraph.
    106                 var iterator = new FCKDomRangeIterator( range ) ;
    107                 var block ;
    108                 while ( ( block = iterator.GetNextParagraph() ) )
     98               
     99                if ( FCKBrowserInfo.IsGecko )
    109100                {
    110                         block.removeAttribute( 'align' ) ;
    111 
    112                         if ( cssClassName )
     101                        var node = range._Range.startContainer ;
     102                        var aCells = [] ;
     103                       
     104                        while ( node )
    113105                        {
    114                                 // Remove the any of the alignment classes from the className.
    115                                 var className = block.className.replace( FCKJustifyCommand._GetClassNameRegex(), '' ) ;
    116 
    117                                 // Append the desired class name.
    118                                 if ( currentState == FCK_TRISTATE_OFF )
     106                                if ( node.nodeType == 1 )
    119107                                {
    120                                         if ( className.length > 0 )
    121                                                 className += ' ' ;
    122                                         block.className = className + cssClassName ;
     108                                        if ( node.tagName.IEquals(['tr', 'table']) )
     109                                        {
     110                                                aCells = FCKTableHandler.GetSelectedCells() ;
     111                                                break ;
     112                                        }
    123113                                }
    124                                 else if ( className.length == 0 )
    125                                         FCKDomTools.RemoveAttribute( block, 'class' ) ;
     114                               
     115                                node = node.parentNode ;
    126116                        }
    127                         else
    128                         {
    129                                 var style = block.style ;
    130                                 if ( currentState == FCK_TRISTATE_OFF )
    131                                         style.textAlign = this.AlignValue ;
    132                                 else
     117                       
     118                        if ( aCells.length > 1 )
     119                        {
     120                                for ( var i = 0 ; i < aCells.length ; i++ )
    133121                                {
    134                                         style.textAlign = '' ;
    135                                         if ( style.cssText.length == 0 )
    136                                                 block.removeAttribute( 'style' ) ;
     122                                        this._SetAlign( aCells[i], currentState ) ;
    137123                                }
     124                               
     125                                FCK.Focus() ;
     126                                FCK.Events.FireEvent( 'OnSelectionChange' ) ;
     127                           
     128                                return ;
    138129                        }
    139130                }
    140 
     131               
     132                // Store a bookmark of the selection since the paragraph iterator might
     133                // change the DOM tree and break selections.
     134                var bookmark = range.CreateBookmark() ;
     135               
     136                // Apply alignment setting for each paragraph.
     137                var iterator = new FCKDomRangeIterator( range ) ;
     138                var block ;
     139                while ( ( block = iterator.GetNextParagraph() ) )
     140                {
     141                        this._SetAlign( block, currentState ) ;
     142                }
     143               
    141144                // Restore previous selection.
    142145                range.MoveToBookmark( bookmark ) ;
    143146                range.Select() ;
    144 
     147               
    145148                FCK.Focus() ;
    146149                FCK.Events.FireEvent( 'OnSelectionChange' ) ;
    147150        },
     151       
     152        _SetAlign : function( block, currentState )
     153        {
     154                var cssClassName = this._CssClassName ;
     155               
     156                block.removeAttribute( 'align' ) ;
     157               
     158                if ( cssClassName )
     159                {
     160                        // Remove the any of the alignment classes from the className.
     161                        var className = block.className.replace( FCKJustifyCommand._GetClassNameRegex(), '' ) ;
     162                       
     163                        // Append the desired class name.
     164                        if ( currentState == FCK_TRISTATE_OFF )
     165                        {
     166                                if ( className.length > 0 )
     167                                        className += ' ' ;
     168                                block.className = className + cssClassName ;
     169                        }
     170                        else if ( className.length == 0 )
     171                                FCKDomTools.RemoveAttribute( block, 'class' ) ;
     172                }
     173                else
     174                {
     175                        var style = block.style ;
     176                        if ( currentState == FCK_TRISTATE_OFF )
     177                        {
     178                                style.textAlign = this.AlignValue ;
     179                        }
     180                        else
     181                        {
     182                                style.textAlign = '' ;
     183                                if ( style.cssText.length == 0 )
     184                                        block.removeAttribute( 'style' ) ;
     185                        }
     186                }
     187        },
    148188
    149189        GetState : function()
    150190        {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy