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