国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
關(guān)于eWebEditor中,完整html文檔會被自動截取的BUG修正...(TSYS中也用到了) - Apc001‘s Blog <當(dāng)哩個當(dāng)..>

關(guān)于eWebEditor中,完整html文檔會被自動截取的BUG修正...(TSYS中也用到了)

[ 2006-07-09 18:20:09 | 作者: 明皓 ]
字體大小: | |
問題是這樣.
有人用編輯器,不只只是編輯內(nèi)容而已,
更有的用來做整頁模板,這樣比如:
<html>
<somecode....>
<body>
bodyCode....
</body>
</html>

在代碼模式中粘貼以上代碼,然后在代碼->編輯->代碼 這樣切換,看到效果了吧?只剩下少量的代碼了.
在別的模式切換也一樣....這就是一個小bug了.

別的不多了.看代碼吧.

下面是我的editor.js 代碼...懶的人,直接拷過去用.我的是最新的 3.8 Free 版.
閑著沒事的,可以看下...

/* eWebEditor - eWebSoft在線編輯器 */

// 當(dāng)前模式
var sCurrMode = null;
var bEditMode = null;
// 連接對象
var oLinkField = null;

//頭尾部對象
var oTopCode =null;
var oBottomCode =null;

// 瀏覽器版本檢測
var BrowserInfo = new Object() ;
BrowserInfo.MajorVer = navigator.appVersion.match(/MSIE (.)/)[1] ;
BrowserInfo.MinorVer = navigator.appVersion.match(/MSIE .\.(.)/)[1] ;
BrowserInfo.IsIE55OrMore = BrowserInfo.MajorVer >= 6 || ( BrowserInfo.MajorVer >= 5 && BrowserInfo.MinorVer >= 5 ) ;

var yToolbars = new Array(); // 工具欄數(shù)組

// 當(dāng)文檔完全調(diào)入時,進(jìn)行初始化
var bInitialized = false;
function document.onreadystatechange(){
  if (document.readyState!="complete") return;
  if (bInitialized) return;
  bInitialized = true;

  var i, s, curr;

  // 初始每個工具欄
  for (i=0; i<document.body.all.length;i++){
    curr=document.body.all[i];
    if (curr.className == "yToolbar"){
      InitTB(curr);
      yToolbars[yToolbars.length] = curr;
    }
  }

  oLinkField = parent.document.getElementsByName(sLinkFieldName)[0];
  if (!config.License){
    try{
      eWebEditor_License.innerHTML = "&copy; <a href='http://www.eWebSoft.com' target='_blank'><font color=#000000>eWebSoft.com</font></a>";
    }
    catch(e){
    }
  }

  // IE5.5以下版本只能使用純文本模式
  if (!BrowserInfo.IsIE55OrMore){
    config.InitMode = "TEXT";
  }
  
  if (ContentFlag.value=="0") {
    ContentEdit.value = oLinkField.value;
    ContentLoad.value = oLinkField.value;
    ModeEdit.value = config.InitMode;
    ContentFlag.value = "1";
  }

  setMode(ModeEdit.value);
  setLinkedField() ;
}

// 初始化一個工具欄上的按鈕
function InitBtn(btn) {
  btn.onmouseover = BtnMouseOver;
  btn.onmouseout = BtnMouseOut;
  btn.onmousedown = BtnMouseDown;
  btn.onmouseup = BtnMouseUp;
  btn.ondragstart = YCancelEvent;
  btn.onselectstart = YCancelEvent;
  btn.onselect = YCancelEvent;
  btn.YUSERONCLICK = btn.onclick;
  btn.onclick = YCancelEvent;
  btn.YINITIALIZED = true;
  return true;
}

//Initialize a toolbar.
function InitTB(y) {
  // Set initial size of toolbar to that of the handle
  y.TBWidth = 0;
    
  // Populate the toolbar with its contents
  if (! PopulateTB(y)) return false;
  
  // Set the toolbar width and put in the handle
  y.style.posWidth = y.TBWidth;
  
  return true;
}


// Hander that simply cancels an event
function YCancelEvent() {
  event.returnValue=false;
  event.cancelBubble=true;
  return false;
}

// Toolbar button onmouseover handler
function BtnMouseOver() {
  if (event.srcElement.tagName != "IMG") return false;
  var image = event.srcElement;
  var element = image.parentElement;
  
  // Change button look based on current state of image.
  if (image.className == "Ico") element.className = "BtnMouseOverUp";
  else if (image.className == "IcoDown") element.className = "BtnMouseOverDown";

  event.cancelBubble = true;
}

// Toolbar button onmouseout handler
function BtnMouseOut() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;
  yRaisedElement = null;
  
  element.className = "Btn";
  image.className = "Ico";

  event.cancelBubble = true;
}

// Toolbar button onmousedown handler
function BtnMouseDown() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    event.returnValue=false;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;

  element.className = "BtnMouseOverDown";
  image.className = "IcoDown";

  event.cancelBubble = true;
  event.returnValue=false;
  return false;
}

