| 2819 | | case "Text": |
| 2820 | | // try to circumvent a bug in IE: |
| 2821 | | // the parent returned is not always the real parent element |
| 2822 | | var parent = range.parentElement(); |
| 2823 | | while (true) |
| 2824 | | { |
| 2825 | | var TestRange = range.duplicate(); |
| 2826 | | TestRange.moveToElementText(parent); |
| 2827 | | if (TestRange.inRange(range)) break; |
| 2828 | | if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) break; |
| 2829 | | parent = parent.parentElement; |
| | 2816 | case "Text": |
| | 2817 | // try to circumvent a bug in IE: |
| | 2818 | // the parent returned is not always the real parent element |
| | 2819 | var parent = range.parentElement(); |
| | 2820 | while (true) |
| | 2821 | { |
| | 2822 | var TestRange = range.duplicate(); |
| | 2823 | TestRange.moveToElementText(parent); |
| | 2824 | if (TestRange.inRange(range)) break; |
| | 2825 | if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) break; |
| | 2826 | parent = parent.parentElement; |
| | 2827 | } |
| | 2828 | return parent; |
| | 2829 | case "None": |
| | 2830 | // It seems that even for selection of type "None", |
| | 2831 | // there _is_ a parent element and it's value is not |
| | 2832 | // only correct, but very important to us. MSIE is |
| | 2833 | // certainly the buggiest browser in the world and I |
| | 2834 | // wonder, God, how can Earth stand it? |
| | 2835 | return range.parentElement(); |
| | 2836 | case "Control": |
| | 2837 | return range.item(0); |
| | 2838 | default: |
| | 2839 | return this._doc.body; |
| | 2840 | } |
| | 2841 | }; |
| | 2842 | } else { |
| | 2843 | HTMLArea.prototype.getParentElement = function(sel) { |
| | 2844 | if(typeof sel == 'undefined') { sel = this._getSelection(); } |
| | 2845 | var range = this._createRange(sel); |
| | 2846 | try { |
| | 2847 | var p = range.commonAncestorContainer; |
| | 2848 | if (!range.collapsed && range.startContainer == range.endContainer && |
| | 2849 | range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes()) |
| | 2850 | p = range.startContainer.childNodes[range.startOffset]; |
| | 2851 | /* |
| | 2852 | alert(range.startContainer + ":" + range.startOffset + "\n" + |
| | 2853 | range.endContainer + ":" + range.endOffset); |
| | 2854 | */ |
| | 2855 | while (p.nodeType == 3) { |
| | 2856 | p = p.parentNode; |