Changeset 807

Show
Ignore:
Timestamp:
2007-09-13 10:11:42 (3 years ago)
Author:
martinkou
Message:

Fix for #277 and #427 : Made the justify commands work for selections with multiple blocks.
Fixed JavaScript error in FCKW3CRange.toString().

Location:
FCKeditor/trunk/editor/_source
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/classes/fckdomrange.js

    r803 r807  
    841841 
    842842                return retval ; 
     843        }, 
     844 
     845        GetText : function() 
     846        { 
     847                if ( ! this._Range ) 
     848                        return '' ; 
     849                return this._Range.toString() ; 
    843850        } 
    844851} ; 
  • FCKeditor/trunk/editor/_source/classes/fckw3crange.js

    r806 r807  
    451451                var startNode = this.startContainer ; 
    452452                var endNode = this.endContainer ; 
    453                 if ( startNode.firstChild && this.startOffset ) 
    454                         startNode = startNode.childNodes[this.startOffset] ; 
    455                 if ( endNode.firstChild && this.endOffset ) 
    456                         endNode = endNode.childNodes[this.endOffset] ; 
     453 
     454                // note that it often occurs that startOffset/endOffset goes beyond the end of a container. 
     455                if ( startNode.firstChild ) 
     456                { 
     457                        if ( startNode.childNodes[this.startOffset] == null ) 
     458                                startNode = startNode.lastChild ; 
     459                        else 
     460                                startNode = startNode.childNodes[this.startOffset] ; 
     461                } 
     462                if ( endNode.firstChild ) 
     463                { 
     464                        if ( endNode.childNodes[this.endOffset] == null ) 
     465                                endNode = endNode.lastChild ; 
     466                        else 
     467                                endNode = endNode.childNodes[this.endOffset] ; 
     468                } 
    457469 
    458470                // Use an array for joining strings for performance. 
  • FCKeditor/trunk/editor/_source/commandclasses/fckjustifycommands.js

    r805 r807  
    1919 * == END LICENSE == 
    2020 * 
    21  * FCKJustifyCommand Class: controls text justification. 
     21 * FCKJustifyCommand Class: controls block justification. 
    2222 */ 
    2323 
     
    3535                range.MoveToSelection() ; 
    3636                var bookmark = range.CreateBookmark() ; 
    37                 range.Expand( 'block_contents' ) ; 
    38                 if ( range.StartContainer == range.Window.document.body ) 
    39                         range.FixBlock( true ) ; 
    40                 range.StartContainer.removeAttribute( 'align' ) ; 
     37                var paragraphs = range.GetParagraphs() ; 
    4138 
    42                 if ( this.CurrentState == FCK_TRISTATE_OFF) 
    43                         range.StartContainer.style.textAlign = this.AlignVaue ; 
    44                 else if ( this.CurrentState == FCK_TRISTATE_ON ) 
    45                         range.StartContainer.style.textAlign = '' ; 
     39                while ( paragraphs.length > 0 ) 
     40                { 
     41                        range = paragraphs.shift() ; 
     42                        if ( range.GetText().search( /^[\r\n\t ]*$/ ) == 0 ) 
     43                                continue ; 
     44 
     45                        if ( range.StartContainer == range.Window.document.body ) 
     46                                range.FixBlock( true ) ; 
     47                        range.StartContainer.removeAttribute( 'align' ) ; 
     48 
     49                        if ( this.CurrentState == FCK_TRISTATE_OFF) 
     50                                range.StartContainer.style.textAlign = this.AlignVaue ; 
     51                        else if ( this.CurrentState == FCK_TRISTATE_ON ) 
     52                                range.StartContainer.style.textAlign = '' ; 
     53 
     54                        var nextNode = range.EndNode ; 
     55                        while ( nextNode.lastChild ) 
     56                                nextNode = nextNode.lastChild ; 
     57                        currentNode = nextNode = FCKDomTools.GetNextSourceNode( nextNode ) ; 
     58                } 
    4659 
    4760                range.MoveToBookmark( bookmark ) ; 
     
    5871                } 
    5972 
    60                 var parentEl = FCKSelection.GetParentElement() ; 
    61                 var nearestBlock = parentEl ; 
    62                 while ( nearestBlock ) 
    63                 { 
    64                         if ( FCKListsLib.BlockBoundaries[nearestBlock.nodeName.toLowerCase()] ) 
    65                                 break ; 
    66                         nearestBlock = nearestBlock.parentNode ; 
    67                 } 
     73                var nearestBlock = FCKSelection.GetParentBlock() ; 
    6874 
    6975                if ( ! nearestBlock ) 
  • FCKeditor/trunk/editor/_source/internals/fckdomtools.js

    r799 r807  
    316316                while ( node ) 
    317317                { 
    318                         parents.splice( 0, 0, node ) ; 
     318                        parents.unshift( node ) ; 
    319319                        node = node.parentNode ; 
    320320                } 
    321321 
    322322                return parents ; 
     323        }, 
     324 
     325        GetCommonParents : function( node1, node2 ) 
     326        { 
     327                var p1 = this.GetParents( node1 ) ; 
     328                var p2 = this.GetParents( node2 ) ; 
     329                var retval = [] ; 
     330                for ( var i = 0 ; i < p1.length ; i++ ) 
     331                { 
     332                        if ( p1[i] == p2[i] ) 
     333                                retval.push( p1[i] ) ; 
     334                } 
     335                return retval ; 
     336        }, 
     337 
     338        GetCommonParentNode : function( node1, node2, tagList ) 
     339        { 
     340                var tagMap = {} ; 
     341                if ( ! tagList.pop ) 
     342                        tagList = [ tagList ] ; 
     343                while ( tagList.length > 0 ) 
     344                        tagMap[tagList.pop().toLowerCase()] = 1 ; 
     345 
     346                var commonParents = this.GetCommonParents( node1, node2 ) ; 
     347                var currentParent = null ; 
     348                while ( ( currentParent = commonParents.pop() ) ) 
     349                { 
     350                        if ( tagMap[currentParent.nodeName.toLowerCase()] ) 
     351                                return currentParent ; 
     352                } 
     353                return null ; 
    323354        }, 
    324355 
  • FCKeditor/trunk/editor/_source/internals/fckselection.js

    r480 r807  
    2222 */ 
    2323 
    24 var FCKSelection = FCK.Selection = new Object() ; 
    25  
     24var FCKSelection = FCK.Selection =  
     25{ 
     26        GetParentBlock : function() 
     27        { 
     28                var retval = this.GetParentElement() ; 
     29                while ( retval ) 
     30                { 
     31                        if ( FCKListsLib.BlockBoundaries[retval.nodeName.toLowerCase()] ) 
     32                                break ; 
     33                        retval = retval.parentNode ; 
     34                } 
     35                return retval ; 
     36        } 
     37} ;