Ticket #1384: fckdomrange.patch

File fckdomrange.patch, 4.1 KB (added by Scott McNaught, 17 years ago)
  • fckdomrange.js

     
    160160                        this._Range.insertNode( node ) ;
    161161        },
    162162
    163         CheckIsEmpty : function()
     163        // Checks if the range is empty
     164        // @bCheckEmptyInline Return true on empty inline tags such as: <u></u>
     165        // @iTrimType 0 = full trim, 1 = left trim, 2 = right trim, 3 = no trim
     166        CheckIsEmpty : function( bCheckEmptyInline, iTrimType )
    164167        {
    165168                if ( this.CheckIsCollapsed() )
    166169                        return true ;
     
    169172                var eToolDiv = this.Window.document.createElement( 'div' ) ;
    170173                this._Range.cloneContents().AppendTo( eToolDiv ) ;
    171174
    172                 FCKDomTools.TrimNode( eToolDiv ) ;
     175                if( iTrimType == 1 )
     176                {
     177                        FCKDomTools.LTrimNode( eToolDiv ) ;
     178                }
     179                else if( iTrimType == 2 )
     180                {
     181                        FCKDomTools.RTrimNode( eToolDiv ) ;
     182                }
     183                else if( iTrimType != 3 )
     184                {
     185                        FCKDomTools.TrimNode( eToolDiv ) ;
     186                }
    173187
     188                if( bCheckEmptyInline )
     189                {
     190                        // Recursive function to determine if all children of a node are inline
     191                        AreAllChildrenInline = function( pElement )
     192                        {
     193                                for( var i = 0; i < pElement.childNodes.length; i++ )
     194                                {
     195                                        var pChild = pElement.childNodes[i] ;
     196
     197                                        if( !pChild.nodeName )
     198                                        {
     199                                                return false ;
     200                                        }
     201                                       
     202                                        if( FCKListsLib.InlineChildReqElements[pChild.nodeName.toLowerCase() ] == null )
     203                                        {
     204                                                return false ;
     205                                        }
     206                                       
     207                                        if( !AreAllChildrenInline( pChild ) )
     208                                        {
     209                                                return false ;
     210                                        }
     211                                }
     212                               
     213                                return true ;
     214                        };
     215                       
     216                        return AreAllChildrenInline( eToolDiv ) ;
     217                }
     218
    174219                return ( eToolDiv.innerHTML.length == 0 ) ;
    175220        },
    176221
    177         CheckStartOfBlock : function()
     222        CheckStartOfBlock : function( refreshSelection )
    178223        {
    179224                var bIsStartOfBlock = this._Cache.IsStartOfBlock ;
    180225
     
    190235                // Move the start boundary to the start of the block.
    191236                oTestRange.SetStart( oTestRange.StartBlock || oTestRange.StartBlockLimit, 1 ) ;
    192237
    193                 if ( oTestRange.CheckIsCollapsed() )
    194                         bIsStartOfBlock = true ;
    195                 else
     238                bIsStartOfBlock = oTestRange.CheckIsCollapsed() ;
     239
     240                if ( !bIsStartOfBlock )
    196241                {
    197                         // Inserts the contents of the range in a div tag.
    198                         var eToolDiv = oTestRange.Window.document.createElement( 'div' ) ;
    199                         oTestRange._Range.cloneContents().AppendTo( eToolDiv ) ;
    200 
    201                         // This line is why we don't use CheckIsEmpty() here...
    202                         // Because using RTrimNode() or TrimNode() would be incorrect -
    203242                        // TrimNode() and RTrimNode() would delete <br> nodes at the end of the div node,
    204243                        // but for checking start of block they are actually meaningful. (Bug #1350)
    205                         FCKDomTools.LTrimNode( eToolDiv ) ;
    206 
    207                         bIsStartOfBlock = ( eToolDiv.innerHTML.length == 0 ) ;
     244                        // The second parameter to CheckIsEmpty forces just an LTrimNode()
     245                        bIsStartOfBlock = oTestRange.CheckIsEmpty( true, 2 );
    208246                }
    209247
    210248                oTestRange.Release() ;
     249               
     250                if ( refreshSelection )
     251                        this.Select() ;
    211252
    212253                return ( this._Cache.IsStartOfBlock = bIsStartOfBlock ) ;
    213254        },
     
    232273
    233274                if ( !bIsEndOfBlock )
    234275                {
    235                         // Inserts the contents of the range in a div tag.
    236                         var eToolDiv = this.Window.document.createElement( 'div' ) ;
    237                         oTestRange._Range.cloneContents().AppendTo( eToolDiv ) ;
    238                         FCKDomTools.TrimNode( eToolDiv ) ;
    239 
    240                         // Find out if we are in an empty tree of inline elements, like <b><i><span></span></i></b>
    241                         bIsEndOfBlock = true ;
    242                         var eLastChild = eToolDiv ;
    243                         while ( ( eLastChild = eLastChild.lastChild ) )
    244                         {
    245                                 // Check the following:
    246                                 //              1. Is there more than one node in the parents children?
    247                                 //              2. Is the node not an element node?
    248                                 //              3. Is it not a inline element.
    249                                 if ( eLastChild.previousSibling || eLastChild.nodeType != 1 || FCKListsLib.InlineChildReqElements[ eLastChild.nodeName.toLowerCase() ] == null )
    250                                 {
    251                                         // So we are not in the end of the range.
    252                                         bIsEndOfBlock = false ;
    253                                         break ;
    254                                 }
    255                         }
     276                        bIsEndOfBlock = oTestRange.CheckIsEmpty( true );
    256277                }
    257278
    258279                oTestRange.Release() ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy