| 922 | }, |
| 923 | |
| 924 | /* |
| 925 | * This is a pretty funny function. This is needed because of the way |
| 926 | * block selections are handled in MS Word. For example, if you try to |
| 927 | * convert the following into a list (^ delimits selection): |
| 928 | * <p>^Line 1<br>Line 2<br>^Line 3</p> |
| 929 | * Then it should become: |
| 930 | * <ul><li>Line 1</li><li>Line 2</li></ul><p>Line 3</p> |
| 931 | * |
| 932 | * Or this: |
| 933 | * <p>^Line 1</p><p>Line 2</p><p>^Line 3</p> |
| 934 | * Should become: |
| 935 | * <ul><li>Line 1</li></li>Line 2</li></ul><p>Line 3</p> |
| 936 | * |
| 937 | * However, we need to be careful when there are multiple <br>s: |
| 938 | * <p>^Line 1<br>Line 2<br><br><br>^<br>Line 3</p> |
| 939 | * Should become: |
| 940 | * <ul><li>Line 1</li><li>Line 2</li><li></li><li></li></ul> |
| 941 | * <p><br>Line 3</p> |
| 942 | * |
| 943 | * Other cases to be careful: |
| 944 | * <p>^Line 1<br>Lin<b>e 2<br><i><u>^Lin</u></i></b>e 3</p> |
| 945 | * <p>^Line 1<br>Line 2<br>^<img>Line 3</p> |
| 946 | * <p>Line 1^<br>Line 2<br>Line 3^</p> |
| 947 | */ |
| 948 | Trim : function() |
| 949 | { |
| 950 | if ( this.CheckIsCollapsed() ) |
| 951 | return ; |
| 952 | |
| 953 | var endContainer = this._Range.endContainer ; |
| 954 | var endOffset = this._Range.endOffset ; |
| 955 | var startNode = this.StartNode ; |
| 956 | |
| 957 | if ( endContainer.nodeType == 3 ) |
| 958 | { |
| 959 | if ( endOffset > 0 ) |
| 960 | return ; |
| 961 | |
| 962 | var currentNode = endContainer ; |
| 963 | var commonParent = FCKDomTools.GetCommonParents( endContainer, startNode ).pop() ; |
| 964 | while ( FCKDomTools.CheckIsEditable( currentNode.parentNode ) |
| 965 | && currentNode == currentNode.parentNode.childNodes[0] |
| 966 | && currentNode.parentNode != commonParent ) |
| 967 | currentNode = currentNode.parentNode ; |
| 968 | |
| 969 | if ( currentNode.previousSibling && currentNode.previousSibling.nodeName.IEquals( 'br' ) ) |
| 970 | this.SetEnd( currentNode.previousSibling, 3 ) ; |
| 971 | |
| 972 | if ( FCKListsLib.BlockElements[ currentNode.nodeName.toLowerCase() ] ) |
| 973 | this.SetEnd( currentNode, 3 ) ; |
| 974 | } |
| 975 | else if ( endContainer.nodeType == 1 ) |
| 976 | { |
| 977 | var currentNode = endContainer.childNodes[ endOffset ] || endContainer.childNodes[ endOffset - 1 ] ; |
| 978 | var commonParent = FCKDomTools.GetCommonParents( currentNode, startNode ).pop() ; |
| 979 | while ( FCKDomTools.CheckIsEditable( currentNode.parentNode ) |
| 980 | && currentNode == currentNode.parentNode.childNodes[0] |
| 981 | && currentNode.parentNode != commonParent ) |
| 982 | currentNode = currentNode.parentNode ; |
| 983 | |
| 984 | var prevNode = ( endOffset >= endContainer.length ? currentNode : currentNode.previousSibling ) ; |
| 985 | |
| 986 | if ( prevNode && prevNode.nodeName.IEquals( 'br' ) ) |
| 987 | this.SetEnd( prevNode, 3 ) ; |
| 988 | |
| 989 | if ( FCKListsLib.BlockElements[ currentNode ] ) |
| 990 | this.SetEnd( currentNode, 3 ) ; |
| 991 | } |