// Toolbar button onmouseup handler
function BtnMouseUp() {
  if (event.srcElement.tagName != "IMG") {
    event.cancelBubble = true;
    return false;
  }

  var image = event.srcElement;
  var element = image.parentElement;

  if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");

  element.className = "BtnMouseOverUp";
  image.className = "Ico";

  event.cancelBubble = true;
  return false;
}

// Populate a toolbar with the elements within it
function PopulateTB(y) {
  var i, elements, element;

  // Iterate through all the top-level elements in the toolbar
  elements = y.children;
  for (i=0; i<elements.length; i++) {
    element = elements[i];
    if (element.tagName == "SCRIPT" || element.tagName == "!") continue;
    
    switch (element.className) {
    case "Btn":
      if (element.YINITIALIZED == null) {
        if (! InitBtn(element)) {
          alert("Problem initializing:" + element.id);
          return false;
        }
      }
      
      element.style.posLeft = y.TBWidth;
      y.TBWidth += element.offsetWidth + 1;
      break;
      
    case "TBGen":
      element.style.posLeft = y.TBWidth;
      y.TBWidth += element.offsetWidth + 1;
      break;
      
    case "TBSep":
      element.style.posLeft = y.TBWidth + 2;
      y.TBWidth += 5;
      break;
      
    case "TBHandle":
      element.style.posLeft = 2;
      y.TBWidth += element.offsetWidth + 7;
      break;
      
    default:
      alert("Invalid class: " + element.className + " on Element: " + element.id + " <" + element.tagName + ">");
      return false;
    }
  }

  y.TBWidth += 1;
  return true;
}


// 設(shè)置所屬表單的提交或reset事件
function setLinkedField() {
  if (! oLinkField) return ;
  var oForm = oLinkField.form ;
  if (!oForm) return ;
  // 附加submit事件
  oForm.attachEvent("onsubmit", AttachSubmit) ;
  if (! oForm.submitEditor) oForm.submitEditor = new Array() ;
  oForm.submitEditor[oForm.submitEditor.length] = AttachSubmit ;
  if (! oForm.originalSubmit) {
    oForm.originalSubmit = oForm.submit ;
    oForm.submit = function() {
      if (this.submitEditor) {
        for (var i = 0 ; i < this.submitEditor.length ; i++) {
          this.submitEditor[i]() ;
        }
      }
      this.originalSubmit() ;
    }
  }
  // 附加reset事件
  oForm.attachEvent("onreset", AttachReset) ;
  if (! oForm.resetEditor) oForm.resetEditor = new Array() ;
  oForm.resetEditor[oForm.resetEditor.length] = AttachReset ;
  if (! oForm.originalReset) {
    oForm.originalReset = oForm.reset ;
    oForm.reset = function() {
      if (this.resetEditor) {
        for (var i = 0 ; i < this.resetEditor.length ; i++) {
          this.resetEditor[i]() ;
        }
      }
      this.originalReset() ;
    }
  }
}

// 附加submit提交事件,大表單數(shù)據(jù)提交,保存eWebEditor中的內(nèi)容
function AttachSubmit() {
  var oForm = oLinkField.form ;
  if (!oForm) return;
  var html = getHTML();
  ContentEdit.value = html;
  if (sCurrMode=="TEXT"){
    html = HTMLEncode(html);
  }
  splitTextField(oLinkField, html);
}

// 表單提交
function doSubmit(){
  var oForm = oLinkField.form ;
  if (!oForm) return ;
  oForm.submit();
}

// 附加Reset事件
function AttachReset() {
  if(bEditMode){
    eWebEditor.document.body.innerHTML = ContentLoad.value;
  }else{
    eWebEditor.document.body.innerText = ContentLoad.value;
  }
}

// 顯示幫助
function onHelp(){
  ShowDialog('dialog/help.htm','400','300');
  return false;
}

// 粘貼時自動檢測是否來源于Word格式
function onPaste() {
  if (sCurrMode=="VIEW") return false;

  if (sCurrMode=="EDIT"){
    var sHTML = GetClipboardHTML() ;
    if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) {
      var re = /<\w[^>]* class="?MsoNormal"?/gi ;
      if ( re.test(sHTML)){
        if ( confirm( "你要粘貼的內(nèi)容好象是從Word中拷出來的,是否要先清除Word格式再粘貼?" ) ){
          cleanAndPaste( sHTML ) ;
          return false ;
        }
      }
    }
    eWebEditor.document.selection.createRange().pasteHTML(sHTML) ;
    return false;
  }else{
    eWebEditor.document.selection.createRange().pasteHTML(HTMLEncode( clipboardData.getData("Text"))) ;
    return false;
  }
  
}

