| | 772 | // If we're in a non-IE browser, and the newBlock is <pre>, and the old block is not <pre>, |
| | 773 | // then we need to clear linebreaks and compress ANSI whitespaces so that we don't get disrupted |
| | 774 | // output in <pre> mode. (Bug #1355) |
| | 775 | if ( !FCKBrowserInfo.IsIE && newBlock.nodeName.IEquals( 'pre' ) && !block.nodeName.IEquals( 'pre' ) ) |
| | 776 | { |
| | 777 | // If the newBlock's first child is a text node, left-trim it since any ANSI whitespace |
| | 778 | // after a non-pre block is meaningless. |
| | 779 | if ( newBlock.firstChild && newBlock.firstChild.nodeType == 3 ) |
| | 780 | newBlock.firstChild.nodeValue = newBlock.firstChild.nodeValue.LTrim() ; |
| | 781 | |
| | 782 | // Ditto for the last child. |
| | 783 | if ( newBlock.lastChild && newBlock.lastChild.nodeType == 3 ) |
| | 784 | newBlock.lastChild.nodeValue = newBlock.lastChild.nodeValue.RTrim() ; |
| | 785 | |
| | 786 | // DFS walk the newBlock to compress ANSI whitespaces and delete excessive linebreaks. |
| | 787 | var currentNode = newBlock ; |
| | 788 | while ( currentNode ) |
| | 789 | { |
| | 790 | currentNode = FCKDomTools.GetNextSourceNode( currentNode, false, 3, newBlock.parentNode ) ; |
| | 791 | if ( currentNode ) |
| | 792 | { |
| | 793 | // If the text node ends with a line break, and its next sibling is a <BR>, |
| | 794 | // then right-trim the text node. |
| | 795 | if ( currentNode.nodeValue.charAt( currentNode.nodeValue.length - 1 ) == '\n' |
| | 796 | && currentNode.nextSibling |
| | 797 | && currentNode.nextSibling.nodeName.IEquals( 'br' ) ) |
| | 798 | currentNode.nodeValue = currentNode.nodeValue.RTrim() ; |
| | 799 | // If the text node begins with a line break, and its next sibling is a <BR>, |
| | 800 | // then left-trim the text node. |
| | 801 | if ( currentNode.nodeValue.charAt( 0 ) == '\n' |
| | 802 | && currentNode.previousSibling |
| | 803 | && currentNode.previousSibling.nodeName.IEquals( 'br' ) ) |
| | 804 | currentNode.nodeValue = currentNode.nodeValue.LTrim() ; |
| | 805 | // Compress any ANSI whitespaces left. |
| | 806 | currentNode.nodeValue = currentNode.nodeValue.replace( /[\r\n\t ]+/g, ' ' ) ; |
| | 807 | } |
| | 808 | } |
| | 809 | } |
| | 810 | |