| | 839 | // The currentBlock must not be moved or deleted from the DOM tree. |
| | 840 | // This guarantees the FCKDomRangeIterator in _ApplyBlockStyle would not |
| | 841 | // get lost at the next iteration. |
| | 842 | _CheckAndMergePre : function( previousBlock, currentBlock ) |
| | 843 | { |
| | 844 | // Check if the next block in HTML equals the next <PRE> block generated. |
| | 845 | if ( FCKDomTools.GetNextSourceElement( previousBlock, true, null, null, true ) != currentBlock ) |
| | 846 | return ; |
| | 847 | |
| | 848 | // Merge the upper <PRE> block's content into the lower <PRE> |
| | 849 | // block. |
| | 850 | // Remove the upper <PRE> block. |
| | 851 | // |
| | 852 | // Another thing to be careful here is that currentBlock might |
| | 853 | // contain a '\n' at the beginning, and previousBlock might |
| | 854 | // contain a '\n' towards the end. These new lines are not |
| | 855 | // normally displayed but they become visible after merging. |
| | 856 | currentBlock.innerHTML = previousBlock.innerHTML.replace( /\n$/, '' ) + '\n\n' + |
| | 857 | currentBlock.innerHTML.replace( /^\n/, '' ) ; |
| | 858 | FCKDomTools.RemoveNode( previousBlock ) ; |
| | 859 | }, |
| | 860 | |
| | 861 | _CheckAndSplitPre : function( doc, previousBlock ) |
| | 862 | { |
| | 863 | var lastNewBlock = null ; |
| | 864 | for ( var j = 0 ; j < previousBlock.childNodes.length ; j++ ) |
| | 865 | { |
| | 866 | var cursor = previousBlock.childNodes[j] ; |
| | 867 | |
| | 868 | // If we have two <BR>s, and they're not at the beginning or the end, |
| | 869 | // then we'll split up the contents following them into another block. |
| | 870 | if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != previousBlock.childNodes.length - 2 |
| | 871 | && cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) ) |
| | 872 | { |
| | 873 | FCKDomTools.RemoveNode( cursor.nextSibling ) ; |
| | 874 | FCKDomTools.RemoveNode( cursor ) ; |
| | 875 | j-- ; // restart at current index at next iteration |
| | 876 | lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || previousBlock, doc.createElement( previousBlock.nodeName ) ) ; |
| | 877 | continue ; |
| | 878 | } |
| | 879 | |
| | 880 | if ( lastNewBlock ) |
| | 881 | { |
| | 882 | FCKDomTools.MoveNode( cursor, lastNewBlock ) ; |
| | 883 | j-- ; // restart at current index at next iteration |
| | 884 | } |
| | 885 | } |
| | 886 | }, |
| | 887 | |
| 889 | | // Merge adjacent <PRE> blocks for #1229. |
| 890 | | for ( var i = 0 ; i < preBlocks.length - 1 ; i++ ) |
| 891 | | { |
| 892 | | // Check if the next block in HTML equals the next <PRE> block generated. |
| 893 | | if ( FCKDomTools.GetNextSourceElement( preBlocks[i], true, [], [], true ) != preBlocks[i+1] ) |
| 894 | | continue ; |
| 895 | | |
| 896 | | // Merge the upper <PRE> block's content into the lower <PRE> block. |
| 897 | | // Remove the upper <PRE> block. |
| 898 | | preBlocks[i+1].innerHTML = preBlocks[i].innerHTML + '\n\n' + preBlocks[i+1].innerHTML ; |
| 899 | | FCKDomTools.RemoveNode( preBlocks[i] ) ; |
| 900 | | } |
| 901 | | |
| 902 | | // Split converted <PRE> blocks for #1229. |
| 903 | | for ( var i = 0 ; i < convertedPreBlocks.length ; i++ ) |
| 904 | | { |
| 905 | | var currentBlock = convertedPreBlocks[i] ; |
| 906 | | var lastNewBlock = null ; |
| 907 | | for ( var j = 0 ; j < currentBlock.childNodes.length ; j++ ) |
| | 931 | // Split and merge processed PRE blocks after they're |
| | 932 | // placed in document. |
| | 933 | if ( newBlockIsPre && !blockIsPre ) |
| 909 | | var cursor = currentBlock.childNodes[j] ; |
| 910 | | |
| 911 | | // If we have two <BR>s, and they're not at the beginning or the end, |
| 912 | | // then we'll split up the contents following them into another block. |
| 913 | | if ( cursor.nodeName.IEquals( 'br' ) && j != 0 && j != currentBlock.childNodes.length - 2 |
| 914 | | && cursor.nextSibling && cursor.nextSibling.nodeName.IEquals( 'br' ) ) |
| 915 | | { |
| 916 | | FCKDomTools.RemoveNode( cursor.nextSibling ) ; |
| 917 | | FCKDomTools.RemoveNode( cursor ) ; |
| 918 | | j-- ; // restart at current index at next iteration |
| 919 | | lastNewBlock = FCKDomTools.InsertAfterNode( lastNewBlock || currentBlock, doc.createElement( currentBlock.nodeName ) ) ; |
| 920 | | continue ; |
| 921 | | } |
| 922 | | |
| 923 | | if ( lastNewBlock ) |
| 924 | | { |
| 925 | | FCKDomTools.MoveNode( cursor, lastNewBlock ) ; |
| 926 | | j-- ; // restart at current index at next iteration |
| 927 | | } |
| | 935 | if ( previousPreBlock ) |
| | 936 | this._CheckAndMergePre( previousPreBlock, newBlock ) ; |
| | 937 | previousPreBlock = newBlock ; |