// 快捷鍵
function onKeyDown(event){
  var key = String.fromCharCode(event.keyCode).toUpperCase();

  // F2:顯示或隱藏指導(dǎo)方針
  if (event.keyCode==113){
    showBorders();
    return false;
  }
  if (event.ctrlKey){
    // Ctrl+Enter:提交
    if (event.keyCode==10){
      doSubmit();
      return false;
    }
    // Ctrl++:增加編輯區(qū)
    if (key=="+"){
      sizeChange(300);
      return false;
    }
    // Ctrl+-:減小編輯區(qū)
    if (key=="-"){
      sizeChange(-300);
      return false;
    }
    // Ctrl+1:代碼模式
    if (key=="1"){
      setMode("CODE");
      return false;
    }
    // Ctrl+2:設(shè)計(jì)模式
    if (key=="2"){
      setMode("EDIT");
      return false;
    }
    // Ctrl+3:純文本
    if (key=="3"){
      setMode("TEXT");
      return false;
    }
    // Ctrl+4:預(yù)覽
    if (key=="4"){
      setMode("VIEW");
      return false;
    }
  }

  switch(sCurrMode){
  case "VIEW":
    return true;
    break;
  case "EDIT":
    if (event.ctrlKey){
      // Ctrl+D:從Word粘貼
      if (key == "D"){
        PasteWord();
        return false;
      }
      // Ctrl+R:查找替換
      if (key == "R"){
        findReplace();
        return false;
      }
      // Ctrl+Z:Undo
      if (key == "Z"){
        goHistory(-1);
        return false;
      }
      // Ctrl+Y:Redo
      if (key == "Y"){
        goHistory(1);
        return false;
      }
    }
    if(!event.ctrlKey && event.keyCode != 90 && event.keyCode != 89) {
      if (event.keyCode == 32 || event.keyCode == 13){
        saveHistory()
      }
    }
    return true;
    break;
  default:
    if (event.keyCode==13){
      var sel = eWebEditor.document.selection.createRange();
      sel.pasteHTML("<BR>");
      event.cancelBubble = true;
      event.returnValue = false;
      sel.select();
      sel.moveEnd("character", 1);
      sel.moveStart("character", 1);
      sel.collapse(false);
      return false;
    }
    // 屏蔽事件
    if (event.ctrlKey){
      // Ctrl+B,I,U
      if ((key == "B")||(key == "I")||(key == "U")){
        return false;
      }
    }

  }
}

// 取剪粘板中的HTML格式數(shù)據(jù)
function GetClipboardHTML() {
  var oDiv = document.getElementById("eWebEditor_Temp_HTML")
  oDiv.innerHTML = "" ;
  
  var oTextRange = document.body.createTextRange() ;
  oTextRange.moveToElementText(oDiv) ;
  oTextRange.execCommand("Paste") ;
  
  var sData = oDiv.innerHTML ;
  oDiv.innerHTML = "" ;
  
  return sData ;
}

// 清除WORD冗余格式并粘貼
function cleanAndPaste( html ) {
  // Remove all SPAN tags
  html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
  // Remove Class attributes
  html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  // Remove Style attributes
  html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
  // Remove Lang attributes
  html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
  // Remove XML elements and declarations
  html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
  // Remove Tags with XML namespace declarations: <o:p></o:p>
  html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
  // Replace the  
  html = html.replace(/ /, " " );
  // Transform <P> to <DIV>
  var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;  // Different because of a IE 5.0 error
  html = html.replace( re, "<div$2</div>" ) ;
  
  insertHTML( html ) ;
}

// 在當(dāng)前文檔位置插入.
function insertHTML(html) {
  if (isModeView()) return false;
  if (eWebEditor.document.selection.type.toLowerCase() != "none"){
    eWebEditor.document.selection.clear() ;
  }
  if (sCurrMode!="EDIT"){
    html=HTMLEncode(html);
  }
  eWebEditor.document.selection.createRange().pasteHTML(html) ;
}

// 設(shè)置編輯器的內(nèi)容
function setHTML(html) {
  ContentEdit.value = html;
  switch (sCurrMode){
  case "CODE":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=oTopCode + html + oBottomCode;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "EDIT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 && haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中間的長度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }
    //alert(config.StyleEditorHeader);
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.execCommand("2D-Position",true,true);
    eWebEditor.document.execCommand("MultipleSelection", true, true);
    eWebEditor.document.execCommand("LiveResize", true, true);
    eWebEditor.document.close();
    doZoom(nCurrZoomSize);
    bEditMode=true;
    eWebEditor.document.onselectionchange = function () { doToolbar();}
    break;
  case "TEXT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=html;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "VIEW":
    eWebEditor.document.designMode="off";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 && haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中間的長度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }

    eWebEditor.document.body.contentEditable="false";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  }

  eWebEditor.document.body.onpaste = onPaste ;
  eWebEditor.document.body.onhelp = onHelp ;
  eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
  eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");

  if ((borderShown != "0")&&bEditMode) {
    borderShown = "0";
    showBorders();
  }

  initHistory();
}

