目录:1. 简介2. 调用示例3. 编辑示例4. js 核心代码内容:1. 简介
sqEditor HTML 编辑器 for .net By shawl.qiu ---/-------------------------------------------------------------------------------------- version 1.0 下载: http://files.myopera.com/btbtd/csharp/class/sqEditor_for_dotNet_v1.0.7z sqEditor HTML 编辑器 for .net v1.0 是 从 sqEditor HTML 编辑器 v1.3 改写而来. sqEditor HTML 编辑器 v1.3 详细: http://blog.csdn.net/btbtd/archive/2007/01/16/1484070.aspx 基本上两者编辑功能无甚区别, 不同的是两者的运行方式. shawl.qiu 2007-3-2 http://blog.csdn.net/btbtd © 2007-2008 shawl.qiu. All rights reserved.2. 调用示例
<%@ Page Language="C#" AutoEventWireup="True" validateRequest="false" %> <%@ import Namespace="System.Web.UI.WebControls" %> <%@ Reference Control="ac/sqEditor.ascx" %> <script runat="server"> public string EdRoot = "/sqEditor_DotNet/"; void Page_Load(Object s, EventArgs e) { GetEditor("<b>hello</b>, test this.", edPlaceHolder, EdRoot+"ac/sqEditor.ascx", new EventHandler(Submit)); } // end Page_Load public void GetEditor(string inti, PlaceHolder edPlaceHolder, string edPath, EventHandler eh) { sqEditor ed = (sqEditor)LoadControl(edPath); ed.EdRoot = EdRoot; ed.EdIntiText = inti; ed.SubmitEventHandler = eh; edPlaceHolder.Controls.Add(ed); } public void Submit(Object s, EventArgs e) { TextBox edTextBox = (TextBox)((Button)s).Parent.FindControl("edTextBox"); HtmlGenericControl edIntiDiv = (HtmlGenericControl)((Button)s).Parent.FindControl("edIntiDiv"); edIntiDiv.InnerHtml = edTextBox.Text; if(edTextBox == null) return; debugLabel.Text = edTextBox.Text; } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shawl.qiu template</title> <style type="text/css"> /*<![CDATA[*/ @import "<% Response.Write(EdRoot); %>style/style.css"; /*]]>*/ </style> </head> <body> <form runat="server"> <asp:Label id=debugLabel runat=server /> <div class="sqEditorDiv"> <asp:PlaceHolder id=edPlaceHolder runat=server /> </div> </form> <p/><a href="?">--back--</a> </body> </html>3. 编辑示例
<%@ Page Language="C#" AutoEventWireup="True" validateRequest="false" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> <%@ import Namespace="System.IO" %> <%@ import Namespace="System.Text" %> <%@ import Namespace="System.Web.UI.WebControls" %> <%@ Assembly src="cs/Pagination.cs" %> <%@ Assembly src="cs/SQ.cs" %> <%@ import Namespace="SQ" %> <%@ Reference Control="ac/sqEditor.ascx" %> <script runat="server"> public bool Debug = false; public string EdRoot = "/sqEditor_DotNet/"; public string ReqIdStr = HttpContext.Current.Request.QueryString["id"]+""; public string ReqAidStr = HttpContext.Current.Request.QueryString["aid"]+""; void Page_Load(Object s, EventArgs e) { string SqlCnnStr; SqlCnnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ @MapPath(EdRoot+"/data/shawlqiu.mdb"); string SqlQuery; SqlQuery = "select * from shawlqiu_"; acDebugLabel.Text = ""; acInfoLabel.Text = ""; switch(ReqIdStr) { case "addnew": AddNewBox(); break; case "edit": SqlQuery+=" where articleid = "+ReqAidStr; EditBox(SqlQuery, SqlCnnStr, acInfoLabel); break; case "display": SqlQuery+=" where articleid = "+ReqAidStr; acDisplayAtDataList.DataSource = Datum.GetDataTable(SqlQuery, SqlCnnStr); acDisplayAtDataList.DataBind(); break; default: SqlQuery+=" order by articleid desc"; DisplayList(Datum.GetDataTable(SqlQuery, SqlCnnStr, "hello"), acDataList); break; } } // end Page_Load private void EditBox(string qry, string cnn, Label InfoLabel) { DataTable dt = Datum.GetDataTable(qry, cnn); string cnt = ""; if(dt.Rows.Count==0) { Utility.GoBack("查询出错, 3 秒后返回, 还有 ", 3, true, InfoLabel); return; } Literal ltl = new Literal(); ltl.Text = "<h3 class='fltr algr'>编辑数据 <a href='?id=display&aid="+ HttpContext.Current.Request.QueryString["aid"]+"'>Go Article</a></h3>title: "; edPlaceHolder.Controls.Add(ltl); TextBox tbx = new TextBox(); tbx.ID = "acTitle"; tbx.Columns = 80; tbx.Text = dt.Rows[0]["title"]+""; edPlaceHolder.Controls.Add(tbx); GetEditor( System.Text.Encoding.Unicode.GetString((byte[])dt.Rows[0]["content"]), edPlaceHolder, EdRoot+"ac/sqEditor.ascx", new EventHandler(SubmitEdit)); } public void SubmitEdit(Object s, EventArgs e) { bool debug = false; TextBox edTextBox = (TextBox)((Button)s).Parent.FindControl("edTextBox"); TextBox titleTextBox = (TextBox)edPlaceHolder.FindControl("acTitle"); HtmlGenericControl edIntiDiv = (HtmlGenericControl)((Button)s).Parent.FindControl("edIntiDiv"); edIntiDiv.InnerHtml = edTextBox.Text; if(edTextBox == null) return; if((debug|Debug)&acDebugLabel!=null) { acDebugLabel.Text += "<li/>titleTextBox.Text: "+titleTextBox.Text; acDebugLabel.Text += "<li/>titleTextBox.Text==/"/": "+(titleTextBox.Text==""); acDebugLabel.Text += "<li/>edTextBox.Text: "+edTextBox.Text; acDebugLabel.Text += "<li/>edTextBox.Text==/"/": "+(edTextBox.Text==""); } if(titleTextBox.Text=="") { acInfoLabel.Text += "<li/>标题不能为空! 操作被取消."; return; } if(edTextBox.Text=="") { edTextBox.Text += "<li/>内容不能为空! 操作被取消."; return; } string SqlCnnStr; SqlCnnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ @MapPath(EdRoot+"/data/shawlqiu.mdb"); OleDbConnection oCnn = new OleDbConnection(SqlCnnStr); OleDbCommand oCmd = new OleDbCommand("update shawlqiu_ set title="+ "@title, content=@content where articleid="+ReqAidStr, oCnn); OleDbParameter oParamTitle = new OleDbParameter("@title", "OleDbType.Varchar"); oParamTitle.Value = titleTextBox.Text+""; oCmd.Parameters.Add(oParamTitle); OleDbParameter oParamContent = new OleDbParameter("@content", "OleDbType.Binary"); oParamContent.Value = edTextBox.Text+""; oCmd.Parameters.Add(oParamContent); oCnn.Open(); oCmd.ExecuteNonQuery(); oCnn.Close(); Utility.GoBack("数据已更新, 3 秒后返回, 还有 ", 3, true, acInfoLabel); } private void AddNewBox() { Literal ltl = new Literal(); ltl.Text = "<h3 class='fltr algr'>添加数据</h3>title: "; edPlaceHolder.Controls.Add(ltl); TextBox tbx = new TextBox(); tbx.ID = "acTitle"; tbx.Columns = 80; edPlaceHolder.Controls.Add(tbx); GetEditor("add new article", edPlaceHolder, EdRoot+"ac/sqEditor.ascx", new EventHandler(SubmitNew)); } public void SubmitNew(Object s, EventArgs e) { bool debug = false; TextBox edTextBox = (TextBox)((Button)s).Parent.FindControl("edTextBox"); TextBox titleTextBox = (TextBox)edPlaceHolder.FindControl("acTitle"); HtmlGenericControl edIntiDiv = (HtmlGenericControl)((Button)s).Parent.FindControl("edIntiDiv"); edIntiDiv.InnerHtml = edTextBox.Text; if(edTextBox == null) return; if((debug|Debug)&acDebugLabel!=null) { acDebugLabel.Text += "<li/>titleTextBox.Text: "+titleTextBox.Text; acDebugLabel.Text += "<li/>titleTextBox.Text==/"/": "+(titleTextBox.Text==""); acDebugLabel.Text += "<li/>edTextBox.Text: "+edTextBox.Text; acDebugLabel.Text += "<li/>edTextBox.Text==/"/": "+(edTextBox.Text==""); } if(titleTextBox.Text=="") { acInfoLabel.Text += "<li/>标题不能为空! 操作被取消."; return; } if(edTextBox.Text=="") { edTextBox.Text += "<li/>内容不能为空! 操作被取消."; return; } string SqlCnnStr; SqlCnnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+ @MapPath(EdRoot+"/data/shawlqiu.mdb"); OleDbConnection oCnn = new OleDbConnection(SqlCnnStr); OleDbCommand oCmd = new OleDbCommand("insert into shawlqiu_(title, content) "+ "values(@title, @content)", oCnn); OleDbParameter oParamTitle = new OleDbParameter("@title", "OleDbType.Varchar"); oParamTitle.Value = titleTextBox.Text+""; oCmd.Parameters.Add(oParamTitle); OleDbParameter oParamContent = new OleDbParameter("@content", "OleDbType.Binary"); oParamContent.Value = edTextBox.Text+""; oCmd.Parameters.Add(oParamContent); oCnn.Open(); oCmd.ExecuteNonQuery(); oCnn.Close(); Utility.GoBack("数据已添加, 3 秒后返回, 还有 ", 3, "?", acInfoLabel); } private void DisplayList(DataTable dt, DataList acDataList) { Pagination Paged=new Pagination(); Paged.Debug=false; // 是否为调试模式 Paged.DebugLabel=acDebugLabel; // 显示调试信息的 Label Paged.NavigatorLabel=acPagedLabel; // 显示主导航条的 Label Paged.DetailsLabel=acPagedDetailsLabel;// 显示分页明细的 Label Paged.PageSize=20; // 每页大小 Paged.Go(dt, acDataList); // 执行分页 Paged=null; } public void GetEditor(string inti, PlaceHolder edPlaceHolder, string edPath, EventHandler eh) { sqEditor ed = (sqEditor)LoadControl(edPath); ed.Debug = Debug; ed.EdRoot = EdRoot; ed.EdIntiText = inti; ed.SubmitEventHandler = eh; edPlaceHolder.Controls.Add(ed); } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>shawl.qiu template</title> <style type="text/css"> /*<![CDATA[*/ @import "<% Response.Write(EdRoot); %>style/style.css"; /*]]>*/ </style> </head> <body> <div class="Main"> <form runat="server"> <asp:Label id=acDebugLabel runat=server /> <div class="info corRed"> <asp:Label id=acInfoLabel runat=server /> </div> <div class="navigator"> <span class="fltr algr"> <a href="?id=addnew">addnew</a> </span> <h2><a href="?">sqEditor HTML 编辑器 for .net</a></h2> </div> <div class="algc"> <div class="pagedList"> <asp:Label id=acPagedLabel runat=server /> </div> <div class="pagedDetails"> <asp:Label id=acPagedDetailsLabel runat=server /> </div> </div> <div class="acMain"> <asp:DataList id="acDisplayAtDataList" BorderColor="black" CellPadding="5" CellSpacing="5" RepeatDirection="Horizontal" RepeatLayout="Flow" RepeatColumns="10" ShowBorder="True" runat="server"> <HeaderTemplate> <ol class="acOlList"> </HeaderTemplate> <HeaderStyle BackColor="#aaaadd"> </HeaderStyle> <AlternatingItemStyle> </AlternatingItemStyle> <ItemTemplate> <li> <span class="algr fltr"> <a href="?id=edit&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>"> edit </a> </span> <a href="?id=display&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>"> <%# DataBinder.Eval(Container.DataItem, "title") %> </a> <div class="text"> <%# System.Text.Encoding.Unicode.GetString( (byte[])DataBinder.Eval(Container.DataItem, "content") ) %> </div> </li> </ItemTemplate> <%-- <SeparatorTemplate> </SeparatorTemplate> --%> <FooterTemplate> </ol> </FooterTemplate> </asp:DataList> <asp:DataList id="acDataList" BorderColor="black" CellPadding="5" CellSpacing="5" RepeatDirection="Horizontal" RepeatLayout="Flow" RepeatColumns="10" ShowBorder="True" runat="server"> <HeaderTemplate> <ol class="acOlList"> </HeaderTemplate> <HeaderStyle BackColor="#aaaadd"> </HeaderStyle> <AlternatingItemStyle> </AlternatingItemStyle> <ItemTemplate> <li> <span class="algr fltr"> <a href="?id=edit&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>"> edit </a> </span> <a href="?id=display&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>"> <%# DataBinder.Eval(Container.DataItem, "title") %> </a> </li> </ItemTemplate> <%-- <SeparatorTemplate> </SeparatorTemplate> --%> <FooterTemplate> </ol> </FooterTemplate> </asp:DataList> </div> <div class="sqEditorDiv"> <asp:PlaceHolder id=edPlaceHolder runat=server /> </div> </form> </div> <p/><a href="?">--back--</a> </body> </html>4. js 核心代码
// sqEditor -- shawl.qiu script : shawl.qiu@gmail.com /*-----------------------------------------------------------------------------------*/ * sqEditor HTML 编辑器 for .net v1.0 /*-----------------------------------------------------------------------------------*/ //---------------------------------begin class sqEditor()-------------------------------// function sqEditor() { // shawl.qiu code //------------------------------------begin public variable //---------------begin about this.auSubject='sqEditor HTML 编辑器 for .net'; this.auVersion='v1.0'; this.au='shawl.qiu'; this.auEmail='shawl.qiu@gmail.com'; this.auBlog='http://blog.csdn.net/btbtd'; this.auCreateDate='2007-2-29'; //---------------end about this.Debug = false; this.Root = "/sqEditor_DotNet/"; this.Iframe = function(){} this.Iframe.Id = "ifm"; this.Iframe.Window = ""; this.Iframe.Document = ""; this.SubmitId = "submId"; this.ContentTextBoxId = "ctbId"; this.IntiTextDivId = "itdId"; this.ReloadString = ""; this.MaxLength = 200000; this.MinLength = 13; this.Word = function(){} this.Word.ModeTrue = "Go Design Mode"; this.Word.ModeFalse = "Go Source Mode"; this.Word.Submit = "现在提交数据?"; this.Word.Reset = "现在重置?"; this.Word.Submitting = "正在提交数据, 请稍候..."; this.Word.Upsize = "数据过长, 请重新编辑. 最多为: "+this.MaxLength+" 字."; this.Word.ShortSize = "数据过短, 请重新编辑. 最小长度为: "+this.MinLength+" 字."; //------------------------------------end public variable //------------------------------------begin private variable var Tl = this; var IntiTextDivObj; var ContentTextBoxObj; var EdMode = true; var ReloadMode = false; //------------------------------------end private variable //------------------------------------begin public method this.Inti = fInti; this.Submit = fSubmit; this.SubmitHandler = fSubmitHandler; this.Mode = fMode; this.Cmd = fCmd; this.XmlHttp = fXmlHttp; this.Select = fSelect; this.Popup= fPopup; this.Reload = fReload; this.Preview = fPreview; this.Source = fSource; //------------------------------------end public method //------------------------------------begin private method function fSource(){ Tl.Popup('about:blank'); oPopup.document.write('<meta http-equiv="Content-Type" content="text/html;'+ ' charset=utf-8" />'); var str=Tl.Iframe.Document.body.innerHTML; switch(navigator.appName) { case 'Opera': str=str.replace(/<br(//|)>/gi,'<br/>/r/n'); str=fStrEncode(str); oPopup.document.write('<xmp><div id="sqEditorMain" class="sqEditorMain">/n', fStdCase(str),'</div></xmp>'); break; case 'Netscape': str=str.replace(/<br(//|)>/gi,'<br/>/r/n'); str='<div id="sqEditorMain" class="sqEditorMain">/n'+str+'</div>'; str=fStrEncode(str); oPopup.document.write('<pre>'+fStdCase(str)+'</pre>'); break; default: str=str.replace(/(<br(//|)>)/gi,'<br/>/n'); oPopup.document.write('<xmp><div id="sqEditorMain" class="sqEditorMain">/n', fStdCase(str),'</div></xmp>'); } oPopup.document.close(); } // end function fSource function fPreview() { Tl.Popup('about:blank'); oPopup.document.write(Tl.Iframe.Document.body.innerHTML); oPopup.document.close(); return false; } function fSubmitHandler() { var btn = document.getElementById(Tl.SubmitId); if(btn==null)return false; btn.click(); return false; } function fReload() { if(ReloadMode)Tl.ReloadString='?id='+fRandomLetter(10); location.replace(document.URL); ReloadMode=true; return false; } function fSelect(obj, e) { if(!e)var e=window.event; var ele=e.target||e.srcElement var iPsti = fGetEleOffsetPsti(ele); fHidEle(obj); //-- obj.style.width=ele.offsetWidth+'px'; obj.style.left=iPsti+'px'; obj.style.top=ele.offsetTop+ele.offsetHeight+'px'; if(obj.childNodes[0].className=='sqEditorCssBorder')return true; for(var i=0; i<obj.childNodes.length; i++) { if(obj.childNodes[i].nodeType==1) { obj.childNodes[i].className='sqEditorCssBorder'; obj.childNodes[i].style.width=obj.style.width; switch(obj.id) { case 'sqDdFontsize': obj.childNodes[i].onclick=function() { Tl.Cmd('formatBlock', false, this.childNodes[0].nodeName.toLowerCase()); fHidEle(this.parentNode); //-- ele.innerHTML=this.childNodes[0].nodeName; return false; } break; case 'sqDdBgColor': obj.childNodes[i].onclick=function() { ele.style.backgroundColor=this.innerHTML; ele.style.color=this.style.color; Tl.Cmd('hiliteColor', false, this.innerHTML); fHidEle(this.parentNode); //-- return false; } break; case 'sqDdFgColor': obj.childNodes[i].onclick=function() { ele.style.backgroundColor=this.innerHTML; ele.style.color=this.style.color; Tl.Cmd('ForeColor', false, this.innerHTML); fHidEle(this.parentNode); //-- return false; } break; case 'sqDdFormatBlock': obj.childNodes[i].onclick=function() { Tl.Cmd('formatBlock', false, this.innerHTML); fHidEle(this.parentNode); //-- ele.innerHTML=this.innerHTML; return false; } break; } // end switch } // end if } // end for return false; function fHidEle(obj){ obj.style.display=='none'?obj.style.display='block':obj.style.display='none'; } // end function fHidEle } // end function fSimulation function fCmd(sCmd, bOpt, sVal) { if(!sCmd)return false; if(!bOpt)var bOpt=false; if(!sVal)var sVal=null; switch(sCmd){ case 'pre': fPre(); return false; case 'formatBlock': if(sVal!='h1'&&sVal!='h2'&&sVal!='h3'&&sVal!='h5'&&sVal!='h5'&&sVal!='h6') { fPadTag(sVal); return false; } break; case 'emptyAll': if(sVal==null)sVal='确实要清空内容吗?' if(confirm(sVal)) Tl.Iframe.Document.body.innerHTML=' ' return false; case 'email': fEmail(); return false; case 'anchor': fAnchor(); return false; case 'emotion': fEmotion(); return false; case 'eraserAll': fEraserAll(); return false; } // end switch if(fCkBrs()!=1) { switch(sCmd) { case 'createLink': fLink(); return false; case 'insertImage': fImg(); return false; } } // end if if(fCkBrs()==1){ switch(sCmd) { case 'insertOrderedList': fOrderListForIe('ol'); return false; case 'insertUnorderedList': fOrderListForIe('ul'); return false; case 'hiliteColor': sCmd='BackColor'; break; case 'insertHTML': fIeInsertHtml(sVal); return false; case 'InsertImage': Tl.Cmd('insertHTML', false, '<img src="'+sVal+'" class="sqImg" />'); return false; case 'formatBlock': if(sVal=='h1'||sVal=='h2'||sVal=='h3'||sVal=='h4'||sVal=='h5'||sVal=='h6') sVal='<'+sVal+'>'; break; } // end switch } // end if Tl.Iframe.Document.execCommand(sCmd, bOpt, sVal); return false; } function fMode(){ var debug = false; var dbs = ""; var EdBtn = document.getElementById('sqBtnMode'); if(EdMode) { EdBtn.innerHTML = Tl.Word.ModeTrue; if(navigator.appName == "Netscape") { Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerHTML. replace(/<pre>[/s/S]*?<//pre>/gi, function(match) { return match.replace(//r/gi,'<br>'); }); var TempTextNode=document.createTextNode(Tl.Iframe.Document.body.innerHTML. replace(/(<br(?://|)>)/gi,'$1/r')); Tl.Iframe.Document.body.innerHTML=''; Tl.Iframe.Document.body.appendChild(TempTextNode); TempTextNode=null; Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerHTML. replace(//r/gi,'<br/>/r'); } else { Tl.Iframe.Document.body.innerText=Tl.Iframe.Document.body.innerHTML.replace(//n|/r/g,''). replace(/<pre>[/s/S]*?<//pre>/gi, function(match){ return match.replace(/<br(//|)>/gi,'/n'); }); Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerHTML. replace(/(/</;BR(?://|)/>/;)/gi,'$1<br/>'); } // end if 1 EdMode = false; } else { EdBtn.innerHTML = Tl.Word.ModeFalse; if(navigator.appName == "Netscape") { Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerHTML.replace(//n|/r/g,''); Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerHTML. replace(//</;pre/>/;[/s/S]+/</;//pre>/;/gi, function(match){ return match.replace(/<br>/gi,'/r'); }); var html = Tl.Iframe.Document.body.ownerDocument.createRange(); html.selectNodeContents(Tl.Iframe.Document.body); Tl.Iframe.Document.body.innerHTML=html.toString(); html=null; } else { Tl.Iframe.Document.body.innerHTML=Tl.Iframe.Document.body.innerText. replace(/<pre.*?>[/s/S]*?<//pre>/gi,function(match) { return match.replace(//n/g,'<br/>'); }); } // end if 1 EdMode = true; } // end if if(debug||Tl.Debug) { dbs += "/nEdMode: "+EdMode; alert(dbs); } return false; } // end function fMode function fSubmit() { var debug = false; var dbs = ""; var oEd=document.getElementById(Tl.Iframe.Id); var oTemp=document.createElement('div'); oTemp.id='sqPosting'; oTemp.style.backgroundColor='yellow'; oTemp.style.color='black'; oTemp.innerHTML= Tl.Word.Submitting; oEd.parentNode.insertBefore(oTemp, oEd); oEd=null; oTemp=null; if(!EdMode) { Tl.Mode(); EdMode=true; } fAtcLink(Tl.Iframe.Document.body, Tl.Iframe.Document); if(!confirm(Tl.Word.Submit)) { fCancel("sqPosting"); return false; } if(Tl.Iframe.Window == null) return false; if(ContentTextBoxObj == null) return false; var ifmHtml = Tl.Iframe.Document.body.innerHTML; if(Tl.Debug||debug) { dbs += "/ndebug submit:"; //dbs += "/nifmHtml: "+ifmHtml; dbs += "/n ifmHtml.length: "+ifmHtml.length; dbs += "/n typeof(ifmHtml.length): "+typeof(ifmHtml.length); dbs += "/n ifmHtml.length: "+ifmHtml.length; dbs += "/n typeof(Tl.MinLength): "+typeof(Tl.MinLength); dbs += "/n Tl.MinLength: "+Tl.MinLength; alert(dbs); } if(ifmHtml.length>Tl.MaxLength) { alert(Tl.Word.Upsize); fCancel("sqPosting"); return false; } if(ifmHtml.length<Tl.MinLength) { alert(Tl.Word.ShortSize); fCancel("sqPosting"); return false; } ContentTextBoxObj.value = ifmHtml; return true; } // end function fSubmit function fCancel(sId) { try { var oEd=document.getElementById(sId); oEd.parentNode.removeChild(oEd); oEd=null; } catch(e){} } // end function fCancel function fAtcLink(obj, dcu) { if(!EdMode) return false; var temp, str='', span; for(var i=0, j=obj.childNodes.length; i<j; i++) { temp=obj.childNodes[i]; if(temp.nodeType==3) { if(temp.parentNode.nodeName=='A')return false; if(temp.data.indexOf('http')<0&&temp.data.indexOf('ftp')<0&& temp.data.indexOf('@')<0)continue; span=dcu.createElement('span'); //str=temp.data.replace(/</g,'<').replace(/>/g,'>'); str=fStrEncode(temp.data); str=str.replace(/(ht|f)tp(s|)/:[/-/w.:]+(//[^ /n/r/'/"]+|)/gi,function(match) { return '<a href="'+match+'" class="sqUrl">'+match+'</a>'; } ); str=str.replace(/[/w.]+@[/w/-.]+(//[^ /n/r/'/"]+|)/gi,function(match) { return '<a href="mailto:'+match+'" class="sqMail">'+match+'</a>'; }); span.innerHTML=str; obj.replaceChild(span, temp); } if(temp.nodeType==1)arguments.callee(obj.childNodes[i], dcu); } temp=span=null; } // end function fAtcLink function fInti() { try { var sbmBtn = document.getElementById(Tl.SubmitId); if(sbmBtn==null)return false; var clkTemp = sbmBtn.onclick; sbmBtn.onclick=function() { try{clkTemp();}catch(e){} return Tl.Submit(); } Tl.Iframe.Window=document.getElementById(Tl.Iframe.Id).contentWindow; Tl.Iframe.Document=Tl.Iframe.Window.document; ContentTextBoxObj = document.getElementById(Tl.ContentTextBoxId) Tl.IntiTextDivObj=document.getElementById(Tl.IntiTextDivId) if(Tl.IntiTextDivObj!=null) Tl.IntiTextDivObj=Tl.IntiTextDivObj.innerHTML; Tl.Iframe.Document.designMode="on"; Tl.Iframe.Document.contentEditable=true; Tl.Iframe.Document.open(); if(!Tl.IntiTextDivObj) Tl.Iframe.Document.write('-------- '); else Tl.Iframe.Document.write(Tl.IntiTextDivObj); Tl.Iframe.Document.close(); try { var oTemp=onunload; onunload=function() { try{oTemp();}catch(e){} fFixMl(); } // end onunload } catch(e) {} } catch(e) { } } // end function fInti function fCkBrs() { switch (navigator.appName) { case 'Opera': return 2; case 'Netscape': return 3; default: return 1; } } // end function fCkBrs function fOrderListForIe(sMarkup) { var sAr = []; var sTemp = ""; var oRange = Tl.Iframe.Document.selection.createRange(); if(oRange.text != '') { sAr = oRange.text.split('/n'); for(var i=0; i<sAr.length; i++) sTemp += '<li>'+sAr[i].replace(/</g,'<').replace(/>/g,'>')+'</li>'; sTemp = '<'+sMarkup+' class="sqList">'+sTemp+'</'+sMarkup+'>'; oRange.pasteHTML(sTemp); } } // end function fOrderListForIe function fPre() { if(fCkBrs()==1) { var range=Tl.Iframe.Document.selection.createRange(); var str=range.text; if(str!='') { range.pasteHTML('<pre class="sqPre">'+str+'</pre>'); } else { fPopup(Tl.Root+'html/popup_pre.htm'+Tl.ReloadString); // end if 1 } } else { var range = Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var selt = Tl.Iframe.Window.getSelection(); var str = selt.toString(); if(str.length>10) { if(fCkBrs()==3) { str=str.replace(/<br>/g,''); str=str.replace(//n/g,''); Tl.Iframe.Document.execCommand('insertHTML', false, '<pre class="sqPre">'+str+'</pre>'); return false; } Tl.Iframe.Document.execCommand('formatBlock', false, 'pre'); } else { fPopup(Tl.Root+'html/popup_pre.htm'+Tl.ReloadString); // end if 1 } } // end if return false; } // end function fPre function fPopup(sUrl, iWidth, iHeight, sAddition) { try{oPopup.close()}catch(e){} if(!sUrl)return false; if(!iWidth)iWidth=screen.availWidth-200; if(!iHeight)iHeight=screen.availHeight-150; if(!sAddition)sAddition=''; var iMrgHor=(screen.availWidth-iWidth)/2; var iMrgVtc=(screen.availHeight-iHeight)/2; oPopup=open('about:blank','sqPopup','width='+iWidth+',height='+iHeight+',left='+iMrgHor +',top='+iMrgVtc+',scrollbars'+sAddition); oPopup.location.href=sUrl; oPopup.focus(); oPopup.document.ondblclick=function(){oPopup.close();} oPopup.document.onkeydown=function(){ if(oPopup.event.keyCode==27)oPopup.close(); } return false; } // shawl.qiu script function fXmlHttp(sMethod, sUrl, oFunc) { var xh; try { xh=new XMLHttpRequest(); } catch(e) { try { xh=new ActiveXObject('microsoft.xmlhttp'); } catch(e) { try{ xh=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){} // end try 2 } // end try 1 } // end try xh.open(sMethod, sUrl); xh.onreadystatechange=function() { if(xh.readyState==4&&xh.status==200) { if(oFunc) oFunc(xh.responseText); else alert(xh.responseText); } } xh.send(null); } // end function fXh function fIeInsertHtml(sStr) { Tl.Iframe.Window.focus(); if(fCkBrs()==1){ var range=Tl.Iframe.Document.selection.createRange(); range.pasteHTML(sStr); } } // end function fIeInsertHtml function fGetEleOffsetPsti(oEle, iPsti) { if(fCkBrs()!=1) return oEle.offsetLeft; var debug = false; if(debug) { alert( "oEle.tagName: "+oEle.tagName+ "/noEle.offsetLeft: "+oEle.offsetLeft ); } iPsti = oEle.offsetLeft; if(oEle!=null && oEle.tagName!="BODY") { iPsti+=arguments.callee(oEle.parentNode, iPsti); } return iPsti; function fCkBrs() { switch (navigator.appName) { case 'Opera': return 2; case 'Netscape': return 3; default: return 1; } } // end function fCkBrs } // end function fGetEleOffsetPsti function fPadTag(sTag) { Tl.Iframe.Window.focus(); if(fCkBrs()==1) { var range=Tl.Iframe.Document.selection.createRange(); range.pasteHTML('<'+sTag+' class="sqGeneral">'+range.htmlText+'</'+sTag+'>'); } else { var range=Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var oTemp=Tl.Iframe.Document.createElement(sTag); range.surroundContents(oTemp); } // end if } // end function fPadTag function fRandomLetter(nLen, sCase) { var ar=''; var arUp=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V','W','X','Y','Z']; var arLw=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z']; var arDgt=[0,1,2,3,4,5,6,7,8,9]; switch(sCase) { case 'upper': ar=arUp; break; case 'lower': ar=arLw; break; case 'letter': ar=arUp.concat(arLw); break; default:ar=arUp.concat(arLw, arDgt); } if(nLen&&nLen>0) { if(!isFinite(nLen))return false; if(nLen<0)return false; var iLetter=''; nLen=parseInt(nLen); for(var i=0; i<nLen; i++) { iLetter+=ar[fRandomBy(0,ar.length-1)]; } return iLetter; } return ar[fRandomBy(0,ar.length-1)]; } // shawl.qiu code function fEmail() { if(fCkBrs()==1) { var range=Tl.Iframe.Document.selection.createRange(); if(range.text!='') { var url=prompt('please enter a e-mail address', 'shawl.qiu@gmail.com'); if(!url)return false; range.pasteHTML('<a href="mailto:'+url+'" class="sqMail">'+range.htmlText+'</a>'); } else { Tl.Popup(Tl.Root+'html/popup_email.htm'+Tl.ReloadString, 500, 120); } } else { var url=''; var temp=Tl.Iframe.Document.createElement('a'); var range=Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var selt=Tl.Iframe.Window.getSelection(); if(selt.toString()!='') { url=prompt('please enter an e-mail address', 'shawl.qiu@gmail.com'); if(url) { temp.href='mailto:'+url; temp.className="sqMail"; range.surroundContents(temp); } } else { Tl.Popup(Tl.Root+'html/popup_email.htm'+Tl.ReloadString, 500, 120); } } // end if return false; } // end function fEmail() function fLink() { var temp=Tl.Iframe.Document.createElement('a'); var range=Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var selt=Tl.Iframe.Window.getSelection(); if(selt.toString()!='') { var url=prompt('please enter a url', 'http://'); if(!url)return false; temp.href=url; temp.className='sqUrl'; range.surroundContents(temp); } else { Tl.Popup(Tl.Root+'html/popup_url.htm'+Tl.ReloadString, 500, 120); } } function fAnchor() { if(fCkBrs()==1) { var range=Tl.Iframe.Document.selection.createRange(); var text if(range.text!='') { text=prompt('please enter a name for anchor', 'anchor name'); if(!text)return false; range.pasteHTML('<a name="'+text+'" class="sqAnchor">'+ range.htmlText+'</a>'); } else Tl.Popup(Tl.Root+'html/popup_anchor.htm'+Tl.ReloadString, 500, 120); } else { var text=''; var temp=Tl.Iframe.Document.createElement('a'); var range=Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var selt=Tl.Iframe.Window.getSelection(); if(selt.toString()!='') { text=prompt('please enter a name for anchor', 'anchor'); if(text){ temp.name=text; temp.className="sqAnchor"; } else return false; range.surroundContents(temp); } else Tl.Popup(Tl.Root+'html/popup_anchor.htm'+Tl.ReloadString, 500, 120); } // end if } // end function fEmail() function fImg() { Tl.Popup(Tl.Root+'html/popup_image.htm'+Tl.ReloadString, 400, 200); } function fEmotion() { Tl.Popup('about:blank', 500,500); Tl.XmlHttp('GET', Tl.Root+'html/popup_emotion.htm'+Tl.ReloadString, fGetEmo); function fGetEmo(sSrc) { sSrc=sSrc.replace(/src/="/gi,'src="'+Tl.Root); if(oPopup) { oPopup.document.write(sSrc); oPopup.document.close(); } // end if } // end function fGetEmo } // end function fEmotion function fStrDecode(sStr){ if(!str)return false; return sStr.replace(//</;/gi,'<'). replace(//>/;/gi,'>'). replace(//&/;/gi,'&'); } function fStrEncode(sStr){ if(!sStr)return false; return sStr.replace(/[&]/g,'&'). replace(/</g,'<'). replace(/>/g,'>'); } function fStdCase(sStr) { if(!sStr||sStr.length==0)return false; return sStr=sStr.replace(/<[^>]+>/g, function(match) { return match.replace(/^<[a-z0-9]+( |)|[a-z0-9]+>$|[a-z]+/=/gi,function(sub) { return sub.toLowerCase(); } ); } ) // shawl.qiu script } // end function fStdCase function fEraserAll() { if(fCkBrs()==1) { var range=Tl.Iframe.Document.selection.createRange(); range.text=range.text; } else { var range=Tl.Iframe.Window.getSelection().getRangeAt(0); // 返回 当前 range 中的内容 var selt=Tl.Iframe.Window.getSelection(); if(fCkBrs()==2) selt=Tl.Iframe.Document.selection.createRange().text; else selt=selt.toString(); if(selt=='')return false; Tl.Cmd('insertHTML', false, selt.replace(//r/n/g,'<br/>').replace(//r/g,'<br/>')); } } // end function fEraserAll function fFixMl(oEle) { if(!oEle)oEle=document.body; var atr=oEle.attributes; if(atr) for(var i=0, j=atr.length; i<j; i++) if(typeof oEle[atr[i].name]=='function')oEle[atr[i].name]=null; if(oEle.childNodes) for(var i=0, j=oEle.childNodes.length; i<j; i++) arguments.callee(oEle.childNodes[i]); } //------------------------------------end private method } // shawl.qiu code //---------------------------------end class sqEditor()---------------------------------// var ed = new sqEditor();
