日期:2014-05-16  浏览次数:20520 次

FCKEditor插件(自动排版)移植至CKEditor下,高分求救(急)
公司网站要将FCKEditor编辑器升级至CKEditor,同时希望将插件也一并移植,难度不大,但是我英文很不好,试了很久都不成功!希望各位前辈帮忙.(Email:170238168@qq.com)
贴出部分代码
//格式化
function FormatText(bodyname) {
  var myeditor = FCKeditorAPI.GetInstance(bodyname);
  if (myeditor.EditMode==FCK_EDITMODE_WYSIWYG){
  var temps = new Array();

  isPart = false; //暂时无法实现局部格式化
  if (!isPart) {
  var imgs = FCKeditorAPI.GetInstance(bodyname).EditorDocument.images;
  if (imgs != null && imgs.length > 0) {
  for (j = 0; j < imgs.length; j++) {
  var t = document.createElement("IMG");
  t.alt = imgs[j].alt;
  t.src = imgs[j].src;
  t.width = imgs[j].width;
  t.height = imgs[j].height;
  t.align = imgs[j].align;
  temps[temps.length] = t;
  }
  var formatImgCount = 0;
  for (j = 0; j < imgs.length;) {
  imgs[j].outerHTML = "#FormatImgID_" + formatImgCount + "#";
  formatImgCount++;
  }
  }
var strongarray = new Array();
var strongcount = 0;
for(var i=0;i<myeditor.EditorDocument.body.getElementsByTagName('b').length;i++){
strongarray[strongcount] = myeditor.EditorDocument.body.getElementsByTagName('b')[i].innerText.trim();
myeditor.EditorDocument.body.getElementsByTagName('b')[i].innerHTML = "#FormatStrongID_" + strongcount + "#";
strongcount++;
}

for(var i=0;i<myeditor.EditorDocument.body.getElementsByTagName('strong').length;i++){
strongarray[strongcount] = myeditor.EditorDocument.body.getElementsByTagName('strong')[i].innerText.trim();
myeditor.EditorDocument.body.getElementsByTagName('strong')[i].innerHTML = "#FormatStrongID_" + strongcount + "#";
strongcount++;
}

  var html = processFormatText(myeditor.EditorDocument.body.innerText);
  if (temps != null && temps.length > 0) {
  for (j = 0; j < temps.length; j++) {
  var imghtml = "<p align=\"center\"><img src=\"" + temps[j].src + "\" alt=\"" + temps[j].alt + "\" width=\"" + temps[j].width + "\" height=\"" + temps[j].height + "\" align=\"" + temps[j].align + "\" border=\"0\"></p>";
  html = html.replace("#FormatImgID_" + j + "#", imghtml);
  }
  }

for(var i=0;i<strongcount;i++){
html = html.replace("#FormatStrongID_" + i + "#", "<strong>"+strongarray[i]+"</strong>");
}

while(html.indexOf("</p></p>")!=-1) html=html.replace("</p></p>","</p>");
while(html.indexOf('<p><p align="center">')!=-1) html=html.replace('<p><p align="center">','<p align="center">');

SetEditorContents(bodyname, html);

  } else {

  }
  }else{
alert('必须在设计模式下操作!');
  }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

FCK编辑器增强插件
 http://www.ittang.