// 取編輯器的內(nèi)容
function getHTML() {
  var html;
  if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
    html = eWebEditor.document.body.innerHTML;
  }else{
    html = eWebEditor.document.body.innerText;
  }
  if (sCurrMode!="TEXT"){
    if ((html.toLowerCase()=="<p> </p>")||(html.toLowerCase()=="<p></p>")){
      html = "";
    }
  }
  return html;
}

// 在尾部追加內(nèi)容
function appendHTML(html) {
  if (isModeView()) return false;
  if(sCurrMode=="EDIT"){
    eWebEditor.document.body.innerHTML += html;
  }else{
    eWebEditor.document.body.innerText += html;
  }
}

// 從Word中粘貼,去除格式
function PasteWord(){
  if (!validateMode()) return;
  eWebEditor.focus();
  if (BrowserInfo.IsIE55OrMore)
    cleanAndPaste( GetClipboardHTML() ) ;
  else if ( confirm( "此功能要求IE5.5版本以上,你當(dāng)前的瀏覽器不支持,是否按常規(guī)粘貼進(jìn)行?" ) )
    format("paste") ;
  eWebEditor.focus();
}

// 粘貼純文本
function PasteText(){
  if (!validateMode()) return;
  eWebEditor.focus();
  var sText = HTMLEncode( clipboardData.getData("Text") ) ;
  insertHTML(sText);
  eWebEditor.focus();
}

// 檢測當(dāng)前是否允許編輯
function validateMode() {
  if (sCurrMode=="EDIT") return true;
  alert("需轉(zhuǎn)換為編輯狀態(tài)后才能使用編輯功能!");
  eWebEditor.focus();
  return false;
}

// 檢測當(dāng)前是否在預(yù)覽模式
function isModeView(){
  if (sCurrMode=="VIEW"){
    alert("預(yù)覽時不允許設(shè)置編輯區(qū)內(nèi)容。");
    return true;
  }
  return false;
}

// 格式化編輯器中的內(nèi)容
function format(what,opt) {
  if (!validateMode()) return;
  eWebEditor.focus();
  if (opt=="RemoveFormat") {
    what=opt;
    opt=null;
  }
  if (opt==null) eWebEditor.document.execCommand(what);
  else eWebEditor.document.execCommand(what,"",opt);
  eWebEditor.focus();
}

// 確保焦點(diǎn)在 eWebEditor 內(nèi)
function VerifyFocus() {
  if ( eWebEditor )
    eWebEditor.focus();
}

// 改變模式:代碼、編輯、文本、預(yù)覽
function setMode(NewMode){
  if (NewMode!=sCurrMode){
    if (!BrowserInfo.IsIE55OrMore){
      if ((NewMode=="CODE") || (NewMode=="EDIT") || (NewMode=="VIEW")){
        alert("HTML編輯模式需要IE5.5版本以上的支持!");
        return false;
      }
    }
    if (NewMode=="TEXT"){
      if (sCurrMode==ModeEdit.value){
        if (!confirm("警告!切換到純文本模式會丟失您所有的HTML格式,您確認(rèn)切換嗎?")){
          return false;
        }
      }
    }
    document.all["Editor_CODE"].style.display = "none";
    document.all["Editor_EDIT"].style.display = "none";
    document.all["Editor_VIEW"].style.display = "none";
    document.all["Editor_"+NewMode].style.display = "block";
    var sBody = "";
    switch(sCurrMode){
    case "CODE":
      if (NewMode=="TEXT"){
        eWebEditor_Temp_HTML.innerHTML = eWebEditor.document.body.innerText;
        sBody = eWebEditor_Temp_HTML.innerText;
      }else{
        sBody = eWebEditor.document.body.innerText;
        //alert('ok');
      }
      break;
    case "TEXT":
      sBody = eWebEditor.document.body.innerText;
      sBody = HTMLEncode(sBody);
      break;
    case "EDIT":
    case "VIEW":
      if (NewMode=="TEXT"){
        sBody = eWebEditor.document.body.innerText;
      }else{
        sBody = eWebEditor.document.body.innerHTML;
      }
      break;
    default:
      sBody = ContentEdit.value;
      break;
    }

    // 換圖片
    /*try{
      document.all["eWebEditor_CODE"].className = "StatusBarBtnOff";
      document.all["eWebEditor_EDIT"].className = "StatusBarBtnOff";
      document.all["eWebEditor_TEXT"].className = "StatusBarBtnOff";
      document.all["eWebEditor_VIEW"].className = "StatusBarBtnOff";
      document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn";
      }
    catch(e){
      }
    */
    sCurrMode = NewMode;
    ModeEdit.value = NewMode;
    setHTML(sBody);
    disableChildren(eWebEditor_Toolbar);
  }
}

// 使工具欄無效
function disableChildren(obj){
  if (obj){
    obj.disabled=(!bEditMode);
    for (var i=0; i<obj.children.length; i++){
      disableChildren(obj.children[i]);
    }
  }
}



