/* *☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ *★ ★ *☆ eWebEditor - eWebSoft在线文本编辑器飞鱼修改版 ☆ *★ ★ *☆ 版权所有: eWebSoft.com ☆ *★ ★ *☆ 程序制作: eWeb开发团队 ☆ *★ email:webmaster@webasp.net ★ *☆ QQ:589808 ☆ *★ ★ *☆ 相关网址: [原版地址]http://www.eWebSoft.com/Product/eWebEditor/ ☆ *★ [支持论坛]http://bbs.eWebSoft.com/ ★ *☆ ☆ *★ 主页地址: http://www.fiyu.net/ 飞鱼论坛 ★ *☆ 有什么问题欢迎到飞鱼论坛提出! ☆ *★ ★ *★ ★ *☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ */ // 当前模式 var sCurrMode = null; var bEditMode = null; // 连接对象 var oLinkField = null; var sBaseUrl = document.location.protocol + '//' + document.location.host ; // 浏览器版本检测 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(); // 工具栏数组 // 当文档完全调入时,进行初始化 var bInitialized = false; document.onreadystatechange=function(){ if (document.readyState!="complete") return; if (bInitialized) return; bInitialized = true; var i, s, curr; // 初始每个工具栏 for (i=0; i"); return false; } } y.TBWidth += 1; return true; } // 设置所属表单的提交或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提交事件,大表单数据提交,远程文件获取,保存eWebEditor中的内容 var bDoneAutoRemote = false; function AttachSubmit() { var oForm = oLinkField.form ; if (!oForm) return; if ((config.AutoRemote=="1")&&(!bDoneAutoRemote)){ parent.event.returnValue = false; bDoneAutoRemote = true; remoteUpload(); } else { 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) setMode('EDIT'); if(bEditMode){ eWebEditor.document.body.innerHTML = ContentLoad.value; }else{ eWebEditor.document.body.innerText = ContentLoad.value; } } // 粘贴时自动检测是否来源于Word格式 function onPaste() { if (config.AutoDetectPasteFromWord && BrowserInfo.IsIE55OrMore) { var sHTML = GetClipboardHTML() ; var re = /<\w[^>]* class="?MsoNormal"?/gi ; if ( re.test( sHTML ) ) { if ( confirm( "你要粘贴的内容好象是从Word中拷出来的,是否要先清除Word格式再粘贴?" ) ) { cleanAndPaste( sHTML ) ; return false ; } } } else return true ; } 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 ; } 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: html = html.replace(/<\/?\w+:[^>]*>/gi, "") ; // Replace the   html = html.replace(/ /, " " ); // Transform

to

