| 2832 | | HTMLArea.prototype.getParentElement = function(sel) { |
| 2833 | | if(typeof sel == 'undefined') |
| 2834 | | { |
| 2835 | | sel = this._getSelection(); |
| 2836 | | } |
| 2837 | | var range = this._createRange(sel); |
| 2838 | | if (HTMLArea.is_ie) { |
| 2839 | | switch (sel.type) { |
| 2840 | | case "Text": |
| 2841 | | // try to circumvent a bug in IE: |
| 2842 | | // the parent returned is not always the real parent element |
| 2843 | | var parent = range.parentElement(); |
| 2844 | | while (true) |
| 2845 | | { |
| 2846 | | var TestRange = range.duplicate(); |
| 2847 | | TestRange.moveToElementText(parent); |
| 2848 | | if (TestRange.inRange(range)) break; |
| 2849 | | if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) break; |
| 2850 | | parent = parent.parentElement; |
| 2851 | | } |
| 2852 | | return parent; |
| 2853 | | case "None": |
| 2854 | | // It seems that even for selection of type "None", |
| 2855 | | // there _is_ a parent element and it's value is not |
| 2856 | | // only correct, but very important to us. MSIE is |
| 2857 | | // certainly the buggiest browser in the world and I |
| 2858 | | // wonder, God, how can Earth stand it? |
| 2859 | | return range.parentElement(); |
| 2860 | | case "Control": |
| 2861 | | return range.item(0); |
| 2862 | | default: |
| 2863 | | return this._doc.body; |
| 2864 | | } |
| 2865 | | } else try { |
| 2866 | | var p = range.commonAncestorContainer; |
| 2867 | | if (!range.collapsed && range.startContainer == range.endContainer && |
| 2868 | | range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes()) |
| 2869 | | p = range.startContainer.childNodes[range.startOffset]; |
| 2870 | | /* |
| 2871 | | alert(range.startContainer + ":" + range.startOffset + "\n" + |
| 2872 | | range.endContainer + ":" + range.endOffset); |
| 2873 | | */ |
| 2874 | | while (p.nodeType == 3) { |
| 2875 | | p = p.parentNode; |
| 2876 | | } |
| 2877 | | return p; |
| 2878 | | } catch (e) { |
| 2879 | | return null; |
| 2880 | | } |
| 2881 | | }; |
| | 2832 | if (HTMLArea.is_ie) |
| | 2833 | { |
| | 2834 | HTMLArea.prototype.getParentElement = function(sel) |
| | 2835 | { |
| | 2836 | if(typeof sel == 'undefined') |
| | 2837 | { |
| | 2838 | sel = this._getSelection(); |
| | 2839 | } |
| | 2840 | var range = this._createRange(sel); |
| | 2841 | switch (sel.type) |
| | 2842 | { |
| | 2843 | case "Text": |
| | 2844 | // try to circumvent a bug in IE: |
| | 2845 | // the parent returned is not always the real parent element |
| | 2846 | var parent = range.parentElement(); |
| | 2847 | while (true) |
| | 2848 | { |
| | 2849 | var TestRange = range.duplicate(); |
| | 2850 | TestRange.moveToElementText(parent); |
| | 2851 | if (TestRange.inRange(range)) |
| | 2852 | { |
| | 2853 | break; |
| | 2854 | } |
| | 2855 | if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) |
| | 2856 | { |
| | 2857 | break; |
| | 2858 | } |
| | 2859 | parent = parent.parentElement; |
| | 2860 | } |
| | 2861 | return parent; |
| | 2862 | case "None": |
| | 2863 | // It seems that even for selection of type "None", |
| | 2864 | // there _is_ a parent element and it's value is not |
| | 2865 | // only correct, but very important to us. MSIE is |
| | 2866 | // certainly the buggiest browser in the world and I |
| | 2867 | // wonder, God, how can Earth stand it? |
| | 2868 | return range.parentElement(); |
| | 2869 | case "Control": |
| | 2870 | return range.item(0); |
| | 2871 | default: |
| | 2872 | return this._doc.body; |
| | 2873 | } |
| | 2874 | }; |
| | 2875 | } |
| | 2876 | else |
| | 2877 | { |
| | 2878 | HTMLArea.prototype.getParentElement = function(sel) |
| | 2879 | { |
| | 2880 | if(typeof sel == 'undefined') |
| | 2881 | { |
| | 2882 | sel = this._getSelection(); |
| | 2883 | } |
| | 2884 | var range = this._createRange(sel); |
| | 2885 | try |
| | 2886 | { |
| | 2887 | var p = range.commonAncestorContainer; |
| | 2888 | if (!range.collapsed && range.startContainer == range.endContainer && |
| | 2889 | range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes()) |
| | 2890 | { |
| | 2891 | p = range.startContainer.childNodes[range.startOffset]; |
| | 2892 | } |
| | 2893 | /* |
| | 2894 | alert(range.startContainer + ":" + range.startOffset + "\n" + |
| | 2895 | range.endContainer + ":" + range.endOffset); |
| | 2896 | */ |
| | 2897 | while (p.nodeType == 3) |
| | 2898 | { |
| | 2899 | p = p.parentNode; |
| | 2900 | } |
| | 2901 | return p; |
| | 2902 | } |
| | 2903 | catch (e) |
| | 2904 | { |
| | 2905 | return null; |
| | 2906 | } |
| | 2907 | }; |
| | 2908 | } |