// 顯示無模式對話框
function ShowDialog(url, width, height, optValidate) {
  if (optValidate) {
    if (!validateMode()) return;
  }
  eWebEditor.focus();
  var arr = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
  eWebEditor.focus();
}

// 全屏編輯
function Maximize() {
  if (!validateMode()) return;
  window.open("dialog/fullscreen.htm?style="+config.StyleName, 'FullScreen'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,fullscreen=yes');
}

// 創(chuàng)建或修改超級鏈接
function createLink(){
  if (!validateMode()) return;
  
  if (eWebEditor.document.selection.type == "Control") {
    var oControlRange = eWebEditor.document.selection.createRange();
    if (oControlRange(0).tagName.toUpperCase() != "IMG") {
      alert("鏈接只能是圖片或文本");
      return;
    }
  }
  
  ShowDialog("dialog/hyperlink.htm", 350, 170, true);
}

// 替換特殊字符
function HTMLEncode(text){
  text = text.replace(/&/g, "&") ;
  text = text.replace(/"/g, """) ;
  text = text.replace(/</g, "<") ;
  text = text.replace(/>/g, ">") ;
  text = text.replace(/'/g, "’") ;
  text = text.replace(/\ /g," ");
  text = text.replace(/\n/g,"<br>");
  text = text.replace(/\t/g,"    ");
  return text;
}

// 插入特殊對象
function insert(what) {
  if (!validateMode()) return;
  eWebEditor.focus();
  var sel = eWebEditor.document.selection.createRange();

  switch(what){
  case "excel":    // 插入EXCEL表格
    insertHTML("<object classid='clsid:0002E510-0000-0000-C000-000000000046' id='Spreadsheet1' codebase='file:\\Bob\software\office2000\msowc.cab' width='100%' height='250'><param name='HTMLURL' value><param name='HTMLData' value='<html xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40"><head><style type="text/css"><!--tr{mso-height-source:auto;}td{black-space:nowrap;}.wc4590F88{black-space:nowrap;font-family:宋體;mso-number-format:General;font-size:auto;font-weight:auto;font-style:auto;text-decoration:auto;mso-background-source:auto;mso-pattern:auto;mso-color-source:auto;text-align:general;vertical-align:bottom;border-top:none;border-left:none;border-right:none;border-bottom:none;mso-protection:locked;}--></style></head><body><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:OWCVersion>9.0.0.2710</x:OWCVersion><x:Label Style='border-top:solid .5pt silver;border-left:solid .5pt silver;border-right:solid .5pt silver;border-bottom:solid .5pt silver'><x:Caption>Microsoft Office Spreadsheet</x:Caption> </x:Label><x:Name>Sheet1</x:Name><x:WorksheetOptions><x:Selected/><x:Height>7620</x:Height><x:Width>15240</x:Width><x:TopRowVisible>0</x:TopRowVisible><x:LeftColumnVisible>0</x:LeftColumnVisible> <x:ProtectContents>False</x:ProtectContents> <x:DefaultRowHeight>210</x:DefaultRowHeight> <x:StandardWidth>2389</x:StandardWidth> </x:WorksheetOptions> </x:ExcelWorksheet></x:ExcelWorksheets> <x:MaxHeight>80%</x:MaxHeight><x:MaxWidth>80%</x:MaxWidth></x:ExcelWorkbook></xml><![endif]--><table class=wc4590F88 x:str><col width="56"><tr height="14"><td></td></tr></table></body></html>'> <param name='DataType' value='HTMLDATA'> <param name='AutoFit' value='0'><param name='DisplayColHeaders' value='-1'><param name='DisplayGridlines' value='-1'><param name='DisplayHorizontalScrollBar' value='-1'><param name='DisplayRowHeaders' value='-1'><param name='DisplayTitleBar' value='-1'><param name='DisplayToolbar' value='-1'><param name='DisplayVerticalScrollBar' value='-1'> <param name='EnableAutoCalculate' value='-1'> <param name='EnableEvents' value='-1'><param name='MoveAfterReturn' value='-1'><param name='MoveAfterReturnDirection' value='0'><param name='RightToLeft' value='0'><param name='ViewableRange' value='1:65536'></object>");
    break;
  case "nowdate":    // 插入當(dāng)前系統(tǒng)日期
    var d = new Date();
    insertHTML(d.toLocaleDateString());
    break;
  case "nowtime":    // 插入當(dāng)前系統(tǒng)時間
    var d = new Date();
    insertHTML(d.toLocaleTimeString());
    break;
  case "br":      // 插入換行符
    insertHTML("<br>")
    break;
  case "code":    // 代碼片段樣式
    insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#FDFDDF style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是代碼片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
    break;
  case "quote":    // 引用片段樣式
    insertHTML('<table width=95% border="0" align="Center" cellpadding="6" cellspacing="0" style="border: 1px Dotted #CCCCCC; TABLE-LAYOUT: fixed"><tr><td bgcolor=#F3F3F3 style="WORD-WRAP: break-word"><font style="color: #990000;font-weight:bold">以下是引用片段:</font><br>'+HTMLEncode(sel.text)+'</td></tr></table>');
    break;
  case "big":      // 字體變大
    insertHTML("<big>" + sel.text + "</big>");
    break;
  case "small":    // 字體變小
    insertHTML("<small>" + sel.text + "</small>");
    break;
  case "SplitPage":  // 插入分頁符
    insertHTML("<HR sysPageSplitFlag>");
    break;
  default:
    if(what.substring(0,2)=='{$'){insertHTML(what);break;}
    alert("錯誤參數(shù)調(diào)用!");
    break;
  }
  sel=null;
}

// 顯示或隱藏指導(dǎo)方針
var borderShown = config.ShowBorder;
function showBorders() {
  if (!validateMode()) return;
  
  var allForms = eWebEditor.document.body.getElementsByTagName("FORM");
  var allInputs = eWebEditor.document.body.getElementsByTagName("INPUT");
  var allTables = eWebEditor.document.body.getElementsByTagName("TABLE");
  var allLinks = eWebEditor.document.body.getElementsByTagName("A");

  // 表單
  for (a=0; a < allForms.length; a++) {
    if (borderShown == "0") {
      allForms[a].runtimeStyle.border = "1px dotted #FF0000"
    } else {
      allForms[a].runtimeStyle.cssText = ""
    }
  }

  // Input Hidden類
  for (b=0; b < allInputs.length; b++) {
    if (borderShown == "0") {
      if (allInputs[b].type.toUpperCase() == "HIDDEN") {
        allInputs[b].runtimeStyle.border = "1px dashed #000000"
        allInputs[b].runtimeStyle.width = "15px"
        allInputs[b].runtimeStyle.height = "15px"
        allInputs[b].runtimeStyle.backgroundColor = "#FDADAD"
        allInputs[b].runtimeStyle.color = "#FDADAD"
      }
    } else {
      if (allInputs[b].type.toUpperCase() == "HIDDEN")
        allInputs[b].runtimeStyle.cssText = ""
    }
  }

  // 表格
  for (i=0; i < allTables.length; i++) {
      if (borderShown == "0") {
        allTables[i].runtimeStyle.border = "1px dotted #BFBFBF"
      } else {
        allTables[i].runtimeStyle.cssText = ""
      }

      allRows = allTables[i].rows
      for (y=0; y < allRows.length; y++) {
         allCellsInRow = allRows[y].cells
          for (x=0; x < allCellsInRow.length; x++) {
            if (borderShown == "0") {
              allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF"
            } else {
              allCellsInRow[x].runtimeStyle.cssText = ""
            }
          }
      }
  }

  // 鏈接 A
  for (a=0; a < allLinks.length; a++) {
    if (borderShown == "0") {
      if (allLinks[a].href.toUpperCase() == "") {
        allLinks[a].runtimeStyle.borderBottom = "1px dashed #000000"
      }
    } else {
      allLinks[a].runtimeStyle.cssText = ""
    }
  }

  if (borderShown == "0") {
    borderShown = "1"
  } else {
    borderShown = "0"
  }

  scrollUp()
}

// 返回頁面最上部
function scrollUp() {
  eWebEditor.scrollBy(0,0);
}

// 縮放操作
var nCurrZoomSize = 100;
var aZoomSize = new Array(10, 25, 50, 75, 100, 150, 200, 500);
function doZoom(size) {
  eWebEditor.document.body.runtimeStyle.zoom = size + "%";
  nCurrZoomSize = size;
}

// 拼寫檢查
function spellCheck(){
  ShowDialog('dialog/spellcheck.htm', 300, 220, true)
}

// 查找替換
function findReplace(){
  ShowDialog('dialog/findreplace.htm', 320, 165, true)
}

// 相對(absolute)或絕對位置(static)
function absolutePosition(){
  var objReference  = null;
  var RangeType    = eWebEditor.document.selection.type;
  if (RangeType != "Control") return;
  var selectedRange  = eWebEditor.document.selection.createRange();
  for (var i=0; i<selectedRange.length; i++){
    objReference = selectedRange.item(i);
    if (objReference.style.position != 'absolute') {
      objReference.style.position='absolute';
    }else{
      objReference.style.position='static';
    }
  }
}

// 上移(forward)或下移(backward)一層
function zIndex(action){
  var objReference  = null;
  var RangeType    = eWebEditor.document.selection.type;
  if (RangeType != "Control") return;
  var selectedRange  = eWebEditor.document.selection.createRange();
  for (var i=0; i<selectedRange.length; i++){
    objReference = selectedRange.item(i);
    if (action=='forward'){
      objReference.style.zIndex +=1;
    }else{
      objReference.style.zIndex -=1;
    }
    objReference.style.position='absolute';
  }
}

// 是否選中指定類型的控件
function isControlSelected(tag){
  if (eWebEditor.document.selection.type == "Control") {
    var oControlRange = eWebEditor.document.selection.createRange();
    if (oControlRange(0).tagName.toUpperCase() == tag) {
      return true;
    }  
  }
  return false;
}

// 改變編輯區(qū)高度
function sizeChange(size){
  if (!BrowserInfo.IsIE55OrMore){
    alert("此功能需要IE5.5版本以上的支持!");
    return false;
  }
  for (var i=0; i<parent.frames.length; i++){
    if (parent.frames[i].document==self.document){
      var obj=parent.frames[i].frameElement;
      var height = parseInt(obj.offsetHeight);
      if(size==0){obj.height=400;break;}
      if (height+size>=300){
        obj.height=height+size;
      }
      break;
    }
  }
}

// 熱點(diǎn)鏈接
function mapEdit(){
  if (!validateMode()) return;
  
  var b = false;
  if (eWebEditor.document.selection.type == "Control") {
    var oControlRange = eWebEditor.document.selection.createRange();
    if (oControlRange(0).tagName.toUpperCase() == "IMG") {
      b = true;
    }
  }
  if (!b){
    alert("熱點(diǎn)鏈接只能作用于圖片");
    return;
  }

  window.open("dialog/map.htm", 'mapEdit'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=not,menubar=no,scrollbars=no,resizable=yes,width=450,height=300');
}

// 上傳文件成功返回原文件名、保存后的文件名、保存后的路徑文件名,提供接口
function addUploadFile(originalFileName, saveFileName, savePathFileName){
  doInterfaceUpload(sLinkOriginalFileName, originalFileName);
  doInterfaceUpload(sLinkSaveFileName, saveFileName);
  doInterfaceUpload(sLinkSavePathFileName, savePathFileName);
}

// 文件上傳成功接口操作
function doInterfaceUpload(strLinkName, strValue){
  if (strValue=="") return;

  if (strLinkName){
    var objLinkUpload = parent.document.getElementsByName(strLinkName)[0];
    if (objLinkUpload){
      if (objLinkUpload.value!=""){
        objLinkUpload.value = objLinkUpload.value + "|";
      }
      objLinkUpload.value = objLinkUpload.value + strValue;
      objLinkUpload.fireEvent("onchange");
    }
  }
}

// 大文件內(nèi)容自動拆分
function splitTextField(objField, html) {
  var strFieldName = objField.name;
  var objForm = objField.form;
  var objDocument = objField.document;
  objField.value = html;

  //表單限制值設(shè)定,限制值是102399,考慮到中文設(shè)為一半
  var FormLimit = 50000 ;

  // 再次處理時,先賦空值
  for (var i=1;i<objDocument.getElementsByName(strFieldName).length;i++) {
    objDocument.getElementsByName(strFieldName)[i].value = "";
  }

  //如果表單值超過限制,拆成多個對象
  if (html.length > FormLimit) {
    objField.value = html.substr(0, FormLimit) ;
    html = html.substr(FormLimit) ;

    while (html.length > 0) {
      var objTEXTAREA = objDocument.createElement("TEXTAREA") ;
      objTEXTAREA.name = strFieldName ;
      objTEXTAREA.style.display = "none" ;
      objTEXTAREA.value = html.substr(0, FormLimit) ;
      objForm.appendChild(objTEXTAREA) ;

      html = html.substr(FormLimit) ;
    }
  }
}

// 遠(yuǎn)程上傳
var sEventUploadAfter;
function remoteUpload(strEventUploadAfter) {
  if (config.AutoRemote!="1") return;
  if (sCurrMode=="TEXT") return;
  
  sEventUploadAfter = strEventUploadAfter;
  var objField = document.getElementsByName("eWebEditor_UploadText")[0];
  splitTextField(objField, getHTML());

  divProcessing.style.top = (document.body.clientHeight-parseFloat(divProcessing.style.height))/2;
  divProcessing.style.left = (document.body.clientWidth-parseFloat(divProcessing.style.width))/2;
  divProcessing.style.display = "";
  eWebEditor_UploadForm.submit();
}

// 遠(yuǎn)程上傳完成
function remoteUploadOK() {
  divProcessing.style.display = "none";
  if (oLinkField){
    if (sEventUploadAfter){
      eval("parent."+sEventUploadAfter);
    }
  }
}

// 修正Undo/Redo
var history = new Object;
history.data = [];
history.position = 0;
history.bookmark = [];

// 保存歷史
function saveHistory() {
  if (bEditMode){
    if (history.data[history.position] != eWebEditor.document.body.innerHTML){
      var nBeginLen = history.data.length;
      var nPopLen = history.data.length - history.position;
      for (var i=1; i<nPopLen; i++){
        history.data.pop();
        history.bookmark.pop();
      }

      history.data[history.data.length] = eWebEditor.document.body.innerHTML;

      if (eWebEditor.document.selection.type != "Control"){
        history.bookmark[history.bookmark.length] = eWebEditor.document.selection.createRange().getBookmark();
      } else {
        var oControl = eWebEditor.document.selection.createRange();
        history.bookmark[history.bookmark.length] = oControl[0];
      }

      if (nBeginLen!=0){
        history.position++;
      }
    }
  }
}

// 初始?xì)v史
function initHistory() {
  history.data.length = 0;
  history.bookmark.length = 0;
  history.position = 0;
}

// 返回歷史
function goHistory(value) {
  saveHistory();
  // undo
  if (value == -1){
    if (history.position > 0){
      eWebEditor.document.body.innerHTML = history.data[--history.position];
      setHistoryCursor();
    }
  // redo
  } else {
    if (history.position < history.data.length -1){
      eWebEditor.document.body.innerHTML = history.data[++history.position];
      setHistoryCursor();
    }
  }
}

// 設(shè)置當(dāng)前書簽
function setHistoryCursor() {
  if (history.bookmark[history.position]){
    r = eWebEditor.document.body.createTextRange()
    if (history.bookmark[history.position] != "[object]"){
      if (r.moveToBookmark(history.bookmark[history.position])){
        r.collapse(false);
        r.select();
      }
    }
  }
}
// End Undo / Redo Fix

// 工具欄事件發(fā)生
function doToolbar(){
  if (bEditMode){
    saveHistory();
  }
}


我暈,真的好恐怖,原來這么長的代碼....

嗬嗬.....其實(shí)主要的就二個地方:

1.變量聲明,在前幾行就有

//頭尾部對象
var oTopCode =null;
var oBottomCode =null;

這是記錄頭尾部代碼的全局變量.

2.修改方法,具體見下:

// 設(shè)置編輯器的內(nèi)容
function setHTML(html) {
  ContentEdit.value = html;
  switch (sCurrMode){
  case "CODE":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=oTopCode + html + oBottomCode;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "EDIT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 && haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中間的長度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }
    //alert(config.StyleEditorHeader);
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.execCommand("2D-Position",true,true);
    eWebEditor.document.execCommand("MultipleSelection", true, true);
    eWebEditor.document.execCommand("LiveResize", true, true);
    eWebEditor.document.close();
    doZoom(nCurrZoomSize);
    bEditMode=true;
    eWebEditor.document.onselectionchange = function () { doToolbar();}
    break;
  case "TEXT":
    eWebEditor.document.designMode="On";
    eWebEditor.document.open();
    eWebEditor.document.write(config.StyleEditorHeader);
    eWebEditor.document.body.innerText=html;
    eWebEditor.document.body.contentEditable="true";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  case "VIEW":
    eWebEditor.document.designMode="off";
    eWebEditor.document.open();
    //eWebEditor.document.write(config.StyleEditorHeader+html);
    var haoHtml,haoB,haoC,haoD,haoE;
    haoHtml=html.toLowerCase();
    if(haoHtml.indexOf("<body")!=-1 && haoHtml.indexOf("</body>")!=-1)
    {
      haoB=haoHtml.indexOf("<body");
      haoC=haoHtml.indexOf("</body>");
      haoD=haoHtml.substring(haoB,haoC+7) //中間的長度
      haoE=haoD.substring(0,haoD.indexOf(">")+1);
      oTopCode=haoHtml.substring(0,haoB) + haoE;
      oBottomCode="</body>" + haoHtml.substring(haoC+7);
      eWebEditor.document.write(html);
    }
    else
    {
      oTopCode="";
      oBottomCode="";
      eWebEditor.document.write(config.StyleEditorHeader+html);
    }

    eWebEditor.document.body.contentEditable="false";
    eWebEditor.document.close();
    bEditMode=false;
    break;
  }

  eWebEditor.document.body.onpaste = onPaste ;
  eWebEditor.document.body.onhelp = onHelp ;
  eWebEditor.document.onkeydown = new Function("return onKeyDown(eWebEditor.event);");
  eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);");

  if ((borderShown != "0")&&bEditMode) {
    borderShown = "0";
    showBorders();
  }

  initHistory();
}


對比一下自己的這個方法,看看有何不同....呵呵,都是極簡單的語法,就不說了.

咕得拜,一天沒吃飯了,發(fā)現(xiàn)自己越來越懶了..這可咋辦涅!??!

PS,這問題還是一朋友告訴我的,我一直沒發(fā)現(xiàn)這問題.汗....虧我以前還用這個做整頁的.
THX小蝦同志.[bookworm]
評論Feed: http://77521.cn/feed.asp
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
JavaScript 點(diǎn)擊插入文字
javascript復(fù)習(xí)題
在線編輯器原理
博客園 - 小橋 - 在線HTML編輯器原理
動態(tài)生成按鈕
H5外部瀏覽器直接調(diào)起微信
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服