To make the editor fit in our project we made some changes that we want to share with others:
(When a text had been selected and the view is changed from or to source it tries to recreate the selection under the new view)
fck_editor.js:
function switchEditMode()
{
var bSource = (trSource.style.display == "none") ;
if (bSource)
{
// ** Non Orrigional Code **
var sOrigHTML = "";
oSel = objContent.DOM.selection;
if(oSel){
if(oSel.type == "Text"){
oRangeStart = oSel.createRange();
oRangeEnd = oRangeStart.duplicate();
oRangeStart.collapse(true);
oRangeEnd.collapse(false);
oRangeStart.text = "%SelStart%";
oRangeEnd.text = "%SelEnd%"
}
if(oSel.type == "Control"){
var oRange = oSel.createRange() ;
oRange.item(0).insertAdjacentText("beforeBegin", "%SelStart%");
oRange.item(oRange.length - 1).insertAdjacentText("afterEnd", "%SelEnd%");
}
}
// ** Non Orrigional Code End **
txtSource.value = objContent.DOM.body.innerHTML ;
}
else
{
// ** Non Orrigional Code **
txtSource.focus();
var oSel = document.selection;
if(oSel){
if(oSel.type == "Text"){
oRangeStart = oSel.createRange();
oRangeEnd = oRangeStart.duplicate();
oRangeStart.collapse(true);
oRangeEnd.collapse(false);
oRangeStart.text = "%SelStart%";
oRangeEnd.text = "%SelEnd%"
}
}
// ** Non Orrigional Code End **
objContent.DOM.body.innerHTML = "<div id=__tmpFCKRemove__> </div>" + txtSource.value ;
objContent.DOM.getElementById('__tmpFCKRemove__').removeNode(true) ;
}
trSource.style.display = bSource ? "inline" : "none" ;
// ** Non Orrigional Code **
if(bSource){
document.selection.empty();
var oStart = txtSource.createTextRange();
}else{
objContent.DOM.selection.empty();
oStart = objContent.DOM.body.createTextRange();
}
oEnd = oStart.duplicate();
if(oStart.findText("%SelStart%")){
oStart.text = "";
if(oEnd.findText("%SelEnd%")){
oEnd.text = "";
oStart.setEndPoint("EndToEnd", oEnd);
oStart.select();
oStart.scrollIntoView();
}else{
if(bSource){
txtSource.value = delSelSigns(txtSource.value);
}else{
objContent.DOM.body.innerHTML = delSelSigns(objContent.DOM.body.innerHTML);
}
}
}else{
if(bSource){
txtSource.value = delSelSigns(txtSource.value);
}else{
objContent.DOM.body.innerHTML = delSelSigns(objContent.DOM.body.innerHTML);
}
}
// ** Non Orrigional Code End **
trEditor.style.display = bSource ? "none" : "inline" ;
events.fireEvent('onViewMode', bSource) ;
}
// ** Non Orrigional Code **
function delSelSigns(sText){
sText = sText.replace(/%SelStart%/g, "");
sText = sText.replace(/%SelEnd%/g, "");
return sText;
}
// ** Non Orrigional Code End **
(When a text had been selected and the view is changed from or to source it tries to recreate the selection under the new view)
fck_editor.js:
function switchEditMode()
{
var bSource = (trSource.style.display == "none") ;
if (bSource)
{
// ** Non Orrigional Code **
var sOrigHTML = "";
oSel = objContent.DOM.selection;
if(oSel){
if(oSel.type == "Text"){
oRangeStart = oSel.createRange();
oRangeEnd = oRangeStart.duplicate();
oRangeStart.collapse(true);
oRangeEnd.collapse(false);
oRangeStart.text = "%SelStart%";
oRangeEnd.text = "%SelEnd%"
}
if(oSel.type == "Control"){
var oRange = oSel.createRange() ;
oRange.item(0).insertAdjacentText("beforeBegin", "%SelStart%");
oRange.item(oRange.length - 1).insertAdjacentText("afterEnd", "%SelEnd%");
}
}
// ** Non Orrigional Code End **
txtSource.value = objContent.DOM.body.innerHTML ;
}
else
{
// ** Non Orrigional Code **
txtSource.focus();
var oSel = document.selection;
if(oSel){
if(oSel.type == "Text"){
oRangeStart = oSel.createRange();
oRangeEnd = oRangeStart.duplicate();
oRangeStart.collapse(true);
oRangeEnd.collapse(false);
oRangeStart.text = "%SelStart%";
oRangeEnd.text = "%SelEnd%"
}
}
// ** Non Orrigional Code End **
objContent.DOM.body.innerHTML = "<div id=__tmpFCKRemove__> </div>" + txtSource.value ;
objContent.DOM.getElementById('__tmpFCKRemove__').removeNode(true) ;
}
trSource.style.display = bSource ? "inline" : "none" ;
// ** Non Orrigional Code **
if(bSource){
document.selection.empty();
var oStart = txtSource.createTextRange();
}else{
objContent.DOM.selection.empty();
oStart = objContent.DOM.body.createTextRange();
}
oEnd = oStart.duplicate();
if(oStart.findText("%SelStart%")){
oStart.text = "";
if(oEnd.findText("%SelEnd%")){
oEnd.text = "";
oStart.setEndPoint("EndToEnd", oEnd);
oStart.select();
oStart.scrollIntoView();
}else{
if(bSource){
txtSource.value = delSelSigns(txtSource.value);
}else{
objContent.DOM.body.innerHTML = delSelSigns(objContent.DOM.body.innerHTML);
}
}
}else{
if(bSource){
txtSource.value = delSelSigns(txtSource.value);
}else{
objContent.DOM.body.innerHTML = delSelSigns(objContent.DOM.body.innerHTML);
}
}
// ** Non Orrigional Code End **
trEditor.style.display = bSource ? "none" : "inline" ;
events.fireEvent('onViewMode', bSource) ;
}
// ** Non Orrigional Code **
function delSelSigns(sText){
sText = sText.replace(/%SelStart%/g, "");
sText = sText.replace(/%SelEnd%/g, "");
return sText;
}
// ** Non Orrigional Code End **
Custom feature: Switchsource keep selection
That is super cool.
Keep up the good work
Custom feature: Switchsource keep selection
Great work
you might add
if(oSel.type == "None") {
var oRange = oSel.createRange() ;
oRange.text ="%SelStart%%SelEnd%"
}
to keep the insertion point if no selection
Custom feature: Switchsource keep selection
could you please post the whole file "fckeditor.js"? - I can't get it to run... my debugger shows a syntax error
thx
markus
Done!
I've uploaded the file at:
http://sourceforge.net/tracker/index.ph ... tid=543655