var re = new RegExp("(]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error html = html.replace( re, "" ) ; insertHTML( html ) ; } // 在当前文档位置插入. function insertHTML(html) { if (!validateMode()) return; if (eWebEditor.document.selection.type.toLowerCase() != "none") eWebEditor.document.selection.clear() ; eWebEditor.document.selection.createRange().pasteHTML(html) ; } // 设置编辑器的内容 /*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=html; 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); 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); 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(); }*/ // 设置编辑器的内容 function setHTML(html) { if (!validateMode()) return; ContentEdit.value = html; if(bEditMode){ eWebEditor.document.body.innerHTML = html; }else{ eWebEditor.document.body.innerText = html; } } // 取编辑器的内容 function getHTML() { var html; if(bEditMode){ html = eWebEditor.document.body.innerHTML; }else{ html = eWebEditor.document.body.innerText; } var re = new RegExp(sBaseUrl.replace(/\//,"\/"),"gi"); html = html.replace(re, ""); if (html=="") { html = " ";} return html; } // 在尾部追加内容 function appendHTML(html) { if (!validateMode()) return; if(bEditMode){ 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版本以上,你当前的浏览器不支持,是否按常规粘贴进行?" ) ) format("paste") ; eWebEditor.focus(); } // 粘贴纯文本 function PasteText(){ if (!validateMode()) return; eWebEditor.focus(); var sText = HTMLEncode( clipboardData.getData("Text") ) ; insertHTML(sText); eWebEditor.focus(); } // 检测当前是否允许编辑 function validateMode() { if (bEditMode) return true; alert("需转换为编辑状态后才能使用编辑功能!"); eWebEditor.focus(); return false; } // 格式化编辑器中的内容 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(); } // 确保焦点在 eWebEditor 内 function VerifyFocus() { if ( eWebEditor ) eWebEditor.focus(); } // 改变模式:代码、编辑、预览 function setMode(NewMode){ if (NewMode!=sCurrMode){ var sBody = ""; switch(sCurrMode){ case "CODE": sBody = eWebEditor.document.body.innerText; break; case "EDIT": case "VIEW": 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_VIEW"].className = "StatusBarBtnOff"; document.all["eWebEditor_"+NewMode].className = "StatusBarBtnOn"; } catch(e){ } // 换内容 switch (NewMode){ case "CODE": eWebEditor.document.designMode="On"; eWebEditor.document.open(); eWebEditor.document.write(config.StyleEditorHeader); eWebEditor.document.body.innerText=sBody; eWebEditor.document.body.contentEditable="true"; eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);"); eWebEditor.document.close(); bEditMode=false; break; case "EDIT": eWebEditor.document.designMode="On"; eWebEditor.document.open(); eWebEditor.document.write(config.StyleEditorHeader); eWebEditor.document.body.innerHTML=sBody; eWebEditor.document.body.contentEditable="true"; eWebEditor.document.oncontextmenu=new Function("return showContextMenu(eWebEditor.event);"); 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; break; case "VIEW": eWebEditor.document.designMode="off"; eWebEditor.document.open(); eWebEditor.document.write(config.StyleEditorHeader+sBody); eWebEditor.document.body.contentEditable="false"; eWebEditor.document.close(); bEditMode=false; break; } sCurrMode=NewMode; disableChildren(eWebEditor_Toolbar); if ((borderShown != "no")&&bEditMode) { borderShown = "no"; showBorders() } } eWebEditor.focus(); } // 使工具栏无效 function disableChildren(obj){ if (obj){ obj.disabled=(!bEditMode); for (var i=0; i/g, ">") ; text = text.replace(/'/g, "’") ; text = text.replace(/\ /g," "); text = text.replace(/\n/g,"
"); 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(" "); break; case "nowdate": // 插入当前系统日期 var d = new Date(); insertHTML(d.toLocaleDateString()); break; case "nowtime": // 插入当前系统时间 var d = new Date(); insertHTML(d.toLocaleTimeString()); break; case "br": // 插入换行符 insertHTML("
") break; case "code": // 代码片段样式 insertHTML('
以下是代码片段:
'+HTMLEncode(sel.text)+'
'); break; case "quote": // 引用片段样式 insertHTML('
以下是引用片段:
'+HTMLEncode(sel.text)+'
'); break; case "big": // 字体变大 insertHTML("" + sel.text + ""); break; case "small": // 字体变小 insertHTML("" + sel.text + ""); break; default: alert("错误参数调用!"); break; } sel=null; } // 显示或隐藏指导方针 var borderShown = "no"; 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 == "no") { allForms[a].runtimeStyle.border = "1px dotted #FF0000" } else { allForms[a].runtimeStyle.cssText = "" } } // Input Hidden类 for (b=0; b < allInputs.length; b++) { if (borderShown == "no") { 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 == "no") { 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 == "no") { allCellsInRow[x].runtimeStyle.border = "1px dotted #BFBFBF" } else { allCellsInRow[x].runtimeStyle.cssText = "" } } } } // 链接 A for (a=0; a < allLinks.length; a++) { if (borderShown == "no") { if (allLinks[a].href.toUpperCase() == "") { allLinks[a].runtimeStyle.border = "1px dashed #000000" allLinks[a].runtimeStyle.width = "20px" allLinks[a].runtimeStyle.height = "16px" allLinks[a].runtimeStyle.backgroundColor = "#FFFFCC" allLinks[a].runtimeStyle.color = "#FFFFCC" } } else { allLinks[a].runtimeStyle.cssText = "" } } if (borderShown == "no") { borderShown = "yes" } else { borderShown = "no" } 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=300){ obj.height=height+size; } break; } } } // 大文件内容自动拆分 function splitTextField(objField, html) { var strFieldName = objField.name; var objForm = objField.form; var objDocument = objField.document; objField.value = html; //表单限制值设定,限制值是102399,考虑到中文设为一半 //var FormLimit = 50000; //var FormLimit = 102399; var FormLimit = 1023990; // 再次处理时,先赋空值 for (var i=1;i FormLimit) { if (false) { 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) ; } } } // 远程上传 function remoteUpload() { if (sCurrMode=="TEXT") return; 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(); } // 远程上传完成 function remoteUploadOK() { divProcessing.style.display = "none"; if (bDoneAutoRemote){ doSubmit(); } }