| 68 | | var oNode = oSel.anchorNode ; |
| 69 | | |
| 70 | | while ( oNode && oNode.nodeType != 1 ) |
| 71 | | oNode = oNode.parentNode ; |
| 72 | | |
| 73 | | return oNode ; |
| | 68 | // make the common case fast - for collapsed/nearly collapsed selections just return anchor.parent. |
| | 69 | if ( oSel.anchorNode == oSel.focusNode ) |
| | 70 | return oSel.anchorNode.parentNode ; |
| | 71 | |
| | 72 | // looks like we're having a large selection here. To make the behavior same as IE's TextRange.parentElement(), |
| | 73 | // we need to find the nearest ancestor node which encapsulates both the beginning and the end of the selection. |
| | 74 | var anchorPath = new FCKElementPath( oSel.anchorNode ) ; |
| | 75 | var focusPath = new FCKElementPath( oSel.focusNode ) ; |
| | 76 | var deepPath = null ; |
| | 77 | var shallowPath = null ; |
| | 78 | if ( anchorPath.Elements.length > focusPath.Elements.length ) |
| | 79 | { |
| | 80 | deepPath = anchorPath.Elements ; |
| | 81 | shallowPath = focusPath.Elements ; |
| | 82 | } |
| | 83 | else |
| | 84 | { |
| | 85 | deepPath = focusPath.Elements ; |
| | 86 | shallowPath = anchorPath.Elements ; |
| | 87 | } |
| | 88 | |
| | 89 | var deepPathBase = deepPath.length - shallowPath.length ; |
| | 90 | for( var i = 0 ; i < shallowPath.length ; i++) |
| | 91 | { |
| | 92 | if ( deepPath[deepPathBase + i] == shallowPath[i]) |
| | 93 | return shallowPath[i]; |
| | 94 | } |
| | 95 | return null ; |