I have to develop a plugin that is supposed to wrap selected text and objects inside a <fieldset> tag. However, I have troubles when I try to get the HTML code from the selected area. I am using the following function extracted from the abbr-tag developed by Koen.
FCKSelection.GetSelectedHTML = function() {
if( FCKBrowserInfo.IsIE) {
var oRange = FCK.EditorDocument.selection.createRange() ;
//if an object like a table is deleted, the call to GetType before getting again a range returns Control
switch ( this.GetType() ) {
case 'Control' :
return oRange.item(0).outerHTML;
case 'None' :
return '' ;
default :
return oRange.htmlText ;
}
}
else if ( FCKBrowserInfo.IsGecko ) { // Mozilla, Safari
var oSelection = FCK.EditorWindow.getSelection();
//Gecko doesn't provide a function to get the innerHTML of a selection,
//so we must clone the selection to a temporary element and check that innerHTML
var e = FCK.EditorDocument.createElement( 'DIV' );
for ( var i = 0 ; i < oSelection.rangeCount ; i++ ) {
e.appendChild( oSelection.getRangeAt(i).cloneContents() );
}
return e.innerHTML;
}
}
This code works fine on Firefox but it always return an empy string on IE. I have read that this problem happens with FCKEditor 2.6 because of the floating dialog iframe. I have tried to use FCKSelection.GetSelection() but it doesn't work either.
Please could you help me, I have to solve this problem as soon as possible.
Thank you
FCKSelection.GetSelectedHTML = function() {
if( FCKBrowserInfo.IsIE) {
var oRange = FCK.EditorDocument.selection.createRange() ;
//if an object like a table is deleted, the call to GetType before getting again a range returns Control
switch ( this.GetType() ) {
case 'Control' :
return oRange.item(0).outerHTML;
case 'None' :
return '' ;
default :
return oRange.htmlText ;
}
}
else if ( FCKBrowserInfo.IsGecko ) { // Mozilla, Safari
var oSelection = FCK.EditorWindow.getSelection();
//Gecko doesn't provide a function to get the innerHTML of a selection,
//so we must clone the selection to a temporary element and check that innerHTML
var e = FCK.EditorDocument.createElement( 'DIV' );
for ( var i = 0 ; i < oSelection.rangeCount ; i++ ) {
e.appendChild( oSelection.getRangeAt(i).cloneContents() );
}
return e.innerHTML;
}
}
This code works fine on Firefox but it always return an empy string on IE. I have read that this problem happens with FCKEditor 2.6 because of the floating dialog iframe. I have tried to use FCKSelection.GetSelection() but it doesn't work either.
Please could you help me, I have to solve this problem as soon as possible.
Thank you